-
Notifications
You must be signed in to change notification settings - Fork 0
Basic obstacle avoidance
a-brannen edited this page May 27, 2021
·
8 revisions
Obstacle avoidance is a stand-alone functionality on the Alset Vehicle (Arduino board). Obstacles are avoided by reading the front and back sensors of the vehicle.
- The car must be able to avoid objects detected by its sensors.
- The car must be able to travel an arbitrary distance while avoiding objects.
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);
}