Wednesday, April 13, 2011

How to control 18 servos [2.007 hexapod]

Things I've learned (not explained thoroughly e.g. with pics for pwm, more for my own reference). Or rather, the 600 threads of information I haven't incorporated into one coherent picture yet.

My final conclusion was to spend money and buy an 18 servo RC controller from Pololu, allowing me to control all 18 servos independently. Also, build a power bus to supply power to the servos.

Next steps: make sure I won't just strip all the servos -- weight hexapod and do some rough estimates.
Order RC controller ASAP and look into Pololu coding.

However, for two week turn-in deadline, just take the carrier, Y splitter cable 9 servos (so mirror the left and right sides no WAIT! that might not work out well, my servos do not look mirrored left to right, perhaps Y cable front and back servos instead for each side = exactly 12 software servos to control), and write code.

PWM can mean two different things in common use.

  1. Power pulse width modulation -- signal is the voltage averaged from the high and low pulses. Used for instance in motor control, where motor's inertia means it just sees 2.5V if you have 5V and a 50% duty cycle
  2. Pulse "duration" modulation -- signal is encoded in length of pulses
    Used for instance in servo control
More properly, PWM -- motor control. PPM -- servo control (looks like low duty cycle PWM). (wait, but I don't see PPM used anywhere else?)

Thus, with regards to Arduino nano and if I can somehow coerce it into controlling 18 servos.
The answer is probably yes, but with lots of electronics and coding. A better solution is to invest in RC board

The limitations: 
Hardware, Arduino nano:
Digital I/O Pins: 14 (of which 6 provide PWM output) **
Analog Input Pins: 8
Atmega328-- one 16 bit timer, two 8 bit timers (8 bit = less resolution on servo control, leads to jitter,  see

Software, Default Arduino Servo library:
The Servo library supports up to 12 motors on most Arduino boards.
**(huh? Maybe TX and RX count as digital pins?)

What this stuff actually means:
AnalogInput pins are actually digital output pins. They are D15 to D22. Thus, I have enough hardware pins to control 22 servos.

Also, the 6 PWM thing is completely unrelated to servo control (related to motor control, I think).

I can use the Playground servo library to control servos off of as many pins as I have, and I'm not limited to the 12 servos in the regular library. 
You are not limited to 8 servos, but you must call the SoftwareServo::refresh() method at least once every 50ms or so to keep your servos updating.

Default servo library uses timer1 (16bit timer).

Random stuff I don't understand yet:
Or maybe I can use a decade counter?

Hardware vs Software PWM
Hardware PWM is low maintenance. You initialize the hardware, then the only other software interaction needed is to set the duty cycle (which can be done whenever you want). Hardware PWM is fixed to specific pins and limited as to the number of outputs channels. Software PWM needs more maintenance. It may still use a hardware timer, but the output must be toggled by software at the proper times. Software PWM can use any open digital output pin and can support several output channels. 

(ref. Driving up to 48 servos with a Spider controller, does NOT apply to Nano)

Commercial products:

Other concerns:
Maybe my servos are too weak for my super-simple design with load-bearing without bearings or anything, and I won't even be able to walk without stripping the servos. That would be REALLY sad if I stripped 18 servos. Or perhaps I'll just stall out the servos with too much torque demand and burn through them. Maybe the plastic is too flimsy and I won't be able to walk without breaking servo horns.

To do: Weigh the robot and each leg, do rough calculations.

Well, the servos may draw a lot of power. Or current. Or something. So I may get a Power Bus (? what is that? it sounds nom-able) by mooching off of Charles or Shane, and then create my own 5V power supply that can supply more current than the hobby king 7.4V LiPo battery + the 2.007 nano carrier board.

Anyway, turns out many-servo hexapods are expensive, even partially subsidized by 2.007. .____. Perhaps I should have stuck with my tiny hexalinkagepod <3 hmm. 

At least it's less expensive time-wise with the help of 2.007 and friends.

18 servos (VS-2 and HITEC 115) @ $2.50 each = $45.
Arduino nano = $30 (completely assembled, I hear buying the PCB and components is much cheaper).
Pololu controller = $40 (18 channel) without shipping. (uh, how do I use this? Do I need to learn another programming thingy? ;___; Can I just program it with Arduino?)

(alternative: arduino mega = $60, spider controller? = $60?)

Also, my way of building a hexapod using zero solidworks seems like very little mechanical engineering and a lot of coding and electronics. _sigh_


  1. WOW~~ thanks for sharing your thoughts and experience! So how did the project finally turn out? I'm up to build my first hexapod robot by using cheap micro servos (HXT900) and considering two servo controllers (Pololu Maestro 24 or Lynxmotion SSC-32) working with Arduino UNO (or nano). Do you have any suggestions? Thanks a lot!!!

    1. Hi! Actually I documented my actual build process on my build blog. Here's a summary:
      and you can check out the youtube video here:
      and you can see other posts by searching for "hexapod" on orangenarwhals.
      I've only used the Maestro so I can't really say I suggest one of the other ^___^
      Yay hexapods! Good luck, let me know if you have any other questions (trossenrobotics is a great forum too).

  2. Thanks for sharing, I am currently searching for the best gait for my hexapod build.