Delay on writing to Maestro 24

Hello,
I’m building hexapod robot based on Raspberry Pi 2B and Maestro 24 using UART and “detect baud rate” setting.
Robot walks using oscillators, it means Raspberry has to write to every single servo every 20-50 ms.
To steer the robot we need almost real-time input from a controller ,and when controlling one leg, everything works fine, but when i connect all servos there is a delay between input and robots response ( sometimes as high as couple seconds).
Changing the baud rate from 9600 to 115200 bps doesnt help.
What could be the reason of that? is this maestros fault or there is some bug in the code?
Any Ideas to fix it?

Hello.

It is not clear to me what could be causing the issue from the details you provided. Can you post pictures of your setup clearly showing all your connections? How are you powering everything? Can you post the code that is running on the your Raspberry Pi? If you are running a script on the Maestro, can you post that as well?

- Amanda

Hello Amanda,
All the hardware is packed tightly inside of the robot. Maestro and Raspberry are connected via UART (TX,RX on Maestro to GPIOs 14 and 15 on RPI). Everything is powered from 5V 10 A Step-Down DC converter ( and 2 cell Li-Po 6000mAh battery); Servos are 12x Hitec HS-645MG.
Code im using to write to Maestro:

<> int maestroSetTarget(int fd, unsigned char channel, unsigned short target) { target = SetAngle(target); unsigned char command[] = { 0xAA, 0xC, 0x04, channel, target & 0x7F, target >> 7 & 0x7F }; if (write(fd, command, sizeof(command)) == -1) { mvprintw(10, 10, "Maestro err writing %d ", channel); refresh(); return -1; } return 0; } </>

Function SetAnge simply converts angle (0 - 180 deg) to values acceptable by maestro

I’ve tried to use ‘fixed baud rate’ setting but there was no response from maestro at all (red LED turned on).

I looked at your maestroSetTarget function and did not notice anything that could be adding the delay in your system, and your power setup seems fine. Is there a reason why you suspect that the maestroSetTarget function is creating the delay? It would be helpful if you can post your entire code (or attach the file) so that I can get a better understanding of how you are setting the position (or angle) for each servo.

- Amanda

maestroSetTarget(fd, 0, katy_a[0]);
maestroSetTarget(fd, 1, katy_a[1]);

maestroSetTarget(fd, 2, 180- katy_b[0]);
maestroSetTarget(fd, 3, 180 - katy_b[1]);

maestroSetTarget(fd, 4, katy_b[0]);
maestroSetTarget(fd, 5, katy_b[1]);

maestroSetTarget(fd, 6, 180 - katy_a[0]);
maestroSetTarget(fd, 7, 180 - katy_a[1]);

maestroSetTarget(fd, 8, katy_a[0]);
maestroSetTarget(fd, 9, katy_a[1]);

maestroSetTarget(fd, 12, 180 - katy_b[0]);
maestroSetTarget(fd, 11, 180 - katy_b[1]);

waitMS(21,true);

This is how i write to servos. I think its Maestros fault becouse the delay only happens when i write to “many” Servos. When I deleted part of code so it was like this

maestroSetTarget(fd, 0, katy_a[0]);
maestroSetTarget(fd, 1, katy_a[1]);

there was no delay as far as i can tell.

Since it looks like you are setting a bunch of servos at once, you probably should consider using the Set Multiple Targets command to see if that helps reduce the delay. The Set Multiple Target command allow you to send fewer bytes to set multiple servo targets. For more information about that command, see the “Serial Servo Commands” section of the Maestro User’s Guide.

- Amanda