Asked — Edited
Resolved Resolved by Steve G!

Writing Script For Multiple Servos At The Same Time

Don't laugh too hard...I'm a noob learning how servos work for the first time. I am just learning how to script with ARC manually... Working with an inMOOV robotic arm/hand.

I have a script that moves 5 servos - 1 at a time for each finger. The script looks like this... SetServoMin(D0,1) SetServoMax(D0,160) SetServoMin(D1,1) SetServoMax(D1,160) SetServoMin(D2,1) SetServoMax(D2,160) SetServoMin(D3,1) SetServoMax(D3,160) SetServoMin(D4,1) SetServoMax(D4,160) Servo(D0,1) Sleep(500) Servo(D0,160) Sleep(500) Servo(D0,1) Sleep(500) Servo(D0,160) Sleep(500) Servo(D0,1) Sleep(500) Servo(D0,160) Sleep(500) Servo(D0,1) Sleep(500) Servo(D1,1) Sleep(500) Servo(D1,160) Sleep(500) Servo(D1,1) Sleep(500) Servo(D1,160) Sleep(500) Servo(D1,1) Sleep(500) Servo(D1,160) Sleep(500) Servo(D1,1) sleep(500) Servo(D2,1) Sleep(500) Servo(D2,160) Sleep(500) Servo(D2,1) Sleep(500) Servo(D2,160) Sleep(500) Servo(D2,1) Sleep(500) Servo(D2,160) Sleep(500) Servo(D2,1) Sleep(500) Servo(D3,1) Sleep(500) Servo(D3,160) Sleep(500) Servo(D3,1) Sleep(500) Servo(D3,160) Sleep(500) Servo(D3,1) Sleep(500) Servo(D3,160) Sleep(500) Servo(D3,1) Sleep(500) Servo(D4,1) Sleep(1000) Servo(D4,160) Sleep(1000) Servo(D4,1) Sleep(500) Servo(D4,160) Sleep(500) Servo(D4,1) Sleep(500) Servo(D4,160) Sleep(500) Servo(D4,1) Sleep(500)

How can I get all 5 servos to move at the same time? Is there a way to execute 5 commands at the same time from the same script on the same line? Can someone give me a short example? I want the robot to close his hand and then open his hand...or maybe open two fingers while 3 are closed.

Any help would be appreciated so I can see how this might be accomplished. Thanks! BobJ

Skip to comments


Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!


Try using the Auto Position control. Put each finger into the position you want in a frame, then create another frame for the next finger positions. When you have a few frames you can make an Action out of them or run them independently.

United Kingdom


Apart from the great advice @bhouston gave above about Auto Positon control which is a great feature, you can manually do it with scripts as you asked as well. You could use something like the following...


Or to have two fingers move at the same time...


And one final example of moving two fingers at the same time, but at a slower speed...


Hope that helps.


Autoposition does seem like a good way to go but, out of curiosity I was wondering how this would work?

# Initialize Variables
$ClosedHand =1
$OpenedHand =160
$HandPos =$OpenedHand #Open position is default
Goto (TheStart) #Initially skip MoveAllFingers

$TheFinger =1 #First finger or thumb
RepeatWhile($TheFinger <=5)

$HandPos =$ClosedHand
Goto (MoveAllFingers)

Sleep(5000) #Wait 5 seconds

$HandPos =$OpenedHand
Goto (MoveAllFingers)

This assumes the finger servos are in sequence 1-5. What I'm wondering is will all the fingers open at once or will they open in sequence? I'm guessing all at once since Servo() is a non-blocking instruction. I can't test this for myself since I STILL don't have my JD after a month, nor do I have a hand of this type. This would also allow for settings in between as well such as $HandAThirdOpen, $HandAForthOpen, etc. Or any value in between by setting $HandPos with a number directly.


I will give these different approaches a try. Bob, I'm not familiar with the auto control function...might have to play around with that one and see how that works!



@bobjacon yep, Auto positioner all the way.... it makes moving multiple servos a snap....


WBS, why do you continually want to not use the Auto Positioner? The code examples are good for arduino - which is why we created ez-robot so you don't have to write that code. Focus on making your robot do amazingly awesome things - who cares about moving servos with code.

Sure, you can do that - but why would you?:)

