Monday, May 30, 2011

11

LIBSSC32: ARDUINO + SSC32

Today I would like to share a library for Arduino that makes it easy to control a SSC32.

But, what is a SSC32?
The SSC32 is a Serial Servo Controller, capable of controlling up to 32 servo motors at a time. Very useful in robotic projects such as arms or humanoids.


You can buy it at http://www.lynxmotion.com for about $40.  The thing about this piece of hardware is that it is very flexible. It is not only a servo controller, it also provides some pins where you can connect sensors and read  its values. And the most useful of its features (in my humble opinion) is that you can specify a group of servos, set each servo inside the group to move to a different location and specify how long will it take for all the servos to finish the movement. It doesn't matter if each servo is far or near its final location, SSC32 will calculate and apply the speed for each servo so all them finish at the same time!! 

This is very powerful to create complex movements. And they will be performed smoothly

Lets get down to business.
In my case, I am using the SSC32 to control an arm with 6 servos (more about this in future posts)  and I thought it would be nice to be able to command it from an Arduino.


The only "problem" is that the serial protocol defined by the SSC32 is a bit "uncomfortable" to handle, so I created a class to handle it and make it a bit more comfortable.

You can find the library for Arduino here (decompress it inside the "libraries" folder of your arduino environment):




And here is an example of how to use the library:

#include <SSC32.h>

/*
  Tests the SSC32 library. By Martin Peris (http://www.martinperis.com)
  This example code is in the public domain.
 */

SSC32 myssc = SSC32();

void setup() {


  //Start comunications with the SSC32 device  
  myssc.begin(9600);



}

void loop() {

  //Move motor 0 to position 750
  //The first command should not define any speed or time, is used as initialization by SSC32
  myssc.servoMove(0,750);

  delay(1000);

  //Move motor 1 to position 750
  //The first command should not define any speed or time, is used as initialization by SSC32
  myssc.servoMove(1,750);

  delay(1000);

  //Move motor 0 to position 1500. It will take 5 seconds to finish the movement.
  myssc.servoMoveTime(0,1500,5000);

  delay(5500);

  //Move motor 1 to position 900. It will take 5 seconds to finish the movement
  myssc.servoMoveTime(1,900,5000);

  //Move both servos to position 750 at the same time. 
  //The movement will take 5 seconds to complete
  //Notice that currently motor 0 is at position 1500 and motor 1 is at position 900,
  //but they will reach position 750 at the same time
  myssc.beginGroupCommand(SSC32_CMDGRP_TYPE_SERVO_MOVEMENT);
  myssc.servoMoveTime(1,750,5000);
  myssc.servoMoveTime(5,750,5000);
  myssc.endGroupCommand();

  delay(5500);

}



[EDIT 2011/11/24]: The library has been adapted to the new version of arduino's IDE. Thanks to Marco Schwarz.

11 comments:

Anonymous said...

Martin, thanks for your post.
Very useful documentation!
I want to use if for the control of a humanoid robot with 17 servos.

mrtn
-- .-. - -.

ErSame said...

Really cool.

Have you though about postint it into Arduino playground (http://arduino.cc/en/Reference/Libraries)?

Best regards from Málaga :)

Martin Peris said...

@mrtn Thank you very much for your comment! I hope you find it useful. Please, let me know about the progress of that 17DoF humanoid ;)

@ErSame Thank you man! I think its a good idea, I will post it :)

Big hug from Japan!

Marco Schwarz said...

Hi Martin,

thanks for the library. I use it for my hexabot.

I have permission to modify the library for use with the new Arduino IDE. A new version can download at http://dl.dropbox.com/u/1213321/LibSSC32.zip

Martin Peris said...

Hi Marco,

Thanks for the update :) I have uploaded your new version to the server so everybody can use it.

By the way your hexabot looks really good :D

Best regards,
Martin.

edysersan said...

hi martin very usefull using SSC32 with arduino, you make this library very cool...i want to make humanoid robot using arduino with 18 servo, thz a lot

Martin Peris said...

Hi edysersan!

I am glad you find it useful :) Thanks a lot for your comment, I really appreciate it.

Martin.

צביק'ה said...

Thanks! looks like a greta library.
before trying it out (tomorrow, hopefully), I had to port the hard coded hardware Serial to SoftwareSerial ("real" serial port was irreversibly occupied by my wireless wixel shield) - here the migrated code:
http://dl.dropbox.com/u/50461514/LibSSC32Soft.zip
pretty straightforward, hope it helps somebody else...

Anonymous said...

Hi,
Can you provide an example on how to make sure of the modification for the version ported for using SoftwareSerial?
* I'm not sure how to use this:
SSC32Soft(SoftwareSerial* serial)

Anonymous said...

hello i wanted to know if i can use the arduino directly for controlling more than 10 servos simultaneously instead of using a servo controller??
the power to each servo would be given saperately...is this right??

Unknown said...

the servo library i heard that it only takes care of 8 servo anything over that you can expect headaches this is why the ssc32 is useful not to mentioned that arduino can only command one servo at a time where ssc can do multiple calls at onces

Post a Comment