Basic Line follower. Using two sensors (in a forever loop):
Check the reflected light reading and use this reading in the following program.
If both sensors are > ? % then both wheels move forward @ 20%
If left sensor see <?% then start moving left @ 20% speed.
Else, start moving right @ 20% speed.
Step 3. Avoid the obstacle ( see below)
The robot detects the obstacle with the ultrasonic sensor, then navigates around the object. A Robot is expected to navigate around obstacles and reacquire the line within 30 cm of the obstacle.
For more advance programs, the RoboCup Junior Victoria Programming the EV3 gives some basic coding examples for line following with One Sensor (slide 14), Two Sensors (slide 17 and more accurate line following using Proportional Line Following (slides 18-19).
Sensor Activation: PARALLEL BEAMS (EVENTS)
IMPORTANT! Preliminary checklist
Distance sensor connected to port 4
Colour sensors connected to ports 2 and 3
Motors connected to ports B and C
Both colour sensors @ 2.5mm above surface
Both colour sensors aligned straight (not crooked!)
Calibrate one colour sensors using Colour sensor callibration
Use Port View to check results of colour sensor calibration
Check both sensors have reflectivity in 20s for pure white and 40s for aluminium foil? If not adjust appropriate values in code.
Explain this is where we identify the separate functions required to perform the overall task.
• Main program
• Line follower and green square turns
• Obstacle avoidance
• Find and push the can off the large green mat
• Find a way back to the start of the mat.
The three programs needing to be written are at right:
First, develop and test a proportional line following program. This code checks for green turn squares. Adjust the correctional factor until it follows the line well. This program include "if statements" to call functions for obstacle and aluminium foil. This code will be written next.
Develop a code for obstacle avoidance. This code starts up when the ultrasonic sensor sees an obstacle.
Develop a code for the green mat where the robot looks for the can then pushes it out. Ot then follows the green edge using a single sensor until it sees the silver strip. This code starts up when the reflected light is greater than (approx.) 35%.*
* Note, for this to work the colour sensors must read approx 10% on white and 35% > on silver.
Placing layers of sticky tape over the EV3 sensors can help these readings to be more reliable.
Use the Ultrasonic Sensor to find and rescue the victim = 50 points
The Ultrasonic Sensor – measures distance to nearby surfaces.
Programming the Ultrasonic.pdf