Page with Awesome Background

Robotics

Day One:


Today in class, we started to learn about robotics. We were able to use the pybot package written by Chris Miller for python. This allowed us to be able to remotely program LEGO NXT Mindstorms via our laptops bluetooth. Here is a sample of the code that we used:

In this code, we created a function called "dance." The robot moves forward, stops and then starts spinning. In order to code this, I needed to import the pybot package in order to get the different functions like "forward" and "right" defined. This function works, but now I am trying to get it to stop. I want to get the function to stop when the touch sensor is pressed. However it did not work at first. I decided that I had better test the sensor so I created a function called test that would print whether the sensor was pressed or not. Even when it was pressed, it still printed "false" or not pressed. This was due to a lableing error in which I forgot to say the sensor was in port one. Now I can get it to stop when the sensor is pressed. The only thing is that it does not stop as soon as it is pressed. I think this is because the robot runs trough all of the moving code before it senses the sensor. Tomorrow I would like to try to figure out a way to get it to stop as soon as it is pressed.

Here are some pics of our robot:

               

Day Two:



Today we focused on using the color sensor for the robots. The mission was to have our robot be able to start from a random place and then be able to find a certain colored paper. In order to do this we created a program to go forward, turn right, go forward, turn left and then repeat. The we created a stop code when it senses yellow. At first we put this section at the end of our code, but that did not work since it would have to run through the entire movement script before in looked for colors again, leaving enough time for it to find an completely leave the yellow before it sensed again.
Here is a picture of our robot from today with a color sensor and a sonar sensor, which we have yet to successfully program

p>

Day Three:


Today we had a new challenge, to get our robot to follow a purple tape line:

It was a good challenge, and it took several tries. Here is our final code:

The trick was to get it to avoid the ground. However when it turned away from the ground, it had to be in small increments because if it passed the blue in the left turn it would end up doing a 180 degree turn and start going the wrong way. This is why in the final code we had a large right turn and a smaller left turn. In the end we got it to finish the course and stop at the green paper.
Here is the picture of our "line bot" with its light sensor.

Day Four:


Today's challenge was to have our robots to wander and avoid having their touch sensors activated. Our first code looked like this:

This had the robot simply spin in a circle continuously until the sensor was pressed. We did this because it would be hard for the sensor to get a direct contact. Originally we had the problem of getting out of the loop. This was fixed by Emily showing me how to use a break code. Essentially it causes the code to miss the section where it runs itself again and goes to the stop.bot function. However this was an easy function overall, so with the help of Willy I added sound affects to the nxt. This was done by opening the pybot.rbt file in pybot.py and going to tools and then sound editor. I then uploaded a mp3 file and saved it as an rso file. I then downloaded it to the brick and used the bot.brick.play_sound_file(False, 'R2.rso') command in python. Now it plays R2D2's scream when he stops moving.
I also decided to create a function that used the sonar function. Here is the code for that:

In this code I define bck as the robot with reverse and turn 180 degrees if it senses an object. I then used this is the wander2 function for it to test constantly. I also had problems like in the previous function with loops, but they were fixed in much the same way. Right now I am trying to use the randrange function to get my robot to play a sound randomly. It is not working how I want it to yet, it is still constantly playing the sound so I am going to experiment with changing the range and see if that helps. er is a picture of our robot using operationcircle: