Nxt robot soccer programming


This sensor will provide the distance between the ball and the sensor as a number. To be able to display this number on the screen of our NXT robot, we need to convert this "number" to "text". The code above will only give one reading. To allow us to see how the reading changes as the soccer ball approaches the ultrasonic sensor, we need a loop. When we download this program into our soccer Robot, and run it, we will be able to see how the ultrasonic reading changes as the soccer ball approaches our robot.

This will enable us to choose the ultrasonic reading that we can use to tell our soccer robot that the ball is close enough to kick. Note that in the case above, I used an ultrasonic sensor.

This may not be the best way to tell your robot when the ball is in the right place to kick. Feel free to use other types of sensors if this is better for your robot. If you use another type of sensor, use a process similar to the process above to enable you to choose a good setting for your soccer robot kicking sensor.

There are lots of different ways to get your Soccer Robot to kick the ball. Which one is best for your Robot is something you can decide.

As an example, I chose to use a bar attached to a third motor that rotates in roughly a quarter turn to kick the ball - your robot ball kicker may be different. Do not be afraid to go your own way! In the meanwhile, my code for my first attempt at a kicker may be a help when you are thinking about how your Robot could kick a ball Note that my LEGO ultrasonic sonar sensor is plugged into computer brick socket 4.

If your robot has an ultrasonic sensor plugged in to a different socket, you will have to change this code. The ultrasonic sensor on my Robot "sees" a distance of 13 centimetres when the ball is not near. It "sees" a distance of 8 centimetres when the ball is completely under the sensor.

In the ultrasonic control panel above, I have chosen to tell my robot to kick if the distance is less then 10 centimetres your distance will be different. My Soccer Robot has a kicker attached to motor B. A rotation "backwards" of approximately degrees about a quarter turn will cause the "kicker" attached to motor B's axle to kick the ball.

The first thing we want our robot to do is to be able to stay inside the Soccer Field; click here. To stay on the Soccer field our Robot must avoid the Soccer field's white borders. How can we teach our robot to know when it sees white?

The highest reading inside my Soccer field is 60, obtained in the "light green" part of the Soccer field. To be able to tell my Robot how to see the difference between the light green and white parts of the Soccer mat, I could use a value: However a light sensor reading greater than 63 would mean that the robot is outside the Soccer field, and that is a problem we must fix.

If your robot has the light sensor plugged in to a different socket, you will have to change this code. If a robot Soccer player that has gone over the edge of the green and black playing field into the white surround, the code above will cause the Robot to retreat backwards on to the Soccer field.

It works like this: The command above will tell motors A and C start to go backwards, taking the Robot back towards the playing field. I have used power However a greater power could be used when testing is complete. The circled loop above will allow motors A and C to continue running backwards sending the Robot backwards until the Robot is back in the Soccer field. The code above is quite sufficient to tell our Soccer Robot to go back to the mat.

They will continue running after leaving the loop. This may confuse us when this code is inserted in to our Soccer program. It is important to test that this code works, before using it as part of a bigger Soccer program.

To do this we download this program into our Soccer Robot, and run it. When placed on your Robot Soccer mat, the robot should do nothing if placed inside the playing field, but should retreat backwards if placed anywhere on the white border surrounding the Soccer playing field.