Antweight Speed Controller
The Pololu Baby Orangutan board is a small module containing an Atmel ATMega328P micro-controller and a dual H-bridge motor drive chip, suitable for driving the 12mm gear motors commonly used in antweight robots. This article describes the software required to implement a 2-channel speed controller with built-in mixing and under-voltage protection.
The program makes use of the Pololu libraries which are licensed under the Creative Commons Attribution Share-Alike license. Consequently I decided to license my code under the same conditions so you are free to use it and modify it for your own purposes, but you must attribute it to me (a link to this site is fine) and share it in the same manner.
All of the low-level I/O is taken care of by the library routines, so there is only a main() function which is mostly one big while() loop. The code monitors the two R/C inputs and the battery voltage and drives two PWM outputs to control the motor speeds. It also drives the on-board LED to indicate a fault condition (loss of signal or battery voltage too low).
If you just want to use the program, here is the hex file.
The I/O pins used for the R/C inputs and battery monitoring are defined at the top of the file so it is easy to change them if you need to. The default pin assignments are as follows:
- R/C channel 1 = pin PC0
- R/C channel 2 = pin PC1
- Battery monitor = pin AD6
The Baby Orangutan module will operate from a 2-cell LiPo battery pack and provides a 5V regulated output at the VCC pin. This can be used to power the R/C receiver, but may not provide enough current for a high-power servo weapon.
The battery monitor input is limited to 5V, so must be connected to the battery pack via a potential divider. With a 2-cell LiPo battery, the potential divider must be made of two equal resistors. The exact value is not critical, anything from about 5k to 100k will do as long as the two are equal. If battery monitoring is not required, connect the battery monitor pin to VCC. The battery monitor is programmed to shut down the drive and light the LED when the battery voltage falls below 2.75V per cell for more than 100ms. This prevents current spikes when suddenly reversing the motors from tripping the monitor. The under-voltage fault latches until the power is removed.
Mixing is set up for a standard "Mode 2" transmitter with all the driving controls on the right stick:
- Channel 1 = Left/Right, Right = longer pulses
- Channel 2 = Forward/Reverse, Reverse = longer pulses
Motors are connected as follows:
- Left motor = M1B positive, M1A negative
- Right motor = M2B positive, M2A negative
Version 1.0 Update:
After some testing I have found that the code (specifically the battery monitor) doesn't work too well with a servo-powered weapon. It seems that the supply voltage noise generated by the servo (an HS-82MG) trips the voltage monitor and sometimes resets the microcontroller. Some extra supply decoupling is probably needed, and possibly some filtrering on the battery voltage monitor.
One work-around is to disable the battery voltage monitor as described above, although there may still be problems with the servo causing the microcontroller to reset.
I will post a proper fix as soon as I have one.
Version 1.1 Update:
I have uploaded version 1.1 (links above) which fixes a bug in the battery monitor filter code. It now filters noise pulses properly and should only shut off the drive motors when the battery voltage drops below 2.75V/cell for more than 100ms. Typical motor current pulses are less than 10ms.