How to make servos move at the same time?

Gentlemen, I'm working on a hexapod (18 motors). I've solved IK legs positioning, and it runs, but all servos run at the same speed, which isn't good enough. Being quite green in programming of almost any kind, I'm proud of this achievement, BUT .... I figured how to make the servos move at different speeds when moving one at a time (with "for loops"), but it's obviously useless for the hexapod. I've been messing around with arrays, .... would I get anywhere with those? Using SoftwareServo library is supposed to do the trick. Installed it, but when include it the list of errors I get is endless.

So .... How do I make multiple servos to move all at the same time? Anybody knows? I'd appreciate any help in this matter.

IMO, in order to get smooth motion from servos you need to set the position of each servo every 20ms (50Hz).

I posted some joystick servo code here. Reply #23 of the thread has links to videos showing the code in use.

The above joystick/servo project has been my only servo project with the Arduino so far. The code linked above can easily be expanded to multiple servo/joysticks as gyrojeremy demonstrated so nicely with his robot.

I think you’ll want to use a similar approach but rather than using input from joysticks, use your IK calculation results for the servos’ target position.

The joystick code smooths the servo motion by using constant acceleration. Constant acceleration is great for a lot of applications but I’m not sure if you’d want to use this sort of algorithm for your hexapod servos.

In my hexapod, I calculated the position where each foot should be positioned and then calculated the IK positions based on these foot positions. The algorithm determining the foot position moved the foot in a linear manner but in order to produce linear motion at the feet of the hexapod, the various servos in the leg had to move in a sinusoidal manner. Calculating servo positions this way is pretty computationally intensive and I’m not sure if an 8-bit Arduino could make the needed calculations at 50Hz. I think one of the faster Arduinos could do this.

An alternative to calculating the full IK positions at 50Hz is to only calculate the servo positions for the foot’s start and end positions. Rather than having the foot move in a linear manner, you could have the servos move in a linearly between the initial and final positions.

If you move the servos linearly as described, you’ll likely end up with the feet of the hexapod sliding a bit since the linear servo movement wouldn’t produce linear movement at the feet. I doubt this sliding motion would be very significant and it would save a lot of calculations. I’ve only read through a few other hexapod programs other than my own and this computational shortcut appears to be a common method of dealing with moving the servos in a hexapod.

I know there’s a servo library which allows you to set the speed of a servo, but it seems to me you might as well calculate the linear motion yourself and issue servo “writeMicroseconds” commands at 50Hz. Though I’m probably suggesting this since I have used this other servo library myself. It’s likely this other library might work just fine.

As I think about this (using the alternate servo library (I don’t recall the name)) a bit more I realize I have another reason why I want to set the servo positions myself at 50Hz. My setting the servo positions myself, I know exactly where the servos are all the time. I think this would be useful when responding to input either from a remote control or from sensors.

but all servos run at the same speed, which isn't good enough.

You probably already have a large investment tin the hexapod, so also purchasing a good servo controller would be a good solution. An SSC-32 servo controller might be a choice as they have been used with hexapod for many years.

For reasons mentioned in this reply, I don't think servo controllers are useful for robots which should react in real time to changing input (either from the remote or from sensors).

I know there are lots of hexapods with servo controllers but there are also a lot of hexapods without servo controllers.

Gentlemen, thank you for your information, suggestions and help. I'll look at the code samples and see if I'll be able to integrate some of it into my script. The SSC-32 looks really interesting.