Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Optimizing board writes for Maestro Mini


I have a 5 board set up running 98 servos. One board is connected to my computer running in USB chained mode. The other 4 are daisy chained to it and are running in UART mode with fixed baud rate of 115200. My set up requires that I be able to change the speeds dynamically as I change targets for each servo. Currently I am setting targets through the Set Multiple Targets command but it seems that the speeds have to be set per board and per servo.
I am interested in ways I can optimize this multi-board set up to eliminate any visible lag within the system. I am noticing a very slight lag between when the board0 servos start moving and when the board4 servos start moving. I understand that ultimately the serial commands are going in order byte by byte and so there will inherently be some small delay in execution but I am interested in keeping this delay small enough that it is not visible. Any advice on how to more efficiently work with multiple daisy chained Maestros and eliminate this visible lag? My current python script is attached. (caveat: I am a python newbie)
controlServosSTANDALONE.py (10.4 KB)



I noticed that your setBoards function will call the write function on your serial port twice for each Maestro board you are controlling. I would suggest refactoring your code that you only call write once. Also, I would probably reorder the commands so that you first send all the speeds to your boards and then send all the targets. To do that, you would probably want to change your setSpeeds and setTargets functions to return some kind of list of bytes, and then you would concatenate those lists into a larger list in the proper order before you write it to the serial port.

A project with 98 servos sounds pretty interesting. Is there a website or video about the project?



Hi David,
Thank you for the quick response. I think I understand your suggestions and will try implementing them. Question: Is there any way around avoiding having to do a separate write per board? Can I put all of the commands per round in one giant write? (a.e. speeds for all the servos for all 5 boards first, followed by the set_multiple_targets commands and target values for all boards in order of board).
The project is an interactive sculpture. We are almost done setting it up. I’ve attached a photo but will post video and project description when we have it up and running. This is V2 of this project and the Maestro board has been an amazing improvement from the previous clunky set up using 3 Arduino Mega boards with the Servo library which had a hard time handling our set up.



Yes, putting all the commands for one round in one giant write is what I suggested. You can look at the setTargets function you using and see how it builds a command by adding bytes to a list. Doing something like that, you can concatenate multiple commands together before writing them to the serial port. And the other suggestion is to send all the speeds before sending any of the targets, to minimize the latency between the first and last targets.

I am glad that the Maestro is working well for you and I look forward to seeing that video!



Thank you for the suggestion. I implemented it and it works like a charm! No noticeable delay. Working test code is attached.
controlServosSTANDALONE.py (10.3 KB)