Debubgging Dragonfly Rangefinders

Think rangefinders are screwing with you? Most likely, they are loosely connected and need to be pressed firmly into the Dragonfly. Try this first.

Alright, still screwy? Time to run a test. Program the below code.

int main(void)
{
    usb_init();
    analog_init(ADC_START);
    range_init();

    sei();

    while(1) {        
        usb_puti(range_read_distance(IR1));
        usb_putc('\t');
        usb_puti(range_read_distance(IR2));
        usb_putc('\t');    
        usb_puti(range_read_distance(IR3));
        usb_putc('\t');
        usb_puti(range_read_distance(IR4));
        usb_putc('\t');    
        usb_puti(range_read_distance(IR5));
        usb_putc('\t');

        usb_puts("\n\r");

        delay_ms(500);
    }
}

Put the robot in an open space and look at the serial output. You should see 5 columns of "-1". The columns correspond with rangefinders IR1 - IR5 matching the labels on the board.

Now test the rangefinders by obstructing their line-of-sight (with your hand or ideally a flat surface). See if the values increase/decrease as you increase/decrease the distance of the obstruction from the rangefinder. Don't get too close, or you'll run into the minimum range.

Stuck Values

If the values don't change when the obstruction is moved farther and closer, your rangefinder might be loose. Press the rangefinder firmly against the board to ensure a good connection. If it's still stuck, try replacing the rangefinder with another one (preferably known working). If the replacement rangefinder gives good values, the replaced rangefinder is defective. Trash it.

Phantom Readings

If you find that one rangefinder reading changes when you obstruct a different rangefinder and both readings are relatively close, you have phantom readings. This is problem caused (presumably by the Dragonfly board) when the phantom rangefinder is loose or not connected. Firmly connecting a rangefinder should resolve the problem.

These are known problems and their symptoms. If you find others, add them here.