Currently, we are building a robot with a raspberry pi and the AX-12 dynamixel Servo's. We found a python2 library we a currently porting to python3, we pinpointed the problem in a specific method that gives an error in python3.
The Python 2 version actually works like a charm
AX_GOAL_LENGTH = 5
AX_WRITE_DATA = 3
AX_GOAL_POSITION_L = 30
AX_START = 255
AX_REG_WRITE = 4
def move(self, id, position):
self.direction(Ax12.RPI_DIRECTION_TX)
Ax12.port.flushInput()
p = [position&0xff, position>>8]
checksum = (~(id + Ax12.AX_GOAL_LENGTH + Ax12.AX_WRITE_DATA + Ax12.AX_GOAL_POSITION_L + p[0] + p[1]))&0xff
outData = chr(Ax12.AX_START)
outData += chr(Ax12.AX_START)
outData += chr(id)
outData += chr(Ax12.AX_GOAL_LENGTH)
outData += chr(Ax12.AX_WRITE_DATA)
outData += chr(Ax12.AX_GOAL_POSITION_L)
outData += chr(p[0])
outData += chr(p[1])
outData += chr(checksum)
Ax12.port.write(outData)
What we have tried is adjust this variable:
Ax12.port.write(bytes(outData,'utf-8'))
Now the script runs, sadly the Servo won't work anymore.
We also tried to place the bytes in a byte array
result = bytes([Ax12.AX_START, Ax12.AX_START,
Ax12.AX_GOAL_LENGTH,Ax12.AX_REG_WRITE,
Ax12.AX_GOAL_POSITION_L, p[0], p[1], checksum
])
Ax12.port.write(result)
The script runs but the servo won't run.
My believe is that the operations done to outData is different in python3 then in python2. I can't find out what should be adjusted or different.
Anybody sees what I am currently doing wrong?