Bodgers – Getting Started With Robots

We are still having network difficulties with WiFi on our Raspberry Pi3s but I will work on finding a solution or a work around during the week.

We managed to connect to two of our robots and we wrote a simple hello world script and a script to control our robots. When we use Python and the Gpio Zero module all it takes to control a wheeled robot like ours is 9 different lines of code these are:

  1. from time import sleep – this will allow us to call the sleep function later in the code.
  2. from gpiozero import Robot – this will allow us to call all the robot functions from Gpio Zero.
  3. robot = Robot(left=(22,23),right=(24,25)) – this is the most complicated line in our code, all it does is assign which gpio pins will be used to control our robot. This will become much clearer when we start to build simpler circuits later in the year.
  4. robot.forward() – this function drives all our motors forward.
  5. robot.backward() – this function drives all our motors backward.
  6. robot.left() – this function drives the motors on the right forward and the motors on the left backward.
  7. robot.right() – this function drives the motors on the left forward and the motors on the right backward.
  8. sleep() – this function pauses the program.
  9.  robot.stop() – this function stops the motors.

If we want to drive our robot forward for five seconds we would use the following code

  1. from time import sleep
  2. from gpiozero import Robot
  3. robot = Robot(left=(22,23),right=(24,25))
  4. robot.forward()
  5. sleep(5)
  6. robot.stop()

We had a brainstorming session about what we might do for our projects and we came up with some great ideas which we talk more about on Saturday. My slides from Saturday are  here robot-intro.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s