United Kingdom

AutoPosition (as everyone else has said) is the way to go, it takes all of the work out of the animations.

However, since you posted your script I would just point out that there's no need for it to be in that order. You could remove a goto by reordering the "TheStart" section to before the "MoveAllFingers". Why have the code jump around all over the place when there is no need for it to do so?

But, again, Auto Position would achieve everything you want to achieve (and more) easier and quicker than writing a script.


@DJ Sures Well, as I see it, using the autopositioner is fine, but not very flexible. That is to say, the results from it are fixed and does what it does the same way every time you run the frames. And that's fine for things like the getting up task. That's a complex operation and will probably be the same every time you use it. Still, If you want to change anything, no matter how slight, you basically have to go back to the autopositioner software control to do it. Also fine by me for some things.

To me, the finger movement under discussion is different. Using autopositioner I can get it to open or close, yes, but, if I want something in between I have to go through the process of moving each finger in the AutoPosition setup to where I want them to be or move to. Then have it generate the script code for that particular sequence. Create a frame and group frames as needed, etc. If I want a different position, I have to do the same thing again. With the example I gave I can set the fingers of the hand to any position (not just full open or full close) with just two lines of code.

Now I'm a neophyte here and I understand that and there are ways to use autopositioner of which I am not aware I'm sure. I don't mean to step on any toes, I just wanted to see what others thought of that method. And to find out of it will actually work as described. Still don't have a JD yet so I can't test it out for myself, so I threw it out there.


@Rich Yes, you're right. Moving the "MoveAllFingers" to after the the calling section instead of before it would be better for this simple example. But I look at the MoveAllFingers routine as something that would be called many times in a given real program. Making sure it is always at the end of the main program sequence would become tedious every time I add to the overall program. Putting it up front eliminates that problem. The same for other routines I would call from several different points on the overall program. I would declare them all up front first. Generally makes it easier to add new such routines as well. Plus, what the hell, it's habit for me to do it that way.

Likewise with the variables I would use in the program. I would declare them up front to make their initial declared values easy to change. I usually add many variables to use as constants as well. For instance I would declare a variable for each servo and use that variable throughout the script as opposed to directly using the servo port number. That way if I change the port for a particular servo all I have to do is change that value in one place.




May not be the hard way. Just a different way, IMHO.


I tried Steve G's code and of course I added min and max servo settings at the top of the script and it worked like a champ! I also liked the code that allowed the fingers to move at a slower speed. That was a pretty cool effect. Next, I will try Bob Houston's and Aerius's and Richard R and Dj's advise with Auto Position control. I also have to figure out how to tighten the braided fishing line as my fingers are not tight enough. I'm sure there is an art to it.

Thanks guys! BobJ


@merne Perhaps hard to you, the familiar (and correct) way to me.:) It's also easy for me because I've done it that way so much. I'm assuming you're referring to the post just above yours. Granted it's also more initial work, but the practices I employ pay dividens in the long run when you want to make changes or additions. Heck, wait until I bring forth the Object Oriented version of the Scripting language! {Kidding ... I think}

United Kingdom

@WBS, in that case, have you looked at using multiple scripts and ControlCommands? Look at the latest Ping Roam script of mine (in the cloud) for an example of this. Multiple scripts or sub-routines called by a main script (or the sub routines). It made it even easier to make changes or use the same section of code multiple times.


@Rich Thanks. I wondered about that. That was going to be the next thing I looked at to see how all that was usually done. I'll start with your example. Does seem like a good way to isolate program sections for reuse. Also perhaps a way to introduce "scope" into the whole thing.


@bobjacon This is how I did my finger servos.... I used screws like guitar tuning pegs... I can adjust tension simply by turning any one of the screws... User-inserted image


Richard R, What a GREAT idea! Can you point me to a source as to where someone can find screws like that? I don't even know what to call them but that would solve that problem pretty well.



@bobjacon Ha, ha.... #4 x 3/8 wood screws from the Home Depot.... you need some crazy glue as you wrap the braided line around the screws... This will keep it from slipping when you turn the screw...


Richard R,


You had me thinking that there was a small screw with a hole through it like tuning peg available someplace!

However, thanks for describing what you will do the same thing! BobJ