Soccer Tactics 2 - Find the Ball!
The second thing we want our robot to do is to find the ball.
If our robot is built according to the 2011 World Robot Olympiad rules, the 2011 New Zealand RoboCup Junior Soccer Rules and the 2011 Australian RoboCup Junior Robot Soccer Rules Open League, it can be equipped with a HiTechnic Seeker V2 sensor. If it is built according to the 2011 Australian RoboCup Junior Robot Soccer Rules Novice League, this HiTechnic Sensor is not allowed, and a LEGO Light sensor should be used. The discussion on this web page is about using the HiTechnic sensor. HiTechnic offers a "Football Kit" that includes a ball, seeker V2 and compass sensor; click here to see the reduced price.
When the HiTechnic NXT IR Seeker V2 sensor is mounted on a robot, the sensor will detect the direction of the Soccer ball, and indicate that direction by a number. If sensor is mounted on a robot with the sensor's mounting holes below the sensor, the direction numbers are as shown in the diagram below:-
If the sensor is mounted on a robot with the sensor's mounting holes above the sensor, the direction numbers are reversed, as shown below:-
If the Soccer Ball is straight ahead, the HiTechnic Seeker Sensor will give a direction number = 5. This will be the same if the sensor is mounted "upside down", "right way up", or "sideways". So, to find the ball, let us make our robot spin around until the sensor sees the Robot Soccer ball straight ahead (seeker direction number = 5).
The circled command above will make motor A go forwards.
The circled command above will make motor C go backwards. Motors A & C working together will cause our robot to spin on the spot, looking for the Soccer ball.
Note that my HiTechnic Seeker V2 sensor is plugged into computer brick socket 2. If your robot has your seeker sensor plugged in to a different socket, you will have to change this code.
The program above brings the HiTechnic Seeker V2 sensor into our program. But how do we know when it produces a direction number = 5?
In the code above, we have added a mathematics block. We have changed the sensor's command block to detect when the direction number "Equals 5". Note that we have connected the two blocks by a yellow wire. This allows the direction number to go from the Seeker block through the yellow wire to the Mathematics block. If you forget to do this, the program will refuse to work!
Next we want to make the robot continue to spin around until it sees the Soccer ball (when it sees a direction number = 5). To do this we need a loop.
In the code above, the mathematics block is connected to the loop with a green wire. When the mathematics block gets a direction number = 5 from the seeker block, it passes a "stop" signal through the green wire to the loop; this tells the loop to stop repeating. This code will allow your robot to leave the loop and obey the next command following the loop. We haven't put that next command in yet, but will soon.
Our Robot has Found the Ball - Now What?
There are lots of things we can tell our robot to do after it finds the ball. However, just so we can test that our code works, let us tell our robot to go forward one rotation each time the ball is seen.
The code above causes motors A and C to turn one rotation, causing the robot to go a short way forwards.
The loop in the code above causes the whole code to keep repeating forever, or until we turn our robot off.
This complete program causes the Robot to keep finding the Soccer ball, and following it - which is what we wanted.
Download this program to your robot, and test it to see that your robot does what you want it to do.
If there are problems, carefully check the diagrams above to make sure you have understood the method we have outlined above.
When everything is good, go on to the next step to find out how to tell your robot which is your opponent's goal!
DrGraeme.net - Family Fun With Robotics - LEGO NXT MindStorms - NXT-G - Robot Gen II Soccer step 5