[Logo for The C Shore Landing Page]
The C Shore

Ready for Action

Now that all the testing is complete we can move the RoboCar to the floor and see what it and your Team are able to do.

First of all go to the file library in Mu and load the file RoboCar.py.

  
from gpiozero import Robot
import time

roboCar = Robot(left=(7,8), right=(9,10))
roboCar.forward()
time.sleep(2)
roboCar.stop()
time.sleep(1)
roboCar.backward()
time.sleep(2)
roboCar.stop()
time.sleep(1)
roboCar.left()
time.sleep(1)
roboCar.stop()
time.sleep(1)
roboCar.right()
time.sleep(1)
roboCar.stop()
  

This is your basic operating program. You can load it at any time through Mu. When you run it your RoboCar will go forward a little, back a little and then spin in a circle. Now the challenge.

You will have to modify the RoboCar.py file making a new file that will allow you RoboCar to complete the three challenges that have been set up for you. Remember to use the three tips to help you.

Challenge One – There and Back

Set you RoboCar anywhere within the START AREA on the MakerPlace floor. (Go over and take a look at it). Program your RoboCar so that it goes forward and stops in the STOP AREA on the MakerPlace floor. Then have your RoboCar go backwards and return and stop in the START AREA. You may have to run the challenge more than once.

Challenge Two – A Triangle

Set your RoboCar anywhere within the START AREA on the MakerPlace floor. Make it go forward a distance of at least 1 meter. Have it turn and go in a different direction for a distance of at least 1 meter. Then have your RoboCar turn one more time and return to the START AREA. Its path will be a triangle.  Can you make all the sides of the triangle the same length?

Challenge Three – An Obstacle (IF TIME PERMITS – SETUP REQUIRED)

Set you RoboCar anywhere within the START AREA on the MakerPlace floor. (Go over and take a look at it. Notice there is now something in the way.).  Program your RoboCar so that it goes forward, turns to avoid the obstacle and ends up in the STOP AREA. You may have to program multiple turns for your RoboCar.

Hints for the Challenge

  • When you write a new program for each challenge, save it and give it a different name so can call it up later. For example you may call the program you write for Challenge One “There.py
  • Remember you can change the speed of the motors by using a decimal value in the command. Example roboCar.forward (0.4)
  • Remember you can change the time a motor is on (or off) by using the sleep command. Example time.sleep(0.3)
  • When you are duplicating sections of code, remember to use the “cut and paste” technique.  See the Cut and Paste Handout sheet.

Have fun and if you get stuck, ask for help.