When I first fired up the trackers I found it helpful to print out the sensor pulse counts. In tracker.c, just before "switch(TRACKER_STATUS)", try printing out the values of LEFT_SENSOR and RIGHT_SENSOR:
Code:
if ( Tracker == LEFT )
printf( "L: %d, %d\n" , (int)LEFT_SENSOR, (int)RIGHT_SENSOR );
else
printf( "R: %d, %d\n" , (int)LEFT_SENSOR, (int)RIGHT_SENSOR );
Since the beacon pulses at 100 Hz and the machine cycles at about 38 Hz, a good sensor will see 2 or 3 beacon pulses per cycle. A value of 0 or 1 indicates no IR or "on the edge". That should help you decide if the sensors are working.
I've had a lot of issues with the tracker code, and I am now trying a different approach to tracking the beacon. The approach of the default tracker is to try to get both sensors seeing IR. There's at least two problems with this.
First, imagine the beacon is on our right at about one or two o'clock, and the moveable goal is dead ahead at 12:00. The 2X ball is this big, shiny, spherical reflector, so it makes a nice IR reflection. The tracker looks forward to 12:00. The left sensor sees the beacon's reflection in the ball; the right sensor,
because it is completely open on the right side, sees the beacon itself to its right. The algorithm is satisfied (both sensors see IR). But the tracker is pointing at 12:00, not at the beacon at 2:00. Oops. I have watched our robot push the moveable goal straight downfield during the autonomous mode, thinking it was heading for the beacon.
The other problem is that the sensors will register IR over a very wide range of angles, especially when near the beacon. With a 1" length of heat shrink on the sensors (not cut away but a complete tube), at a range of about three feet the sensors see the IR over more than half the range of the servo. With the default approach ("both sensors see IR" means it's pointed at the beacon), the trackers will be satisfied over a very wide range of angles.
I am working on a new approach where the left tracker constantly dithers back and forth across the left EDGE of the beacon beam pattern, and the right tracker dithers across the right edge of the beacon pattern. When a sensor goes from light to dark, the servo reverses until it goes from dark to light. Each time it reverses it notes the servo position. The average of the dark-to-light and the light-to-dark servo angles is considered the angle to the edge of the beacon beam pattern. The average of these values for left and right
trackers should point at the beacon itself. Note that this approach requires only one sensor per tracker.
A similar approach to finding the edge of the beam pattern is to use two sensors on each tracker, and adjust the servo until they straddle the "edge of darkness". If both see it, move away from the light. If neither sees it, move towards the light. If one does and the other doesn't, you're good, just stay there. (If the other does and the one doesn't, you're lost!)
I have experimented with both approaches and decided that the constant dither is better because it is constantly re-measuring, and can register a small change in angle, whereas the straddling approach can be satisfied over some range of angles and think nothing has changed.
But reflections are still a problem. My solution is to first "scan the horizon" over the entire servo range. I wrote test code to step the servo from left to right and print out the sensor pulse count. I get outputs like this:
Code:
___1233_____12332322323323232321_______1323223____
This shows two reflections at the sides and the direct IR in the middle. Before starting to dither, I point the tracker at the edge of the direct IR source, so it doesn't dither on the edge of a reflection.
My code is still experimental -- I hope to get it fully functional before the next regional!
-Norm