Infrared sensors are another method to find obstacles and the distance from the robot. The principle of infrared distance sensors is based on the infrared light that is reflected from a surface when hitting an obstacle. An IR receiver will capture the reflected light and the voltage is measured based on the amount of light received.
One of the popular IR range sensors is Sharp GP2D12, the product link is as follows:
http://www.robotshop.com/en/sharp-gp2y0a21yk0f-ir-range-sensor.html
The following figure shows the Sharp GP2D12 sensor:
The sensor sends out a beam of IR light and uses triangulation to measure the distance. The detection range of the GP2D12 is between 10 cm and 80 cm. The beam is 6 cm wide at a distance of 80 cm. The transmission and reflection of the IR light sensor is illustrated in the following figure:
On the left of the sensor is an IR transmitter, which continuously sends IR radiation, after hitting into some objects, the IR light will reflect and it will be received by the IR receiver. The interfacing circuit of the IR sensor is shown here:
The analog out pin Vo can be connected to the ADC pin of Launchpad. The interfacing code of the Sharp distance sensor with the Tiva C Launchpad is given further in this section. In this code, we select the 18th pin of Launchpad and set it to the ADC mode and read the voltage levels from the Sharp distance sensor. The range equation of the GP2D12 IR sensor is given as follows:
Range = (6787 / (Volt - 3)) – 4
Here, Volt is the analog voltage value from ADC of the Vout pin.
In this first section of the code, we set the 18th pin of Tiva C LaunchPad as the input pin and start a serial communication at a baud rate of 115200:
int IR_SENSOR = 18; // Sensor is connected to the analog A3 int intSensorResult = 0; //Sensor result float fltSensorCalc = 0; //Calculated value void setup() { Serial.begin(115200); // Setup communication with computer to present results serial monitor }
In the following section of code, the controller continuously reads the analog pin and converts it to the distance value in centimeters:
void loop() { // read the value from the ir sensor intSensorResult = analogRead(IR_SENSOR); //Get sensor value //Calculate distance in cm according to the range equation fltSensorCalc = (6787.0 / (intSensorResult - 3.0)) - 4.0; Serial.print(fltSensorCalc); //Send distance to computer Serial.println(" cm"); //Add cm to result delay(200); //Wait }
This is the basic code to interface a Sharp distance sensor. There are some drawbacks with the IR sensors. Some of them are as follows:
In the next section, we can discuss IMU and its interfacing with Tiva C LaunchPad. IMU can give the odometry data and it can be used as the input to navigation algorithms.
3.133.144.197