Saturday, 12 April 2014

Heaxpod (Pt 3)

The wireless PS2 controller and 32ch servo driver board arrived, and has proven to be a minor challenge to work with.

For the last couple of days, the Torobot site has been down, possibly patching for the SSL HeartBleed vulnerability, and quite clearly having a few issues..just been there and their backend database just spilled it's contents onscreen for me.  Since I'm an ethical hacker, I'll just leave them to it. :-)

However, it has given me an updated manual for the controller/servo board and also access to the command software used to create actions.

What has been really interesting is the stuff I have found regarding sending serial data to the servo board from an Arduino Uno, receiving command data from the PS2 controller over wifi!  The servo controller uses PWM, not the degree values I have been used to with the servo library.  As it turns out, it's reasonably easy, once you know the PWM upper and lower limits for the servos.

In my case, I'm using TowerPro MG996R servos for all joints.  With some messing around (trial and error), I have a PWM range of 800 to 2500 microseconds(us).  This gives me the full 180deg sweep from 0 to 180.

I'm a bit new to this, and I got un-invited to 6th Form high school so the maths skills aren't that great, but the guts of it is:

If 0deg is 800us and 180 is 2500, then midpoint is ((2500-800)/2)+800 = 1650.
It also goes that 180 deg / 1700us (PWM range 2500-800)  = 0.105 deg per microsecond.
Therefore 1 deg = 9.52us  (1 / 0.105)

So if I want to send the servo to 40 deg, then (40deg / 0.105us) + 800 = 1180.95us

Now, they aren't the most accurate servos, and when it reaches the edges of the limits, it can overshoot.  These things are capable of 10kg/cm torque, which is enough to split the casing if the servo reckons it can go past the physical stop pin.  To counter that, I knock about 5 deg off each end of the sweep, giving me a range of 5 to 175.

Now I have a PWM range of 850 to 2450, with midpoint still at 1650..cos all I did was trim 50us off each end.

Still with me then? :-)

Right....Arduino has a really cool function named "map()" which makes it an absolute doddle to translate the values coming from the PS2 controller to PWM values.  It goes like this...

map(value to change, min value it will be, max value it will be, min value to assign, max value to assign), 0, 100, 0, 1000) will return 500...because 500 is the same to 0-1000 as 50 is to 0-100), 0, 255, 850, 2450) will return the value 1650...because 1650 is to the range 850 - 2450 as 127 is to the range 0 - 255...which is really handy because the PS2 controller joysticks produce values ranging from 0 - 255 in their full left to full right range of movement...with 127 being the sticks neutral point.

The Torobot board uses a serial data string format of "#[servo port]P[PWM value]T[Time in ms]"
To send servo on port 1 to the midpoint => "#1P1650T500" mash it all together:

