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.

Monday, 31 March 2014

Next project...3D printer (Pt1) I was going to blog as I went with this build, but then every man and his dog is doing the same, so it's a bit pointless regurgitating the same old stuff.  It gets a bit like dejavu...again.

So the upshot is, I had the parts for a Mendel90 (nophead's design) gathered up and looking all lonely whilst I did the Printer/CNC machine conversion.  To be honest, the CNC build seemed a lot less intimidating than a Mendel90 build, hence it jumped the build queue.

On that, the CNC machine didn't produce as good a quality product as I had hoped, and I've had a rethink about some of the design "features"...for want of a better word.  So on the hit list is:

  • Move the back Y carrier shaft rearward, which opens up the gap down the Z axis slot for the entire dremel.  The flexishaft has far too much drift in the collet, and the runout was pretty ugly too.  There's none in the collet for the direct attachment on the dremel.
  • Stablise the X axis platform with a couple of skate bearings pressed against the inside face of the rails.  The threaded rod has a very slight bend which has the effect of 'walking' the platform when moving at speed.  Movement is not a problem except when directly under the Z axis, so I figure that's the only place where I need to stabilise the sideways movement.
  • Cut a new mount for the Z axis carrier and make it 1.5 times wider to accommodate the dremel, then make mounts for the dremel and bolt to the Z axis.
In order to help me do this, and satisfy my new found curiosity with hexapods, I built the printer.  This was another several days work since I was building from self-sourced parts, rather than a kit supplied by nophead and crew.

There were a couple of interesting moments, and it came under threat of being thrown out onto the street several times, but with some serious encouragement and advice from Clayton (UK ebay-er that supplied me the printed parts for the beast) I finally have my very own 3D printer! [insert evil grin and rubbing hands with glee]

Thursday, 9 January 2014

CNC - First real cut

 Here's the first real run with the CNC with a diamond engraving bit in the dremel.

I put a grid of silicon door bumper pads (about 7mm dia) on the bed as way to stop the acrylic work-piece from sliding.  I also used a pair of moly magnets from an old server HDD, one stick to the underside with double sided foam tape.  These things have enormous amount of magnetic pull, and with the other one directly above it, it clamped the work-piece to the bed without risk of distorting it.  Works a treat!

I used CamBam to generate the g-code, but I reckon I had the feed rate too high.  The dremel bit seemed to twitch when it got to the end of each it was under too much side load.  This did cause the letters to have a small bump at the start/end point of each character.

This run was 1.0mm deep, 0.5mm each Z step, and 200mm/min feed rate.  I might be a bit ambitious with these settings :-)

It also doesn't help when the dremel collett seemed to swing the bit off-centre upwards of 0.25mm each way (a combined runout of 0.5mm).

The CNC router upgrade may be sooner that I had planned, but in its current state, a reasonably OK setup for learning with.

Next test..cutting a profile and drilling some holes.  If I don't update this for a while, it's most likely gone all horribly wrong...but that's just me being optimistic :-)


Wednesday, 8 January 2014

Converting an A3 printer into CNC machine - In Summary

In short, it's been an awesome project to do, and I would do it again in a heartbeat.  I've still got some tidying up with cable routing, etc, but it has had it's first run with a pen zip-tied to the Z-axis.  The results are pretty good, and the accuracy is nice to see. (

There will be some enhancements and improvements:

  • Upgrade the rails and linear bearings to 12mm,
  • Expand the Z carrier to accommodate a 52mm CNC spindle,
  • Put in a 400W CNC spindle
  • Make the lights on the dash go blinky blink :-)
I would also like to drop in a 4x20 character LCD screen and get some output from the Arduino...some sort of job status maybe?

So on behalf of Dasher (she's been sitting here listening to me typing this blog) and myself, thanks for reading.  Feel free to leave feedback or ask questions.  Dasher won't give a fat rats bum about feedback or questions, but I'll do my best to get back you as soon as.

In the meantime, please check out the video of the first run, and I'll update the blog when I do something a bit more exciting than an electronic sketchograph.