The rangefinders are used to detect any objects that are near the robots. The robots have three rangefinders in front and two in the back.

Sample code

#include <dragonfly_lib.h>
 * Turns the orbs red when something is in front of them and
 * green when nothing is in front of them.
void rangefinder_sample(void)
  range_init(); // must be called before using the rangefinder code
  orb_init(); // must be called before using the orb code

  while(1) // repeat the following code in brackets forever
    int distance = range_read_distance(IR2); // gets the distance of the nearest object as read by rangefinder 2
    if(distance > MIN_IR_ADC8) // if the distance is larger than MIN_IR_ADC8, the rangefinder sees an object
      orb_set_color(RED); // sets the orb color to red
      orb_set_color(GREEN); // sets the orb color to green

Header File

For a full list of functions, see the rangefinder code header file

Hardware Documentation

More details about how the rangefinders work: Rangefinders details


If the rangefinders are not working, see the rangefinder debugging guide: Rangefinders Debugging


rangefinders_front.png (254 KB) Emily Hart, 09/16/2009 08:45 pm

rangefinders_back.png (249 KB) Emily Hart, 09/16/2009 08:45 pm

rangefinders_schematic.png (28.4 KB) Emily Hart, 09/16/2009 09:47 pm

Rangefinder_Offset_Values.xlsx (21.8 KB) Megan Dority, 01/21/2010 09:21 pm