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:
- from time import sleep – this will allow us to call the sleep function later in the code.
- from gpiozero import Robot – this will allow us to call all the robot functions from Gpio Zero.
- 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.
- robot.forward() – this function drives all our motors forward.
- robot.backward() – this function drives all our motors backward.
- robot.left() – this function drives the motors on the right forward and the motors on the left backward.
- robot.right() – this function drives the motors on the left forward and the motors on the right backward.
- sleep() – this function pauses the program.
- robot.stop() – this function stops the motors.
If we want to drive our robot forward for five seconds we would use the following code
- from time import sleep
- from gpiozero import Robot
- robot = Robot(left=(22,23),right=(24,25))
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.