Range Finders

modified on 14 July 2010 at 17:02 - 2,449 views

From RoboWiki

(Redirected from Tutorial: Tabletop Sensors)
Jump to: navigation, search
Tutorial 2. Sensors

Topic
Tutorial: Sensors
Related Topics


Download this tutorial's presentation PDF

Range finders are sensors that are designed to find the distance between the sensor and an object obstructing the sensor's beam. The beam may be composed of infrared or sonar signals. Sensors return either an analog signal that must be interpreted or a digital signal. Range finder sensors are critical to robotics movement and control algorithms. It is important to note that all sensors must be "configured" to read real-world distances: a function must convert from analog to a real-world distance.

Contents

[edit] Analog Reading

The Arduino supports six built-in analog input pins. In our below example, we have the red cable to the 5V pin, the black cable on the Gnd pin, and the yellow signal pin on Analog In pin 0.

To read an analog signal on the Arduino, we will be using the int analogRead(pin) function.

/*
 * Read IR Sensor
 * Reads an analog pin and prints the value onto the serial.
 */
 
int DataPin = 0; // Declare our Data Input pin as Analog In pin 0
 
void setup()
{
  // Initialize serial communication
  Serial.begin(9600);
}
 
void loop()
{
  // Read the analog pin
  int value = analogRead(DataPin);
 
  // Write this to the serial
   Serial.println(value, DEC);
 
  // Delay the main loop for a half of a second
  delay(100);
}

From here you are able to save sample range values and, using the methods listed below, configure your sensor.

[edit] Sonar Sensors

A sample sonar device is to the left, with an IR range finder to the right.

Sonar sensors use ultra-sonic sound pulses to find an object. Based on the time it takes for the pulse to return, it returns the distance of the obstructing object in an analog signal.

The benefits of sonar sensors is that they are indifferent to light and color, and have a large field of view. Sonars are perfect for avoiding general obstacles. Sonars are sensitive, but are less sensitive to picking up interference to sound relative to environmental effects.

With most sonar sensors there are certain conditions in which you should be aware of. Some sonars have a large cone, which means that it's angle of field of view is large and can receive false-positives from obstructions such as the robot it-self or even the ground the robot is on. In our case, the sonar has a narrow cone and long field of view which is still efficient enough for general use but limits any possible errors.

Sonars, similar to IR, are interfaced with the same three basic cables: Power (red), ground (black), and the signal (yellow). The club is currently using the LV-MaxSonar-EZ1. Some advanced sonars interface through other protocols, such as IIC. This specific sonar sensor provides a multiple methods of interfacing with extra functionally and different calibrations, but are not covered in this article.

[edit] Conversion Function

The sonar sensors are easy to implement in hardware as well as in code since they follow the exact same instructions are the above mentioned IR sensors. The except is that these sonar sensors have a linear relationship between distance and voltage. This means that for every 10 mV returned by the sonar, it is about 1 inch in distance.

#include "math.h"
 
// Returns the distance in inches based on the given voltage for a sonar sensor
// This function is based on the fact that or every 10 mV returned by the sonar,
// it is about one inch in distance.
int GetDistance(int AnalogValue)
{
     // We convert the analog value to the voltage (1024 is the highest value)
     // Then divide by 0.01 to convert to the distance
     double ratio = ((double)AnalogValue / 1024.0) * 5.0 / 0.01;
}

[edit] IR Sensors

IR sensors, well documented on Acroname's page, are infra-red devices that calculate distance based on the angle of the returned IR beam. IR sensors are more sensitive, have faster response time (speed of light is faster than sound) and are more accurate (due to a narrow field of view) than sonar. The negative aspects are the that they have a narrow field of view, can receive interference from other IR sources (sun, incandescent light bulbs, etc..), as well as return erroneous values for certain textures/colors (such as black). Other factors to consider in the usage of IR sensors is that they return an analog signal that is not linear to distance. An interpolation, documented below, must be done to obtain accurate data.

Most IR sensors have three interface cables: Power (5V), Ground, and Signal. The standard IR device used in the club is Sharp's GP2D12. See the data sheet here.

Three cables come from the sensor: Source (Red), ground (Black), and signal (Yellow). Connect the source (red) cable to Vdd (Positive supply, typically +5V) and connect the ground (black) cable to Vss (Negative supply, 0V). Please note that this device typically pulls 33 to 50 mA. The signal cable (yellow) is connected to in different ways for each Microcontroller.

[edit] Conversion Function

The calibration data of Actual Distance (cm) vs Analog Value. Click for a larger image.

As mentioned above, the given signal is non-linear. To correct this, you should manually calibrate each IR sensor. To do this, we will setup an experiment to collect multiple data points in excel, graphing the actual distance measured by hand versus the returned analog value. By doing this, we will be able to find an equation that takes the analog and returns the distance. Certain close-range distances will return erroneous values, such as any distance smaller than 10 cm. Certain distances beyond 80 cm can also be considered erroneous.

Once the graph is built, use the solve function in Excel to generate a exponential best-fit line. Remember to remove erroneous points as mentioned above. In the sample image to our right, we generated an equation for our best-fit line, and solved it as an equation used in our calibration function code below:

#include "math.h"
 
// Returns the distance in cm based on a given analog value
// This is based on our calibration equation of (analog value) = 556.7 * e ^ (-0.03 * x)
// This C-function returns: ln( (analog value) / 556.7) / -0.03
int GetDistance(int AnalogValue)
{
     return (int)(log((double)AnalogValue / 556.7) / -0.03);
}

[edit] Other Sensors

Many other sensors exist such as laser-range finders, Light Detection sensors, sound (microphones), Line Detectors, etc. Even simple devices, such as Bump Sensor, are types of sensors. Read more about these sensors throughout the RoboWiki.

[edit] Building Schedule

If you or your team are building for a specific robotics competition during a semester format, make sure you follow our Tabletop Design Schedule. Contact any club executive to learn more about differences in the schedule for your respective semester.

[edit] Links