DistanceSensor Example

This example illustrates the use of the Distance Sensors on Robotino. If Robotino is placed in an obstacle cluttered environment then it moves around avoiding the obstacles. The example runs for 60 seconds.

Contents

Description

Robotino is equipped with 9 infrared distance sensors (labelled 0 - 8 ). In this example we read the voltage readings from the IR1, IR2 and IR9 sensor as they are in front of the robot.

Based on the readings from the distance sensors, we can find out if Robotino is approaching an obstacle or not. In case it is, we stop Robotino and let it rotate until all the three distance sensors do not detect any obstacles in front of them. If the sensors don't detect any obstacles in front of them then we let Robotino move forward with a constant velocity.

Code explanation

First we put the IP address of Robotino into a variable

url='192.168.0.1'

We then start our "stop watch" to limit the example execution to 60 seconds.

tStart = tic;

We initiate a while loop based on the condition that Robotino's bumper hasn't detected a collision. Here we obtain the distance sensor readings and based on a simple comparison decide whether if we are approaching an obstacle or not. In case Robotino is approaching one, using the OmniDrive_setVelocity function we stop the robot and make it rotate. In case there is no obstacle in front of Robotino then using the same OmniDrive_setVelocity function, we let Robotino continue moving forward.

If front sensors detect obstacles nearer than mindist given in meters Robotino should start rotating

mindist = 0.2;
while (Bumper(url) ~= 1)
    tElapsed = toc(tStart);
    % If 60 seconds are elapsed then exit while loop
    if(tElapsed >= 60 )
        break;
    end;

	values = DistanceSensorArray(url);

    if((values(1)<mindist)|(values(2)<mindist)|(values(9)<mindist))
        % Approaching obstacle
        OmniDrive(url,[0, 0 ,100 * pi / 180]);
    else
        % No obstacle ahead
        OmniDrive(url, [0.5, 0 ,0]);
    end;

end;

Once 60 seconds have been elapsed and the while loop is exited.

Video

A video of this example running can be viewed on youtube .