Hi Guys,
I’m not sure if there is any and if so, I couldn’t find it. So I made my own.
Here is the binary version of the ServoDriver subroute used in the Phoenix code V2.0. It is tested with Mikes new firmware.
Version : SSC32-V2.05Alpha4A-EGP
[code];--------------------------------------------------------------------
;[SERVO DRIVER] Updates the positions of the servos
;Binary version
;**********************************************************************
;Extended binary commands.
;
;Commands 0x80-0x9F are group move servo number 0-31. The next 2 bytes
;must be pulse width for the servo:
; 0x80+servoNum, pwHigh, pwLow
;
;Command 0xA0 is the group move servo speed, which must immediately
;follow the pulse width:
; 0xA0, spdHigh, spdLow
;
;Command 0xA1 is the group move time, which must follow all of the
;pulse widths and speeds:
; 0xA1, timeHigh, timeLow
;
;Command 0xA2 is the stop all command, 1 byte
; 0xA2
;**********************************************************************
CoxaPWM var word
FemurPWM var word
TibiaPWM var word
ServoDrivernew:
for LegIndex = 0 to 5
;Update Right Legs
if LegIndex <= 2 then
CoxaPWM = (-CoxaAngle1(LegIndex) +900)*1000/1059+650
FemurPWM = (-FemurAngle1(LegIndex)+900)*1000/1059+650
TibiaPWM = (-TibiaAngle1(LegIndex)+900)*1000/1059+650
else
;Update Left Legs
CoxaPWM = (CoxaAngle1(LegIndex) +900)*1000/1059+650
FemurPWM = (FemurAngle1(LegIndex)+900)*1000/1059+650
TibiaPWM = (TibiaAngle1(LegIndex)+900)*1000/1059+650
endif
serout cSSC_OUT, cSSC_BAUD, [0x80+cCoxaPin(LegIndex) ,CoxaPWM.highbyte, CoxaPWM.lowbyte]
serout cSSC_OUT, cSSC_BAUD, [0x80+cFemurPin(LegIndex),FemurPWM.highbyte, FemurPWM.lowbyte]
serout cSSC_OUT, cSSC_BAUD, [0x80+cTibiaPin(LegIndex),TibiaPWM.highbyte, TibiaPWM.lowbyte]
next
;Send speed and
serout cSSC_OUT, cSSC_BAUD, [0xA1,SSCTime.highbyte,SSCTime.lowbyte,13]
PrevSSCTime = SSCTime
return
;--------------------------------------------------------------------[/code]
The only thing you should do is to replace the old version with this one and make sure you’ve got the right SSC firmware uploaded.
Don’t forget to update this little line
;Wait for previous commands to be completed while walking
pause (PrevSSCTime - CycleTime - 18) MIN 1 ; Min 1 ensures that there alway is a value in the pause command
This line ensures that the previous command is finished before sending a new one. The pause length is SSC speed time - cycleTime used to do IK - time it takes to send the new command. As you will see in the old version the value to send the new command is 45. This is also involves a bit of testing. You don’t want a new command before the previous is finished since not all legs will be on the right position yet. But you also don’t want the move to be already finished for some time since the walking part will be pretty shockey and bumpy.
You have to play a bit with this value to get it right. I couldn’t do it since the battery of the hybrid died while testing this…
Now the good part. I hooked up my logic analyzer to see the differences between the 2 commands. A full update of all 18 servos takes:
- with the original sub: 52ms
- with the binary sub: 18ms 8)
Thats what I call: a good win of some serous processing time! Thanks for the new set of SSC commands Mike!
Xan