---
title: "Driving School Basics"
date: "2022-03-13"
categories: ["Activities"]
tags: ["Colour Sensors", "Branching", "Iteration", "Algorithm Design", "Ultrasonic", "IR", "Motors", "Simulator", "Advanced"]
codingSkills: ["Branching", "Iteration", "Algorithm Design"]
roverConcepts: ["Colour", "Ultrasonic", "IR", "Motors"]
excerpt: "Learn the basics of rover motors and sensors while navigating Duck City."
featuredImage: "/images/resources/driving-school-basics.png"
---

** **

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 running over ducks and hitting other rovers.

![](/images/content/d13e2c-driving-school.gif)

### Activity Demonstration

### Setup

This exercise has no physical setup as it is completed in the Micromelon Robot Simulator. To learn more about the Robot Simulator check out the [**Getting Started With The Robot Simulator**](https://micromelon.com.au/resources/robot-simulator) post.

### Here’s Our Approach

#### Stage 1

Add a while true loop and an IF/ELSE IF/ELSE statement so that we can continuously ask our rover questions about its environment.

#### **Stage 2**

The simulator’s roads actually have a slight brightness gradient towards the edges, so using the colour sensors you can work out where the rover is on the road. This approach uses an IF/ELSE IF/ELSE statement together with the colour sensor blocks to work out whether it is too far to the left or right. You can use the set motor speeds blocks to slightly turn to the left or right and adjust the position on the road.

#### **Stage 3**

Now we need to make sure we do not run into the duck! We can use our front ultrasonic sensor distance block to get our robot to wait for the duck to cross. It will also avoid other rovers now!

![](/images/content/dba11b-driving-school-answer.png)

Example Code
