Sensors:Exercise3:Sonar Sensor

From The Robotics Primer Workbook

Setup

This exercise requires the use of a sonar sensor. There are many sonar sensors to choose from, and we have chosen to use the Devantech SRF05. This is a relatively simple sonar sensor, compact, and low cost. It has a range of 3cm to 4m, operates at 40kHz, and easily plugs into the Robostix or Create.

You will need to create a cable to connect the SRF05 to the robot.

Howto:Build a SRF05 Sonar Cable

Sensor Calibration

Once you have a cable attached to the sonar device, plug it into PortC, Pin 1 of the robostix.

Sonar robostix connection.jpg


This sonar returns a distance measure in the form of a pulse width. A pulse consists of two transition on a binary line: low->high : high->low or high->low : low->high. In the case of the SRF05, the pulse is low->high : high->low. The time between the two transition points correlates to the range reading. The only calibration necessary is to convert the pluse width reading into a distance measurement.

StepDescription
1Place the sonar on a flat surface and position a flat obstacle 20cm directly in front of it.
2Fill in the exercise Update function with
std::cout << client->GetRobostixSRF05Value() << std::endl;
Compile
$ scons
3Run the exercise, and take an average value of the printouts.
4Use this average to solve this equation <tex>factor=avg/0.2</tex>.
5Use this factor to compute any range with the equation <tex>Range=sonar value/factor</tex>
6Test your solution by changing the exercise Update function to std::cout << client->GetRobostixSRF05Value() / factor << std::endl;

Obstacle Avoidance

For this part you will implement obstacle avoidance. If you have completed the obstacle avoidance part of Sensors:Exercise2:Infra-red Sensor, then this part should be easy. The only difference is the type of sensor being used. Once, again mount the sonar on the front of the robot, and write control code to stop the robot before hitting an obstacle. The robot should also turn 90 degrees and continue on. This is a very simplistic approach to obstacle avoidance, but you also have only one range sensor available.

The sonar sensor has a much greater range than an IR. If the first approach to obstacle avoidance is too easy, try using more fluid motion. When the robot detects an obstacle, adjust the angular speed of the robot so that it continues moving forward while still avoiding the obstacle.

Solution

This solution rotates the robot when it moves within 0.2 meters of an object.