Hello
I am relatively new to the Pololu range of servo controllers and I am currently experimenting with servos using a Micro Maestro 6 which is connected to a Picaxe 08M2 microcontroller via serial comms.
So far I have been sucessful controlling servo positions, speed and acceleration using the Picaxe controller, however I am struggling to interpret the low byte and high byte data when I use the Get Position command to determine a servos position.
When I issue the 0x90 serial command I get two bytes of data back, but I am unsure how to interpret these numbers to get the actual servo position. The table below shows part of a spreadsheet giving the servo position which I am sending to the Micro Maestro 6, and the low & high byte data which is returned. I am allowing a brief pause between Set Target command and the Get Position Command to ensure that the servo gets to its final position. The manual refers to the data being returned as “the position is formatted as a standard littleendian two-byte unsigned integer” but I am unsure what this means.
For Servo_Position = 1000 to 1500 step 1
Gosub Servo_Output
pause 100
serout 1,T4800_4,(144,0)
serin 2,N4800_4,Lowbyte, Highbyte
sertxd(#Servo_Position,",",#Lowbyte,",",#Highbyte,13,10)
Next
I am using 3 x variable names for the Servo Position, Low Byte & High Byte and calling a subroutine to send the servo position to the Picaxe. I have verified that the servo is actually moving to the correct position using the status tab on the control centre.
From your code, it looks like you are inverting the serial data that you are getting back from the Maestro. Please try replacing the “serin” command as follows to see if that works:
The final solution has actually involved 3 separate alterations to the code.
Correcting the inverted serial input. Unfortunately this just caused the program to hang whilst waiting for serial input data.
Adding a 5ms timeout to the serial input. This allowed the programme to keep looping whilst waiting for data and resulted in the low byte being received correctly but the high byte defaulted to 252 for every servo position.
Increasing the Picaxe clock speed to 32MHz. Through a bit of trial and error I determined that the Picaxe operating at a default 4MHz was struggling to process the incoming data bytes fast enough. Gradually increasing the speed to 8MHz and then 16MHz improved the accuracy of the high byte until at 32MHz every data byte was correct.
The final code is as follows:
Setfreq M32
For Servo_Position = 1000 to 1500 step 1
Gosub Servo_Output
pause 1000
serout 1,T4800_32,(144,0)
serin [5],2,T4800_32,Lowbyte, Highbyte
sertxd(#Servo_Position,",",#Lowbyte,",",#Highbyte,13,10)
Next