2009-11-11

Playing with servo motors

I bought some cheap mini servos from DealExtreme to play with.  They're less than $4 each (in quantities of 3 or more.)

I designed a few little plastic parts to hold the servos together into a structure that can do something.  The assembly is meant to resemble a single leg from a hexapod robot, but the current design is much too weak to support any weight.  It works fine for playing with motor control software, though.

I designed the motor mounts by playing with SketchUp for a few hours.  The first thing I did was grab a pair of calipers and model one of the mini servos.  Then I just pushed the motor models around in SketchUp, and draw parts to connect them.  This is what I came up with:


I exported these parts to STL and printed them out using my MakerBot Cupcake 3D printer:


I'm still working on tweaking the printer.  After a bit of cleanup with a knife and a file, the parts work fine:


 

I like this 3D printer.  It's so easy to go from a rough idea to an actual part!

I did have a lot of trouble getting from SketchUp to an STL file.  In fact, the parts I printed out are actually mirrored compared to the design.  They work fine that way, though.  I've since discovered that getting an STL out of SketchUp is easy if you know the trick to making the STL export plugin work: the part to export has to be exploded for the plugin to find it.

The next step was to try control the arm (or leg, whatever it is.)  I hooked the servos up to an Arduino, which has an extremely easy to use servo library.  It took no time at all to get the servos responding to a simple test program.

I did have a occasional problem with the stepper motors, where all the motors would just start spasming.  It looked like the arm was having a seizure.  This turned out to be caused by my powering the 3 mini servos from a 1.5A regulated power supply, which was apparently insufficient.  I hooked the servos up to 4 AA batteries instead, and the problem went away.

After demonstrating that servo control with Arduino was a trivial task, I wanted to control the servos from a computer program.  To do this, I threw together a quick and dirty program in C#.

A side note here: I use Linux more often than Windows, and I like programming in Python.  However, I've found that when I just want to get something with a GUI working quickly, Visual Studio and C# are hard to beat.

I modified the Arduino program to watch the serial port for commands which set the position of each servo motor, and threw 3 sliders onto a form as the UI.  This worked as expected, and made it easy to set the angle of each servo.  However, even with only 3 degrees of freedom, it's rather difficult to position a robotic arm by specifying the angle of each joint.

So, next part: inverse kinematics.  Inverse kinematics is something I've found interesting for a while, but never tried to do anything with.  Luckily, it turns out that the inverse kinematics equations for this particular configuration are relatively simple.  It still took me quite a few hours to get everything working, though.  This is the page I used as a reference: http://www.learnaboutrobots.com/inverseKinematics.htm

I ended up with a picture box which can be clicked on to set the XY position of the end of the arm, while the mouse wheel sets the Z position.  It works well, and it's really neat to see all 3 motors moving in tandem to get to the designated position.  I also used forward kinematics equations to draw the current estimated configuration of the robotic arm in the background of the picture box.  Even without the physical thing hooked up, it's interesting to see the drawn arm and all the sliders move around as the picture box is clicked.

Here's a video showing the inverse kinematics in action:

This is the first time I've tried uploading an HD video.  I was going to use Vimeo, but it's not accepting uploads as I write this.  I guess I get to try YouTube.

This whole project took maybe 3 days.  About 1 day of messing around with SketchUp and printing parts, 1 day to get the Arduino code and basic sliders working, and 1 final day to get all the inverse kinematics stuff working. 


6 comments:

khiraly said...

You can programing gui in pygtk or enlightenment (elementary).

Im programming guis in enlightenment (python-elementary) this days, and its really nice. You have no limits in your gui, its a bit similar to html+css concept.

Zach Smith said...

awesome stuff!

a few tips: if your objects are mirrored, one of your steppers may be plugged in backwards. open the control panel and move the X or Y axis. You're controlling the head movement, so the platforms should move the opposite direction (X+ moves platform X-, etc)

also, you should check out openscad. parametric modeling for objects!

James Wilkins said...

khiraly, I'm familiar with the Enlightenment window manager, but I hadn't heard of Elementary before. I'll have to look into that.

Zach, I have looked at OpenSCAD. I really like the concept, and I plan to use it for something in the future.

I didn't use it for this, because I wasn't really sure what I was building. My design process was basically to create models for the motors, then move them around and draw in various connecting boxes until something looked about right. For this, it seemed like an editor with GUI editing was better suited.

themitch22 said...

very cool. It seems like there are very little example of makerbots for building robot parts.

christofer said...

That program looks great, is there a copy of it publicly available? i was thinking of starting a similar program myself.

James Wilkins said...

christofer, you can find the program I wrote for this here: http://dl.dropbox.com/u/2944159/ServoTest.zip

This is a VS 2008 project. I just opened it with C# 2010 Express, and it seemed to convert OK, but I don't have anything hooked up to test it right now.

Please keep in mind that this program was meant as a once-off experiment. It is not made to be general purpose, and is just hacked together rather than designed properly. I don't know how much help it will be with your own project, but you're welcome to take whatever information you can from it.