Micro Maestro 6 Get Position Data

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.

Any help would be appreciated.

Servo Position Low Byte High Byte
1000 9 0
1001 75 0
1002 37 0
1003 74 0
1004 18 0
1005 73 0
1006 36 0
1007 72 0
1008 132 0
1009 71 0
1010 35 0
1011 70 0
1012 17 0
1013 69 0
1014 34 0
1015 68 0
1016 8 0
1017 67 0
1018 33 0
1019 66 0
1020 16 0
1021 65 0
1022 32 0
1023 64 0
1024 223 0
1025 223 7
1026 239 7
1027 222 7
1028 247 7
1029 221 7
1030 238 7
1031 220 7
1032 251 0
1033 219 7
1034 237 7
1035 218 7
1036 246 7
1037 217 7
1038 236 7
1039 216 7
1040 125 0
1041 215 7
1042 235 7
1043 214 7
1044 245 7
1045 213 7
1046 234 7
1047 212 7
1048 250 0
1049 211 7
1050 233 7

Hello.

In little endian, you store the least significant byte in the smallest address. Normally, you should be able to reconstruct the full integer by doing:

firstByte + 256*secondByte

However, the bytes you listed don’t look correct. Could you please post the simplest code example that demonstrates the issue?

-Derrill

Picaxe code as follows:

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:

serin 2, T4800_4, Lowbyte, Highbyte

-Derrill

Derrill

Thanks for spotting that error.

The final solution has actually involved 3 separate alterations to the code.

  1. Correcting the inverted serial input. Unfortunately this just caused the program to hang whilst waiting for serial input data.
  2. 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.
  3. 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