Skip to main content

Introduction

Use the servo sonar module to improve our intelligent driving!

  1. In this project, we'll be using your robot's motors to create a self-driving car!
    • In this project, we'll be using your robot's motors to create a self-driving car!

    • To access the motor libraries, go to https://www.techcamp.org.uk/invent. This will give you access to our Invent modules, which includes a module for controlling the motors.

    • You'll know you're in the right place if you can see the Invent namespace on the right-hand side.

  2. In this project, we want to develop a car that looks left and right when it detects an obstacle, and then goes in the direction with more clearance. Let's get started!
    • In this project, we want to develop a car that looks left and right when it detects an obstacle, and then goes in the direction with more clearance. Let's get started!

    • First, we reset the servo position to be looking straight ahead in the first 3 lines.

    • Next in the forever loop, we tell the car to drive forwards. We then have an if statement, which will run if there's an obstacle in front of the sonar.

    • In TypeScript, comments are denoted with // rather than # like in Python.

  3. First, we need to stop the car if there's an obstacle so we don't ram into it!
    • First, we need to stop the car if there's an obstacle so we don't ram into it!

    • Next, we use the servo to look left and take the sonar reading, and then the same for the right.

    • Now that we have our measurements, we can look straight ahead again.

  4. You'll notice we left the contents of the while loop empty!
    • You'll notice we left the contents of the while loop empty!

    • Can you write the code that will make the car turn left if there's more space, or right if not?

    • On your board from the sonar project, attach the two motors if they're not already installed!

    • Program your micro:bit and turn on the car!

    • You should find that when it encounters an obstacle, it will stop, look both ways, and then turn in the direction with more clearance. If so, you're done!

Finish Line

Paul Clavier

Member since: 06/11/2018

7 Guides authored

Team

Inventor School Member of Inventor School

Community

4 Members

140 Guides authored

0 Comments

Add Comment