The goal of this project was to create a robot that would be able to reach a goal geolocation from any starting position while avoiding obstacles. Performing this operation with multiple goal locations, the robot is able to travel a predefined path. Robot operation is based on two modes: Cruise and Wall follow (for obstacle avoidance). Cruise mode uses readings from GPS and Compass while the wall follow mode uses distance information acquired from 5 ultrasonic sensors as well as compass readings. The main operation loop runs at 20Hz.
Cruise mode loop calculates goal heading from current to goal location. Offset between goal heading and current heading is the error that is passed to the cruise PID algorithm that operates the wheel speeds in order to maintain direction.
During cruise mode distance measurements are performed. If an obstacle is detected the main algorithm switches to wall follow mode. Only exception is in case obstacle is detected on the side of the robot and the robot is moving away from it to get to the goal so the obstacle can be ignored.
Wall follow mode is used to avoid obstacles. In order to avoid interference from ultrasonic sensors, measurements are performed in 50ms intervals so each sensor gets to perform 4 readings every second. Adaptive PID algorithm is used to operate the wheel speeds in order to move around obstacles.
The LCD is used to display debug data and the three potentiometers are used to fine tune cruise and wall follow PIDs. One thing to note is that compass has to be very carefully placed on the robot because it is very susceptible to interference from other components, e.g. the LCD was causing problems when it was placed just an inch closer to the compass.
1 x Arduino Pro Mini
1 x NEO6MV2 GPS Module
1 x HMC5883L Triple Axis Compass
1 x L298N Motor Driver Controller
2 x 12V 122 RPM Gear Motors + 80mm Wheels
3 x 10k Potentiometer
5 x Ultrasonic HC-SR04 Module
1 x LCD Display Module HD44780 16×2 Character /w I2C interface
6 x AA Rechargeable Batteries + holder case
The code is written in C++ and is hosted on my GitHub repo: https://github.com/lukagabric/LRover
Videos below show test drives with obstacles. Goal location is marked with the bag. Once robot reaches the goal location it stops and turns in place. Tests in the videos are performed in very cloudy weather which did not have impact on GPS readings.
Test drive 1
Test drive 2:
Heading and distance calculation: http://www.movable-type.co.uk/scripts/latlong.html
Compass calibration: http://hobbylogs.me.pn/?p=17
If you liked this blog post I’d appreciate if you followed me on Twitter