Driving School is a virtual robot playground with ducks, obstacles, and traffic lights in the Micromelon Robot Simulator. In Driving School Basics, we program the Rovers to stay in the centre of the lanes while avoiding ducks and other Rovers.
Driving School activity in the Robot Simulator
Setup
This exercise has no physical setup, it’s completed in the Micromelon Robot Simulator. To learn more about the Robot Simulator, check out the getting started guide.
Our Approach
Stage 1: Loop with Branching
Add a While True loop with an IF / ELSE IF / ELSE statement so we can continuously ask the Rover questions about its environment.
Stage 2: Stay Centred Using the Colour Sensors
The simulator’s roads have a slight brightness gradient towards the edges, so the colour sensors can work out where the Rover is on the road. Use an IF / ELSE IF / ELSE with the colour sensor blocks to work out whether it’s too far left or right. Use the Set Motor Speeds block to slightly turn left or right and adjust position.
Stage 3: Don’t Hit the Duck!
Use the front ultrasonic sensor distance block to make the Rover wait for the duck to cross. This also avoids other Rovers.

Example code, driving-school algorithm




