Stirling Robot software: Avoidance
20th March, 2018
In this article we'll cover the RobotMoves Avoidance module. To see the other modules available, click the Software Overview button above.
You can download the RobotMoves suite of modules here. This was updated on the 6th of February, 2019.
The Avoidance program uses the RobotMoves movement and sensor modules to drive a robot autonomously without (usually) bumping into stuff.
It drives easily in basic rooms, and in more complex areas it can usually go five minutes without crashing into something or getting stuck. Fortunately, it's improving rapidly.
To use the program you'll need three distance sensors facing front, left and right. You'll need to configure the sensors in robot_sensors.py as 'forward', 'left' and 'right'. Your distance_sensor array should look like this (with your own pin numbers and adjustments):
You'll also need your motors configured and callibrated in robot_moves.py, as described earlier in the article.
You can now try the avoidance program with default settings. In an SSH terminal type:
Your robot will check the forward distance sensor and if there is room to move it will pivot 30 degrees left and right to measure the clearance on the flanks. If everything is clear it will move forwards 40 cms and repeat. It will also monitor the side sensors to watch for walls closing in, and veer away if required.
If the robot finds the way forward is blocked, it will measure the left and right distances and turn 90 dgrees towards the longest measurement.
If the way forward is clear but one of the flanks is not, the robot will veer 15 degrees away from the flank obsticle.
There are lots of settings you can adjust in the avoidance.py file to fine tune the program.
The min_forward variable on line 50 is the forward clearance in centimeters required before the robot will move forward. The min_flank variable on line 52 is the minimum clearance on the diagonal flanks. On line 54, flank_degree sets the degrees the robot pivots to check the flanks.
The travel_distance on line 60 is the number of centimeters the robot moves forward each time. The min_side variable on line 63 is the minimum side clearance before the robot will veer away from a wall. The opposite_side_clearance variable on lin 65 is the minimum clearance on the opposite side of the robot before it veers. If there is no room to veer the robot will turn around and move away from the narrow passage.
On line 67. veer_degree sets the degrees the robot will veer away from a side objects. It will keep veering this amount until is is no longer closing in on the wall.
There are settings to control how the robot decides whether it is either trapped, or endlessly circling a room.
To avoid endlessly circling a room, the program keeps track of recent turns. If it has turned left six times without a right turn it will decide it is circling and look for the first opportunity to turn right and hopefully find a way to exit the room.
You can change the amount of turns by setting turn_limit on line 39.
To detect when it is trapped in place, the robot counts the number of turns performed without moving forward in between. After six turns without finding forward clearance, it will pivot 45 degrees then start again from the new direction.
You can change the number of turns allowed with the blocked_limit variable on line 47.
Avoidance is included in the robot_moves folder now.
That's all for today, check back soon.
Previous: RobotMoves sensor module
Next: RobotMoves CamBot module (Coming soon)