In week four of computer science, the class moved into the robotics unit. We used Python to program the robots to do various things such as make a square or avoid objects.
Making the Robot
To make the robot, everyone had to actually put the motors and wheels on the central bricks which was the source of power for the motors and sensors on the robot.
Here is the front of the robot when we first built it. You can see here the two sensors that were used: Sonar (or range) sensor, and a touch sensor. The sonar sensor detects range and the touch sensor detects whether or not the front is being pushed in or not.
To make the square, the robot needed to go forward a little bit, make a ninety degree right turn and repeat those two steps and the robot will make a square.
Here is a video of the robot making a square:
Here is the code to actually make a square:
This is the code to make the bot go forward and then turn. The "for i in range" statement is telling the program to repeat the lines of code below four times, one for each side/angle.
The objective of this challenge was to make the bot be able to navigate around randomly while avoiding hitting anything in it's path. If the bot's front two sensors are pressed, the bot will stop. In order to make this work, the sonar and sensors on the front must be used.
In this video you can see whenever the bot gets close to a surface, it backs up and turns slightly to the right. This process will be repeated many times or until the program is stopped.
The code to make it work:
Follow the line
The objective of the follow the line activity was to make the bot follow a strip of green tape. To make this work, a color sensor had to be added to the front of the bot, pointing downwards.
This is just a video of the line program at work. Another robot interferes with it but the robot continues to work the way it was designed to do, following the green tape line.
Here is the code to make it work:
You can see that once the sensor detects that it is no longer looking at green, it rotates until it senses the green again and then goes straight forward until it breaks contact with green.
The Mars challenge
The objective of this was to make the robot navigate a terrain with craters and a pool of water (blue painter's tape) successfully and to find the blue tape from the starting line.
To make this work, the sonar sensor and color sensor had to be utilized. The sonar sensor would be used to detect the craters and edges, while the color sensor would only be used to detect the blue tape that was at the end of the course.
The code to make it work:
Aside from minor physical design flaws with the robot, the program worked just as intended. How it works is that if the robot senses that it's sensor is more than 7.5 units off of the surface it will back up and turn away. The blue sensing part of this was the easiest, it being just sensing the blue and turning the robot around in sort of a victory spin.
Back to Home