Iam trying to control Micro Maestro 6-Channel USB and 2 servos with python code i found here http://ottobelden.blogspot.com/2009/10/robotic-leg-testing-with-python-pololu.html The code in was made to control Pololu USB 16 RC Servo Controller and wont work with Micro Maestro 6-Channel USB directly.
Iam not sure what i have to change in the code or what iam missing there, to get it work with Micro Maestro 6-Channel USB controller. Looks like my contoller use COM port 21 and 22.
I have changed python code to use port 21 and it seems to connect when i run it (cant connect with Maestro Control Senter same time). Tried port 22 too but no luck.
I can control servos with UscCmd.exe and --list shows me:
1 Maestro USB servo controller device found:
Has anyone good ideas how to get it work?
First of all, if you haven’t done so already, please go into the Maestro Control Center and set the Serial Mode to be “USB Dual Port”. This tells the Maestro to listen for serial commands coming to its Command Port, which is one of the two virtual COM ports it presents to the PC.
You don’t need to change the code for loading the serial port library or opening the serial port, but you do need to change the code that decides which bytes to send to the port, because the Maestro uses a different serial protocol than the Pololu USB 16-Servo Controller.
In several places, you will see code like this:
serstr = chr(0x80)+chr(0x01)+chr(0x01)+chr(0x02)+chr(0x10)
Do you understand what the code above does? You will need to modify the bytes specified there to be Maestro serial commands. The Maestro’s serial protocol is described in the Serial Interface section of the Maestro User’s Guide. The main command you will want to use is called “Set Target”.
Got it working now with Python using siple os.system(“UscCmd --servo 0,4500”). Iam not using direct hex because i didnt find easy way to calculate hex values i want… is there any tools? I didnt find how to see position in hex values from UscCmd tool.
Now i have another question. Is it possible to add steps without knowing previous position? Like if the status position is 4500 and i want to add +500 and servo should go to position 5000.
Tried to UscCmd --servo 0,+500 but it goes to 500
The hex values are pretty simple to calculate in any modern programming language. Did you see the sample C code for computing Set Target bytes in the user’s guide?
serialBytes = 0x84; // Command byte: Set Target.
serialBytes = channel; // First data byte holds channel number.
serialBytes = target & 0x7F; // Second byte holds the lower 7 bits of target.
serialBytes = (target >> 7) & 0x7F; // Third data byte holds the bits 7-13 of target.
You should be able to understand what this code does and convert it to Python. Python has bitwise operators >> and & just like C. You might need to change the syntax used for assigning to an array, and remove the semicolons and comments.
No, we don’t provide an easy way to do that. You can just make an array of 6 integers in your program to keep track of the current targets of the servos.
Iam Ok with UscCmd with Python for now, but ill try to that hex thing when i get another pololu controller
So is there a hard way to command +500 to the servo? If there is no easy way
I managed to use array to get previous value for now but if theres a way to add +500 directly it would speed up a little.
Well the hard way is to run “UscCmd --status”, parse the output to figure out the current target of the servo, then add the number to it in your program, then run “UscCmd” to set the target. I would not do this. I don’t think this will “speed up” anything.
The array of integers is a much better idea. You should be able to write a Python function that takes care of the details for you so your code can be clean. An example use of such a function would look like this:
servo_target_add(0, 300) # Increases the target of servo 0 by 300.