Here is a project I have been working with on and off for about a year – Alvin the autonomous RC car. The robot is built to comply with the rules of two Swedish robot competitions, Robot SM and Stockholm Robot Championship, where the objective is to race three other robots around a track without any form of remote control. Rules vary somewhat, but each heat typically lasts until one robot reaches 7 laps, or for max 3 minutes. The robots are then given points according to the number of laps they have completed at this point. The participants can also signal the organizer to flip or turn the robot if it crashes or gets stuck, at the cost of one point.
Here is Alvin in action, racing some other robots from the Norbot team at a recent meetup:
- Wltoys A222 RC car
- Texass Instruments TM4C123G Launchpad microcontroller evaluation board
- My own custom Launchpad protoboard booster-pack
- Sharp GP2Y0A21YK0F analog distance sensors from Ebay
- “10A Brushed ESC Motor Speed Controller for RC Car without Brake” off Ebay
- A3144 hall effect switch, also from Ebay
- Rare earth magnets (D4x2mm), Ebay as well
Since Alvin is built on a RC car, both the steering servo and throttle ESC have a maximum update rate of once per 20 ms, or 50 times per second. For the first implementation, therefore, the processor simply runs the algorithms for calculating new steering and throttle values once every 20 ms and then just waits in between.
For the steering, Alvin uses two Sharp distance sensors to measure the distance to the side walls and a third to detect obstacles in front. To stay in the middle of the track, it simply compares the distance to the walls and compensates the steering to make them equal. This rather simple approach could probably be improved a lot to gain more speed.
Since the track contains a hump, the power to the motor can not be hardcoded – it needs to increase in the uphill. To control the speed, a hall effect sensor is reading two magnets mounted on the drive shaft. The algorithm converting pulses from this sensor to a throttle setting has so far proven to be the hardest to implement, mainly because there are only two pulses per revolution of the drive shaft. This means there are normally just 0-2 new pulses recorded every time the algorithm runs, making it hard to determine the actual speed. To work around this, the delta in revolutions is instead calculated 10 iterations back in time. The resulting speed value is then used as input to a PI controller which calculates the throttle.
Alvin raced for the first time last year at Stockholm Robot Championship and I was very happy to finish 6th without ever tuning it on a full size track before! I have since worked on the throttle algorithm to make it as responsive as in the video above, so I think it could do even better today.
- Extend front bumper to go around the wheels to avoid getting stuck against the wall.
- Add a speed sensor with more pulses per revolution to allow better throttle control.
- Add more distance sensors to enable a more advanced steering algorithm.
- Add roll cage or body to protect the electronics and improve the looks.
Autonomous robot racing is a fun and fairly affordable way to put your combined engineering skills to the test, including both mechanical, electrical and software components. Being new in my city, it has also been a way to meet like-minded people and a reason to go down to the local hackerspace.
Finally, here is a playlist from Stockholm Robot Championship 2016 if you want to see some more action!