This is a project in progress. It doesn't actually work yet, but feel free to keep coming back to catch up on progress.
Note: I am waiting on a (proper) Nano Dual Motor Driver from RobotShop, because the cheap Chinese one I got of eBay is not up to scratch. Serves me right for being stingy. That's what all the styrofoam is all about. Currently it doesn't actually balance properly.
Note: The standard PID calibration strategy (ie get it balancing with P, add D until it stops shaking, add I to stop it wandering) is not working. It seems to be two issues: 1. the non-linear response of the motor to the power value sent to the motor controller, and 2. delays between the IMU reading the value, and the motor reacting. Time to get out the old physics text-book and model it properly (with the delays).
Because it is the 'hello world!' of modern robotics.
Arduino Nano | EBay | Lightweight, 5V tolerant, easy to program, cheap as silicon chips, and no tears when clumsy roboticists fry them. | |
Bluetooth receiver | EBay | If you want to control it remotely from the PC or a phone. | |
BNO055 or LSM9DS0 | EBay | IMU which does the orientation calculation on-chip. | |
DC Motors | AliExpress | "Mini 2WD self-balance robot car chassis balance wheel car frame" from "SINONING Official Store" on aliexpress.com. | |
Nano Motor Controller | EBay | See notes below about the good, bad and ugly. | |
Aluminium Bar | Bunnings | Easy to bend, drill and fashion - for the frame. | |
7.4 Li-ion battery | EBay or local hobby shop | Should try out an 11.1V one of these. |
Because I ordered these DC motors with encoders, and it seemed a shame not to use them.
Because it's winter, and indoor robots can be built next to the fireplace.
Because DC motors require a different timing logic to steppers, and it should be easier to make a faster robot than with steppers.
These two Nano Motor Controllers look almost identical (one has the Nano perched on it, but use your imagination). The one on the right is a cheap Chinese eBay $AU8 job, and the the one of the left is a RobotShop one for around $AU53. The cheap one has issues:
There are two motors, each with an encoder. The encoders have two lines each, A and B, which output square waves which are 90 degrees out of phase. Hence a total of four encoder lines are connected to the Arduino Nano, but the Nano (even when we put a sensible Nano Motor Controller on it), only has two hardware interruptable pins.
It is possible to decipher a motor's encoders with one interrupt pin and one ordinary (digital read) pin.
Line A can be connected to the interrupt line, and B connected to the ordinary digital read port. An interrupt routine can be set to be called whenever the state of A changes (ie either LOW to HIGH or HIGH to LOW). This means that when B changes state we don't know about it, but it doesn't matter. When A changes state, the interrupt handler can query the state of the B pin, and effectively work out what change was missed. The logic works out very simply: if both A and B now have the same state the encoder went one direction, if they are now different, they went another.
This method loses one bit of resolution, but this is unlikely to be a problem in practice. The Arduino source code is there if this explanation doesn't make sense.
There really isn't much software to make this go. This is a pretty simple program, but it hasn't been optimised yet. Watch this space.