Basic line follower =================== This program will be used to demonstrate line following. It requires 3 files to be loaded onto the Pico: Basic LF.py, UKMARS.py and params.py UKMARS.py is the import file. It imports the necessary machine classes (e.g. Pin, ADC, PWM, time, etc.). It also defines a Motor class for controlling the motors, and two calibration functions to make sense of the line sensor phototransistors. Basic.py contains the pushbutton response code, and the driving of the motors, in response to the line sensor output. params.py holds just 4 values, (only three used in the demo), so that students can explore the effect on the robots behaviour of editing the parameters, Instructions. ============= If you are using Thonny to edit the parameters, Click "Stop" before connecting to the Pico After switch-on the robot will be in state 0, having read the values from file params.py., and adjusting the speed according to the switches(see below). The parameters in the file are currently speed:20 efactor:30 dfactor 10 - good for a slow and steady run around the track. In state 0 the robot's forward speed is zero, and and the motors only cause the robot to spin to keep the sensor over the line. When you push the button, it goes into state 1 and runs forward as well as steering. The motor speed difference is proportional to the line sensor "error" - the distance from the centre of the white line. This steers the robot so that the sensor stays centered over the line. The line sensors self-calibrate (flashing the on-board LED), and produce, after calibration, an output 0-100. 0 for the black background, 100 for the white line. Before the sensors are calibrated, the robot may well spin, but will stop once it sees the line. It is best to manually sweep the sensor across the line, until the flashing stops. The two indicator LEDs on the line sensors show which of the two sensors is seeing the line. When running, you can stop the robot by pressing the button, to go back to state 0 It has no mechanism for automatically stopping. params.py ========= "efactor" This parameter needs to be large enough ( >10) so that the motors can re-centre the sensor, during state 0 (stationary line following). If faster speeds mean that the robot takes the corner wide, then efactor may need to be increased. "basespeed" is the robots forward speed (the average of the two motor speeds). It is not used until the pushbutton is pressed. Speeds can be between 0 and 100. Note, however, that each motor's speed has a maximum of 100, so having a basespeed of 100, means that steering can only be achieved by slowing one motor (as opposed to increasing one, and decreasing the other) "dfactor" is a stabilisation control. If zero, and if efactor is high, then the robot will swing wildly from left to right (even in state 0). Increasing dfactor to at most 40 will reduce this swinging. try these values for starters: basespeed=20 efactor=30 dfactor=20 Robots ====== The robots have motors with different gear ratios. The fastest (No.4) is 6 times as fast as the slowest (no.3). Robots 1,2,5 and 6 are all reasonably fast. So maximum basespeed settings will vary between them. Setting speed from switches =========================== The 4 switches on the pico board can be used to set the speed. This can be done without editing the file params.py on the robot. It is done in binary. off,off,off,off: Use value from params.py (20) on,off,off,off: 10, on,off,on,off : 50, off,on,off,off: 20, off,on,on,off : 60, on,on,off,off: 30, on,on,on,off : 70 off,off,on,off: 40, off,off,off,on : 80 and, on,off,off,on: 90 (but this speed will reduce steering ability!)