Skip to content

Basic obstacle avoidance

Jensah edited this page May 21, 2021 · 8 revisions

Obstacle avoidance is a stand-alone functionality on the Alset Vehicle (Arduino board). It avoids obstacles by reading the front and back sensors of the vehicle.

Below is the implementation used to test the cars ability to avoid obstacles, running until it reaches a distance of 100m:

const auto STOPPING_DISTANCE = 100;

void avoidObstacle() 
{
    unsigned int forwardDistance = frontUSSensor.getDistance();
    unsigned int reverseDistance = backIRSensor.getDistance();

    bool frontStop = forwardDistance != 0 && forwardDistance < STOPPING_DISTANCE;
    bool backStop = reverseDistance != 0 && reverseDistance < STOPPING_DISTANCE;

    car.setSpeed((frontStop || backStop) ? 0 : DEFAULT_DRIVING_SPEED);
}

Clone this wiki locally