This article explains a design of both hardware and software of IR ball sensor that my former RoboCupJunior team have been researching. Since the rules have been updated in 2017, active IR ball is only used for a RCJ lightweight league, and Open league is now using a passive ball as of 2022. If you are interested in the development of a passive ball sensor that requires more additional developments, please refer to the following article: Self-made 360°Camera for RoboCupJunior 2017.
Basic principles of detecting IR pulse ball
The waveform of the IR pulse ball is very unique, and it allows robots to detect the distance from the IR sensor by just reading a pulse width using a digital pulse input or combination of analog smoothing circuit and ADC input. As you can see in the waveform description provided from ELEKIT, the MODE-A which is now officially used for the game, has multiple amplitudes of IR emission. Since the low-amplitude IR light is not reaching a long distance, the pulse observed by the robot is getting shorter as the distance is getting far. As a result, the pulse width that the IR sensor outputs is getting shorter as the distance increases. Note that the 40kHz wave is just a carrier wave which prevents interference with environment light such as sunlight, it won't affect the sensor’s hardware and software.
You also need to determine the angle as well as the distance. Generally, direction can be determined by using multiple sensors that have a certain directivity. For example, Figure 1 shows the IR ball sensor that was developed by the team I belonged to, and there are 12 sensors installed as well as the black-painted plastic sensor mask that makes the sensor directivity sharp.
Figure 1 Hardware for sensing test consisted of 12 TSSP58038 and atMega168P with Arduino bootloader.
Selecting IR pulse sensor for ball sensor
Firstly you need to select the good IR pulse sensor for the purpose, a ball sensor for RCJ soccer. In the past, there were actually some example IR pulse sensors in the rulebook, Soccer rules (2017) - RoboCupJunior, Appendix I: Technical Specification for pulsed Soccer Ball”, and it says;
Balls with these specifications can be detected using specific sensors from HiTechnic (IRSeeker - information on distance and angle) but also common IR remote control receivers (TSOP1140, TSOP31140, GP1UX511QS, ... - on-off detection with a possible gross indication of distance).
As you already know, the IR pulse signal is widely used for a very short distance communication such as a remote controller of house electronics, and hence the majority of IR pulse sensors on the market are designed for such kind of remote control application. IR remote controllers that were introduced in the rulebook, TSOP1140, TSOP31140, GP1UX511QS, are also the case.
The characteristics of pulse sensors are different depending on the application, which generally appear on the datasheet as “the purpose of use”. Figure 2 illustrates the comparison of two sensors in different applications, and you can see how they different each other, but these two are likely the “pulse sensor”. The significant difference you have to think about is how the waveform emitted by the transmitter reaches as the output signal of the pulse sensor. In the remote control application, the waveform is not preferred to be modified between the transmitter signal and receiver signal, but in the presence application, the waveform changes between them and the user detects walls or obstacles using that changes.
This difference of characteristics affects enormously when we design the RCJ IR ball sensor because the information we need is not an original waveform that was illustrated in the waveform description MODE-A, but how the waveform decay during the transport. The most important factor to determine if the pulse sensor is appropriate for the IR ball sensing is whether the sensor has an Automatic Gain Control (AGC) which is a feedback circuit controlling the sensor gain in order not to be affected by the distance attenuation.
For example, the TSSP58038 IR pulse sensor that my team used doesn’t have an AGC, and it allows us to determine the distance by just measuring pulse width using microcontroller. However, since the sensor for presence application like the TSSP58038 has very high sensitivity and you can’t change the gain, you might be troubled with a lack of directivity as long as you are using those sensors without a sensor mask, so let me describe how you design the sensor mask in the next section.
Sensor directivity and sensor mask
When multiple sensors directing to different angles are getting almost the same waveform, it gets very hard to determine the angle of the ball from the robot. We have tested a number of sensors in a number of configurations so far, and have experienced some difficulty on getting angles especially when the sensor which is not directing the ball is returning the same pulse width as the sensor that is exactly directing toward the ball. Then, we needed to design the sensor mask that keeps each sensor’s directivity narrow enough. Figure 4 illustrates the design of the sensor mask we designed for Yunit3 robot, which is a model for RCJ world championship 2015 in Hefei China.
If you only need to read pulse width by the microcontroller, you can simply connect the sensor output pin to the digital input pin of the microcontroller. If you are trying to read a pulse width as an analog signal, you have to implement some smoothing circuit between the sensor output and ADC input. I am not writing a detailed explanation on this since the electrical design is quite simple.
The sensing software consists of two parts, sensor pulse width reading and ball position calculation. As you can see in the waveform of MODE-A, you have to observe one-cycle = 833 microsec at least to measure the pulse width. You might think this time will be longer if the number of sensors increases, but actually it is not as long as you are not reading each pulse width one-by-one as shown in Figure 6.
You can measure multiple pulse widths by switching the target as shown in Figure 7. If you use this method to read multiple pulse widths, you will not achieve a high accuracy of pulse width measurement compared to one-by-one reading, however, it actually doesn’t matter because the light amplitudes of MODE-A are only 4. In the sample program, there is a process to read GPIO directly from the register in order to increase speed of reading states of the digital input, but I don’t think it is needed to be honest.
The sample software can be seen from GitHub y6tada/RCJr_IRball . If your design is different from 12 sensors, 30 degree, front sensor = 0, etc, you need to modify them depending on your design. Also note that the quality of the software is not good because it is out of my profession even when I was in the RCJ team, so I would strongly recommend you to understand the basic theory and implement it yourself.
Testing results of distance/angle measuring
There are a number of ways to calculate angle and distance from each pulse width array, and it can be changed depending on the hardware configuration. Below are some of the methods we have tried in our robot so far.
Until the 2015 competition, we used method 2 because the implementation was very simple and it can get the distance with a certain accuracy. We switched to the vector calculation after 2016, and that results in more accurate ball position detection.
- maxSensorNumber and maxPulseWidth
- Get the angle of the sensor that observes the longest pulse width
- Get the distance from the longest pulse width
- maxSensorNumber and activeSensors
- Get the angle of the sensor that observes the longest pulse width
- Get the distance from how many sensors are detecting IR signals
- Vector calculation
- Get both the angle and the distance by vector calculation
Movie.1 Ball Tracking Test with Each Reading Method
The direction can be detected to a certain extent, but the distance is not accurate. If you want to get accurate distance data, you need to combine multiple sensor data somehow.
Counting how many sensors are detecting an IR signal is very simple but useful for distance measurement if you are using a circular ring shaped sensor mask. The result of distance measurement is much better than method 1 which uses only one sensor pulse width, and still very easy to implement.
Vector calculation is a bit complicated but very effective to improve the sensing capabilities. Most of the sample source code is for this calculation. If you need more performance, I would recommend trying this.
Thanks for reading. If you have any suggestion, comment, request, let me know in the comment.