Connect the PS2 wifi receiver to the Uno with some female/male jumpers.  The receiver pinouts are(left to right, looking into the socket end with the D shape smiling at you):

  1. Data -> UNO pin 12 (NOTE: Must use a 10k resistor for pullup..else the signal is all squiffy and won't work)
  2. Command -> UNO pin 11
  3. Not used
  4. Earth/ground -> Have a guess..
  5. 3.3v in -> You got it...
  6. Attention -> UNO pin 10
  7. Clock -> UNO pin 13
  8. Not Used
  9. Not Used
Connect the UNO to the Servo Controller board:
  • UNO TX -> RX0 (next to the mini USB socket, bank of 3x2 header pins ahead of "S1")
  • UNO RX -> TX0
  • (Screw block)
    • Gnd -> ..well...ground!
    • VS - Voltage supply in for the servo main power..this does not power the board itself
    • VSS -> 5v from UNO for powering the board processor.  Can power from the USB and has voltage protection so you don't zap back up the USB cable
Download and import the PS2 controller Arduino Library from Bill Porter ( shout out to him and the awesome work he's done on this.

Connect your servos to the header pins...dealers choice which ones you use.

Here's my test sketch for one robot arm (3 servos), and has been vastly trimmed just for testing.
Note that you can move mulitple servos with a single line...just add the string with "#[servo number]P[PWM value]" prior to the "T" value and the final "println"  The servo controller reacts when it gets a newline character.

[code starts here]

#include <PS2X_lib.h>  //for v1.6

PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning 
//you must always either restart your Arduino after you conect the controller, 
//or call config_gamepad(pins) again after connecting the controller.
int error = 0; 
byte type = 0;
byte vibrate = 0;

void setup(){

 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

void loop(){
  //DualShock Controller

  ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed

    Serial.print(map(ps2x.Analog(PSS_LY),0,255,900,2400));     // Read the left joystick values
    Serial.println("T500");    //Send the string off to the controller board

[End code]

You may have seen the min/max for servo 3 is around the other way?..You can swap them to actually change the servo sweep direction.  This servo is for the shin section of the leg, and by swapping the values you can get it to move "leg cramping curling up" style..or "Mr Miyagi whoopass crane" style.

I have found that if you don't disconnect the power to the servo board (the 5v and/or the USB cable), the sketch won't upload to the arduino.  I'm not sure why, but I think it gets messed up with the serial data responses from the servo board?..anyone want to chip in here?

Well...after all that, I've got remote control of a hexapod leg with a wireless PS2 controller joystick.  The photo is a couple of the legs set up in a test rig to see how well the legs move and test range and servo jitter.

Just for $hits and giggles I moved the rig so it was resting in the middle of the table, then moved the leg in a "stand up" type of movement.  Impressed with those servos..because the rig is being held in place with a 3kg dive weight..and the leg tipped it off without any bother at all.

I am encouraged! :-)

I'll upload a video of the test when I can borrow the camera (again!).

Video of the abovementioned rig in action..

See ya next post.

Friday, 4 April 2014

Hexapod (Pt2) it might seem a short timeframe between my last blog, and this one where I proudly announce that I have finished printing the leg parts for the hexapod.  I do actually have a day job, and as much as I would like to spend all day making robot stuff, it don't pay the bills.

I started printing the parts a couple of weeks ago, then had to wait for some hardware to turn up (long 3mm screws, 21mm brass standoffs, etc).  So tonight, I have finished the printing and assembly of the legs, complete with servos.  I did have to re-print a couple of parts because I hadn't taken into account the left side/right side thing.  However, because of the way I designed it, it was a simple case of mirroring a couple of parts in netFabb, slice and dice in slic3r, and print them out.

All in all though, everything has gone as planned, all the parts fit nice and snug, and now ready to be attached to a body.

As you can see...SU to the rescue again.  I plan to use 6mm acrylic sheet, but will wait until the servo controller board arrives so I can model it up and see where I might put the boards.

For a better view of the model, check out the new vid ( for a quick fly-around of the model.

Might be a while for the next instalment where I'll be getting the legs calibrated for midpoints on the servos as well as testing the (hopefully arriving soon!) 24 channel servo driver board with wireless PS controller.

Bye for now.

Tuesday, 1 April 2014

The hexapod (Pt1) now I have the printer, have learned some stuff from building the printer and the CNC conversion...those 6 legged roboty things look way cool!..So here I go.

Been looking at a large number of designs, blogs, thingiverse thingies, youtube, get the point.  So since I'm into doing things the hard way, I will design and build my own hexy...once I have finished the printed cats that her majesty found on thingiverse, and promised her workmates I would print for them.  Cats!!...all this technology, money, combined knowledge and resources...and she wants cats!

Anyhoo...I start with SketchUp (herein referred to as "SU"), and I have been playing with SU for years.  I'm still living on SU pro 8...It's perfect for my needs, so why upgrade?  SU has a massive number of plugins which are really useful for this sort of thing.  Granted, SU is not industrial strength like AutoCAD, AutoDesk, SolidWorks or Truespace (and the many, many others out there), but a powerful beast nonetheless.  Once you add in a few plugins, you start to see exactly how powerful it is.

Once of the first to get is SketchyPhysics.  If you want to do some basic mechanical design, and then test things like movement, clearances, and general aesthetic, then this is a must.  You can add servos, hinges, pistons, sliders and then animate them.

Then you get the STL exporter...kind of goes without saying what this is for, but for the readers that are new to this 3D thing, it's the 3D model format used to create the code used by 3D printers.

There's a couple of others that I recently added since building the printer.  Shape Bender and DrawHelix combo is awesome for creating nuts and bolts.  The standard followme tool in SU doesn't work that well to create the bolt threads, or even a nice smooth helix, but ShapeBender and DrawHelix are the schizzle at it.

One more...CurviLoft.  This is one I recently started using, and for organic shapes, you can't go past it.  This would be an interesting one to try with a laserline scan of something like a face, and then use the loft tool to create a surface over the profiles.  Hmm...that sounds like a project :-)

So the grand plan involves using an Arduino board (Uno, possibly Mega), some sort of servo controller chip like the JP Serial Servo chip (24ch), MG996R servos and a whole bunch of freshly printed parts.

Here's the basic concept, with some motion added to check the actions..

Of course, best laid plans and all....The legs went through a bit of a redesign because I could see there would be problems printing those shapes, and print them in a way that maintained a high degree of structural inegrity.  Trying to screw in a self tapping screw through the side of a printed item is no just delaminates the plastic.  There's also the issue of assembly.  Very easy to design the impossible-to-assemble shape.

So what I ended up with is a little convoluted, possibly slightly over-engineered, but I reckon it might just work.  I've seen these set up with just struts on the servo horns, everything off to one side, and only pivoting on the servo shaft.  That would be OK for lasercut or CNC milled aluminium parts...but I'm printing mine and I want something a bit more here it is.

There's 8 parts to each leg, 4 parts are identical, so only 6 different models to deal with.
After some test parts, working out that you have to give items clearance (if you don't then things are such a close fit, you can't fit them!), I settled on the final design for the legs.

 Let the printing begin!

Next project...3D printer (Pt2)

(Yes...I could have written this in a single blog..but I have a short attention span and only 330ml bottles of beer)

In no particular is some points from the Mendel90 build.

Spend the $$ and get the frame templates printed on a single sheet of paper!  It took an age to get 4 sheets lined up square, not stretched, and taped together enough to survive the hole drilling exercise (..or the whole drilling exercise...either one fits)

Careful when attaching heat sinks to the stepper driver chips.  The tops of the pins are pretty close to the edges of the aluminuim heatsink block..and they don't really like being powered up with a whole side all shorted to each other.  Lucky I bought a batch of 10 of them...I have 3 left (you only need 4 for the RAMPS board)

When wiring up the Z motors, check out how to wire them in series, rather than parallel.  The RAMPS board has header pins for parallel, but it works so much better in series keeping the Z axis steppers in sync.

Get your end stops sorted!..(seems a common theme from the CNC build)..especially those Z axis stops.  Seeing your extruder try and plow it's way through the top of the print bed is not a happy thing.  Be ready to hit that reset button!

Be prepared to chew through a lot of filament fine tuning the Z height.  I can't stress how important it is to get the bed level, and the zero height set properly to ensure that first print layer goes down properly, without zits (lumps that will make the steppers skip when they get hit by the nozzle), and with enough coverage to make the print stick to the print surface enough to hold on for the rest of the layers.

Search, search, and more search...before you ask.  It's a big community out there, and they have been doing this a while.  Chances are that a noob question has been asked before.  Go look for it, and you will find a wealth of additional information on the way.

That is all...for now.