Python robot stuff.

We used python to run robots that we had built (but underwent many, many, changes), and use input from sensors, such as the ultrasonic rangefinder, and touch sensor, which was supposed to make the robot turn when it encountered an obstacle, and shut down when it was hit. On the second day, we worked on the robot some more, mainly making it have a bit more stability and rigidity, along with rearranging the sensors again. The robot ended up being unstable, but that was later fixed. Our robot wouldn't stop upon encountering the yellow paper, which we couldn't figure out quite how to fix, but we thought it might have been issues with sampling. It turned right whenever it came too close to a wall or other big obstacle, but failed at stopping when it encountered the yellow paper or came across a smaller obstacle.

The robot at the end looked like this:





The things on the front were the ultrasonic rangefinders, and the sensor on the top of inside the robot visible in the second picture is a touch sensor, with a pole attached to it to activate the touch sensor upon being pressed. The sensor that the back of is visible in the first image is the colour sensor, which was supposed to detect if it is over the yellow paper.

Some of the earlier code:



This causes it to try and turn upon encountering an obstacle, but does not match the current robot, and does not work very well.

We made new code (and a new robot) on the third day. This robot was designed to follow a coloured line, but this didn't work out too well for us. what we did manage, however, was to use xpadder and a XBOX controller to remote control the robot. We did kind of manage to work at the end, but at one point it testing it turned 180 degrees.

Here is the programming bits themselves:



This is importing the pybot module first, so that we can connect to the robot, take input, and control it, all from the computer via python.



This is defining the function.



This is defining the bot via bluetooth and its mac address, along with defining the sensors, because the name is too long to want to type it each time we call it, so instead we just assign it to a variable.



This is inside the function, similar to a "while True:", just running limited times instead of forever. This means that it will do whatever is inside it however many times is specified. The main thing in it, before the if statements is getting the distance and if the touch sensor is pressed each time it runs.



This is what makes the bot move, you can see that cause d is the distance to an object, if d is greater than or equal to 25, the bot will move forward, and if it is less than 25 it will spin wildly before hightailing it.

On Friday we put phones on the front of the robots, and remote controlled them, while using another phone back at the classroom to watch what the robot saw. We had issues with the robots wheels starting to try and come off,