I recently ran a Hangout session with a group of girls on the other side of the world. They were having some issues getting their IRSeeker to accurately track an IR Soccer ball and just needed some tips to get them going.
This post sets out 1 possible way of getting a robot to track an IR Soccer ball using the HiTechnic IRSeeker V2 sensor using the NXT-G software. If you haven’t already done so, download the custom IRSeeker block and install it in the NXT-G software.
The sensor itself comprises 5 individual detectors, that when used together can tell us if the ball is located in 1 of 9 different locations. From the diagram below we can see that if the IRSeeker gives us a reading of 1, then the ball is all the way to the left. If it gives a reading of 5 the ball is in the middle and a 9 means the ball is all the way to the right. A reading of 0 means that it cannot see a ball at all.
Before we start programming, we need to think about what we want the robot to do for each value we may receive from the IRSeeker. I’m going to keep it very simple for this tutorial, but you can add in more complexity once you have it up and running.
Let’s start with some of the easier decisions:
- If I receive a 1, then I want the robot to do a fast, sharp turn to the left
- If I receive a 5, then I want the robot to drive forward as fast as possible
- If I receive a 9, then I want the robot to do a fast, sharp turn to the right
- If I receive a 0, I’ll just make the robot stop moving altogether
Some trickier decisions will be 2,3,4 and 6,7,8. For each of these conditions I’ll still want to turn, but perhaps not as sharply and perhaps not as fast. I’ll leave it up to you to play around and see what works best for your robot.
The Program
The key to this program is the Switch Block. Normally the Switch block is tied to a sensor and will give you something like the following
IF Sensor reading is greater than a given amount
Do Action No. 1
ELSE
Do Action No. 2
This works well if you only have two things to worry about, but in our case we have 10 separate values that will each have a different action associated with it. The first thing we need to do is to set up the Switch to be able to take 10 separate values.
1. Set up the Switch to make decisions based on a ‘Value’
That value will be of type ‘Number’ (not Logic or Text).
2. Uncheck ‘Flat View’
Flat View is used to flatten out our two conditions so we can see them both on the screen at the same time. Unchecking this will convert to ‘Tabbed’ mode where each condition is indicated with a Tab.
3. Add in more conditions
The ‘Conditions’ column in the configuration panel shows you how many conditions are currently available. Pressing the “+” button will add conditions (and you will see more Tabs added to the Switch Block itself). Let’s go for 10 conditions.
4. Check the values that trigger each Condition.
The second column in the Conditions section shows you what value will trigger each condition. The default is that if I receive a ‘0’, I will run condition 1. If I receive a ‘1’, I’ll run condition 2 and so on. You can play with these if you want, but I’m going to leave them as is.
5. Start filling in the actions.
By selecting the appropriate Tab, I can then specify exactly what I want my robot to do for each condition. 0=stop, 1=left, 5=straight, 9=right. I’m setting all movements to be ‘unlimited’ as I want them to keep doing the same thing until the number changes. ie, if I can see a ‘1’, then keep turning, keep turning, keep turning until I see a number that is not 1.
6. Configure the whole switch so that the IRSeeker is the sensor sending it numbers.
Grab your newly installed IRSeerker Block. Use the datahub to wire the ‘IRDirection’ value to the Switch.
7. Put the whole thing inside a loop
This is done to ensure the programming is constantly going back to the start and checking for new values from the IRSeeker. I’ve set mine up to loop forever, but perhaps you set yours up on a time (chase the ball for 10 seconds?) or another sensor (chase the ball while the compass sensor is pointing towards goal?)
Other ways of doing it.
Check out these other links (one is mine that I wrote a few years ago and forgot about!). Remember that there are always many ways of solvinf the same problem. See if you can understand all of them.
http://robocupjunior.org.au/soccer_training
http://www.drgraeme.net/DrGraeme-free-NXT-G-tutorials/Ch106/Ch106V1G/default.htm
Conclusion:
Just remember that I have only presented a framework for making this work. You’ll need to fill in the blanks and also test / tweak to suit your robot. If you manage to get it working, let me know in the comments below!
1 Comment
Comments are closed.
Thank you for sharing your experiences with this sensor. We are working on pulling some data log information using the data logging block but struggling with how to see this in the Experiment data or to export it as a CSV file to read into Excel. If you've had any experience with this let us know. We will post what we find on our blog at http://tardisrepaircompany2015.blogspot.com/. Thanks again for sharing what you have its been very helpful for us!
Taryn Campbell, Tardis Repair Company