7 'Roboclaw Interface Class' 9 def __init__(self, comport, rate, timeout=0.01, retries=3):
62 MIXEDSPEEDACCELDIST = 46
67 MIXEDSPEED2ACCELDIST = 51
75 GETMINMAXMAINVOLTAGES = 59
76 GETMINMAXLOGICVOLTAGES = 60
81 M1SPEEDACCELDECCELPOS = 65
82 M2SPEEDACCELDECCELPOS = 66
83 MIXEDSPEEDACCELDECCELPOS = 67
84 SETM1DEFAULTACCEL = 68
85 SETM2DEFAULTACCEL = 69
101 SETM1MAXCURRENT = 133
102 SETM2MAXCURRENT = 134
103 GETM1MAXCURRENT = 135
104 GETM2MAXCURRENT = 136
118 for bit
in range(0, 8):
119 if (self.
_crc&0x8000) == 0x8000:
120 self.
_crc = ((self.
_crc << 1) ^ 0x1021)
128 self._port.write(chr(address))
130 self._port.write(chr(command))
134 data = self._port.read(2)
136 crc = (ord(data[0])<<8) | ord(data[1])
141 data = self._port.read(1)
153 return (1,val1[1]<<8|val2[1])
165 return (1,val1[1]<<24|val2[1]<<16|val3[1]<<8|val4[1])
171 if val[1]&0x80000000:
172 return (val[0],val[1]-0x100000000)
173 return (val[0],val[1])
178 self._port.write(chr(val&0xFF))
202 self._port.flushInput()
208 if self.
_crc&0xFFFF!=crc[1]&0xFFFF:
219 self._port.flushInput()
225 if self.
_crc&0xFFFF!=crc[1]&0xFFFF:
236 self._port.flushInput()
242 if self.
_crc&0xFFFF!=crc[1]&0xFFFF:
253 self._port.flushInput()
261 if self.
_crc&0xFFFF!=crc[1]&0xFFFF:
263 return (1,val1[1],val2[1])
272 self._port.flushInput()
279 for i
in range(0,args):
289 if self.
_crc&0xFFFF==crc[1]&0xFFFF:
623 def _write444444441(self,address,cmd,val1,val2,val3,val4,val5,val6,val7,val8,val9):
643 for i
in range(0,cnt):
644 byte = random.getrandbits(8)
645 self._port.write(chr(byte))
649 return self.
_write1(address,self.Cmd.M1FORWARD,val)
652 return self.
_write1(address,self.Cmd.M1BACKWARD,val)
655 return self.
_write1(address,self.Cmd.SETMINMB,val)
658 return self.
_write1(address,self.Cmd.SETMAXMB,val)
661 return self.
_write1(address,self.Cmd.M2FORWARD,val)
664 return self.
_write1(address,self.Cmd.M2BACKWARD,val)
667 return self.
_write1(address,self.Cmd.M17BIT,val)
670 return self.
_write1(address,self.Cmd.M27BIT,val)
673 return self.
_write1(address,self.Cmd.MIXEDFORWARD,val)
676 return self.
_write1(address,self.Cmd.MIXEDBACKWARD,val)
679 return self.
_write1(address,self.Cmd.MIXEDRIGHT,val)
682 return self.
_write1(address,self.Cmd.MIXEDLEFT,val)
685 return self.
_write1(address,self.Cmd.MIXEDFB,val)
688 return self.
_write1(address,self.Cmd.MIXEDLR,val)
691 return self.
_read4_1(address,self.Cmd.GETM1ENC)
694 return self.
_read4_1(address,self.Cmd.GETM2ENC)
697 return self.
_read4_1(address,self.Cmd.GETM1SPEED)
700 return self.
_read4_1(address,self.Cmd.GETM2SPEED)
703 return self.
_write0(address,self.Cmd.RESETENC)
708 self._port.flushInput()
712 for i
in range(0,48):
713 data = self._port.read(1)
726 if self.
_crc&0xFFFF==crc[1]&0xFFFF:
736 return self.
_write4(address,self.Cmd.SETM1ENCCOUNT,cnt)
739 return self.
_write4(address,self.Cmd.SETM2ENCCOUNT,cnt)
742 return self.
_read2(address,self.Cmd.GETMBATT)
745 return self.
_read2(address,self.Cmd.GETLBATT)
748 return self.
_write1(address,self.Cmd.SETMINLB,val)
751 return self.
_write1(address,self.Cmd.SETMAXLB,val)
754 return self.
_write4444(address,self.Cmd.SETM1PID,long(d*65536),long(p*65536),long(i*65536),qpps)
757 return self.
_write4444(address,self.Cmd.SETM2PID,long(d*65536),long(p*65536),long(i*65536),qpps)
760 return self.
_read4_1(address,self.Cmd.GETM1ISPEED)
763 return self.
_read4_1(address,self.Cmd.GETM2ISPEED)
766 return self.
_writeS2(address,self.Cmd.M1DUTY,val)
769 return self.
_writeS2(address,self.Cmd.M2DUTY,val)
772 return self.
_writeS2S2(address,self.Cmd.MIXEDDUTY,m1,m2)
775 return self.
_writeS4(address,self.Cmd.M1SPEED,val)
778 return self.
_writeS4(address,self.Cmd.M2SPEED,val)
781 return self.
_writeS4S4(address,self.Cmd.MIXEDSPEED,m1,m2)
784 return self.
_write4S4(address,self.Cmd.M1SPEEDACCEL,accel,speed)
787 return self.
_write4S4(address,self.Cmd.M2SPEEDACCEL,accel,speed)
790 return self.
_write4S4S4(address,self.Cmd.MIXEDSPEEDACCEL,accel,speed1,speed2)
793 return self.
_writeS441(address,self.Cmd.M1SPEEDDIST,speed,distance,buffer)
796 return self.
_writeS441(address,self.Cmd.M2SPEEDDIST,speed,distance,buffer)
799 return self.
_writeS44S441(address,self.Cmd.MIXEDSPEEDDIST,speed1,distance1,speed2,distance2,buffer)
802 return self.
_write4S441(address,self.Cmd.M1SPEEDACCELDIST,accel,speed,distance,buffer)
805 return self.
_write4S441(address,self.Cmd.M2SPEEDACCELDIST,accel,speed,distance,buffer)
808 return self.
_write4S44S441(address,self.Cmd.MIXEDSPEEDACCELDIST,accel,speed1,distance1,speed2,distance2,buffer)
811 val = self.
_read2(address,self.Cmd.GETBUFFERS)
813 return (1,val[1]>>8,val[1]&0xFF)
817 val = self.
_read4(address,self.Cmd.GETPWMS)
829 val = self.
_read4(address,self.Cmd.GETCURRENTS)
841 return self.
_write4S44S4(address,self.Cmd.MIXEDSPEED2ACCEL,accel1,speed1,accel2,speed2)
844 return self.
_write4S444S441(address,self.Cmd.MIXEDSPEED2ACCELDIST,accel1,speed1,distance1,accel2,speed2,distance2,buffer)
847 return self.
_writeS24(address,self.Cmd.M1DUTYACCEL,duty,accel)
850 return self.
_writeS24(address,self.Cmd.M2DUTYACCEL,duty,accel)
853 return self.
_writeS24S24(address,self.Cmd.MIXEDDUTYACCEL,duty1,accel1,duty2,accel2)
856 data = self.
_read_n(address,self.Cmd.READM1PID,4)
865 data = self.
_read_n(address,self.Cmd.READM2PID,4)
874 return self.
_write22(address,self.Cmd.SETMAINVOLTAGES,min,max)
877 return self.
_write22(address,self.Cmd.SETLOGICVOLTAGES,min,max)
880 val = self.
_read4(address,self.Cmd.GETMINMAXMAINVOLTAGES)
888 val = self.
_read4(address,self.Cmd.GETMINMAXLOGICVOLTAGES)
896 return self.
_write4444444(address,self.Cmd.SETM1POSPID,long(kd*1024),long(kp*1024),long(ki*1024),kimax,deadzone,min,max)
899 return self.
_write4444444(address,self.Cmd.SETM2POSPID,long(kd*1024),long(kp*1024),long(ki*1024),kimax,deadzone,min,max)
902 data = self.
_read_n(address,self.Cmd.READM1POSPID,7)
908 return (0,0,0,0,0,0,0,0)
911 data = self.
_read_n(address,self.Cmd.READM2POSPID,7)
917 return (0,0,0,0,0,0,0,0)
920 return self.
_write44441(address,self.Cmd.M1SPEEDACCELDECCELPOS,accel,speed,deccel,position,buffer)
923 return self.
_write44441(address,self.Cmd.M2SPEEDACCELDECCELPOS,accel,speed,deccel,position,buffer)
925 def SpeedAccelDeccelPositionM1M2(self,address,accel1,speed1,deccel1,position1,accel2,speed2,deccel2,position2,buffer):
926 return self.
_write444444441(address,self.Cmd.MIXEDSPEEDACCELDECCELPOS,accel1,speed1,deccel1,position1,accel2,speed2,deccel2,position2,buffer)
929 return self.
_write4(address,self.Cmd.SETM1DEFAULTACCEL,accel)
932 return self.
_write4(address,self.Cmd.SETM2DEFAULTACCEL,accel)
935 return self.
_write111(address,self.Cmd.SETPINFUNCTIONS,S3mode,S4mode,S5mode)
949 if self.
_crc&0xFFFF!=crc[1]&0xFFFF:
951 return (1,val1[1],val2[1],val3[1])
958 return self.
_write11(address,self.Cmd.SETDEADBAND,min,max)
961 val = self.
_read2(address,self.Cmd.GETDEADBAND)
963 return (1,val[1]>>8,val[1]&0xFF)
968 return self.
_write0(address,self.Cmd.RESTOREDEFAULTS)
971 return self.
_read2(address,self.Cmd.GETTEMP)
974 return self.
_read2(address,self.Cmd.GETTEMP2)
977 return self.
_read4(address,self.Cmd.GETERROR)
980 val = self.
_read2(address,self.Cmd.GETENCODERMODE)
982 return (1,val[1]>>8,val[1]&0xFF)
986 return self.
_write1(address,self.Cmd.SETM1ENCODERMODE,mode)
989 return self.
_write1(address,self.Cmd.SETM2ENCODERMODE,mode)
993 return self.
_write4(address,self.Cmd.WRITENVM,0xE22EAB7A)
998 return self.
_write0(address,self.Cmd.READNVM)
1003 return self.
_write2(address,self.Cmd.SETCONFIG,config)
1006 return self.
_read2(address,self.Cmd.GETCONFIG)
1009 return self.
_write44(address,self.Cmd.SETM1MAXCURRENT,max,0)
1012 return self.
_write44(address,self.Cmd.SETM2MAXCURRENT,max,0)
1015 data = self.
_read_n(address,self.Cmd.GETM1MAXCURRENT,2)
1021 data = self.
_read_n(address,self.Cmd.GETM2MAXCURRENT,2)
1027 return self.
_write1(address,self.Cmd.SETPWMMODE,mode)
1030 return self.
_read1(address,self.Cmd.GETPWMMODE)
1035 self._port.flushInput()
1038 self._port.write(chr(ee_address))
1043 if self.
_crc&0xFFFF!=crc[1]&0xFFFF:
1052 retval = self.
_write111(address,self.Cmd.WRITEEEPROM,ee_address,ee_word>>8,ee_word&0xFF)
1056 self._port.flushInput()
def SpeedDistanceM1(self, address, speed, distance, buffer)
def SpeedDistanceM1M2(self, address, speed1, distance1, speed2, distance2, buffer)
def SetM1MaxCurrent(self, address, max)
def _write444444441(self, address, cmd, val1, val2, val3, val4, val5, val6, val7, val8, val9)
def _writeS2S2(self, address, cmd, val1, val2)
def SpeedAccelM1M2_2(self, address, accel1, speed1, accel2, speed2)
def TurnLeftMixed(self, address, val)
def SpeedDistanceM2(self, address, speed, distance, buffer)
def _sendcommand(self, address, command)
def SetEncM1(self, address, cnt)
def ReadM1VelocityPID(self, address)
def SetM1PositionPID(self, address, kp, ki, kd, kimax, deadzone, min, max)
def _read4(self, address, cmd)
def _write1(self, address, cmd, val)
def ResetEncoders(self, address)
def _write22(self, address, cmd, val1, val2)
def ReadLogicBatteryVoltage(self, address)
def ReadEncoderModes(self, address)
def ReadMinMaxMainVoltages(self, address)
def SetM2MaxCurrent(self, address, max)
def ForwardBackwardMixed(self, address, val)
def _read2(self, address, cmd)
def SetLogicVoltages(self, address, min, max)
def _writeS24S24(self, address, cmd, val1, val2, val3, val4)
def SpeedAccelM1M2(self, address, accel, speed1, speed2)
def DutyAccelM1M2(self, address, accel1, duty1, accel2, duty2)
def SetMaxVoltageLogicBattery(self, address, val)
def ForwardM2(self, address, val)
def SetM2EncoderMode(self, address, mode)
def GetConfig(self, address)
def _write4444(self, address, cmd, val1, val2, val3, val4)
def BackwardM1(self, address, val)
def ReadSpeedM2(self, address)
def ReadEncM2(self, address)
def ReadEncM1(self, address)
def ReadM1PositionPID(self, address)
def ReadPinFunctions(self, address)
def SpeedAccelDistanceM1M2(self, address, accel, speed1, distance1, speed2, distance2, buffer)
def SetConfig(self, address, config)
def ForwardMixed(self, address, val)
def SetM2PositionPID(self, address, kp, ki, kd, kimax, deadzone, min, max)
def SetPWMMode(self, address, mode)
def WriteEeprom(self, address, ee_address, ee_word)
def SetDeadBand(self, address, min, max)
def ReadBuffers(self, address)
def _write4S4S4(self, address, cmd, val1, val2, val3)
def _write44(self, address, cmd, val1, val2)
def ReadSpeedM1(self, address)
def SpeedAccelDistanceM1M2_2(self, address, accel1, speed1, distance1, accel2, speed2, distance2, buffer)
def DutyM2(self, address, val)
def ReadVersion(self, address)
def _write4S44S441(self, address, cmd, val1, val2, val3, val4, val5, val6)
def ForwardBackwardM1(self, address, val)
def SpeedAccelM1(self, address, accel, speed)
def ReadM2MaxCurrent(self, address)
def SpeedAccelDeccelPositionM1(self, address, accel, speed, deccel, position, buffer)
def _write0(self, address, cmd)
def SetPinFunctions(self, address, S3mode, S4mode, S5mode)
def _write11(self, address, cmd, val1, val2)
def ReadEeprom(self, address, ee_address)
def _readchecksumword(self)
def _writeS2(self, address, cmd, val)
def _read4_1(self, address, cmd)
def SetMainVoltages(self, address, min, max)
def SpeedAccelM2(self, address, accel, speed)
def SpeedAccelDistanceM1(self, address, accel, speed, distance, buffer)
def _write44441(self, address, cmd, val1, val2, val3, val4, val5)
def DutyM1M2(self, address, m1, m2)
def SpeedM1M2(self, address, m1, m2)
def ReadTemp2(self, address)
def DutyAccelM2(self, address, accel, duty)
def _writelong(self, val)
def _write4S444S441(self, address, cmd, val1, val2, val3, val4, val5, val6, val7)
def ForwardBackwardM2(self, address, val)
def crc_update(self, data)
def _writesword(self, val)
def SetM1EncoderMode(self, address, mode)
def ReadM2PositionPID(self, address)
def RestoreDefaults(self, address)
def _write4444444(self, address, cmd, val1, val2, val3, val4, val5, val6, val7)
def ReadPWMMode(self, address)
def SetM2VelocityPID(self, address, p, i, d, qpps)
def _writebyte(self, val)
def _read_n(self, address, cmd, args)
def __init__(self, comport, rate, timeout=0.01, retries=3)
def _write2(self, address, cmd, val)
def ReadMinMaxLogicVoltages(self, address)
def _writeS24(self, address, cmd, val1, val2)
def _read1(self, address, cmd)
def ReadM1MaxCurrent(self, address)
def SendRandomData(self, cnt)
def _writeS441(self, address, cmd, val1, val2, val3)
def DutyAccelM1(self, address, accel, duty)
def _writeword(self, val)
def _writeS4S4(self, address, cmd, val1, val2)
def SpeedAccelDeccelPositionM1M2(self, address, accel1, speed1, deccel1, position1, accel2, speed2, deccel2, position2, buffer)
def ReadISpeedM1(self, address)
def ForwardM1(self, address, val)
def SpeedM1(self, address, val)
def _writesbyte(self, val)
def SetEncM2(self, address, cnt)
def SetM2DefaultAccel(self, address, accel)
def BackwardM2(self, address, val)
def SetMinVoltageMainBattery(self, address, val)
def _write4(self, address, cmd, val)
def ReadPWMs(self, address)
def SetM1VelocityPID(self, address, p, i, d, qpps)
def ReadCurrents(self, address)
def ReadTemp(self, address)
def ReadNVM(self, address)
def _writeS44S441(self, address, cmd, val1, val2, val3, val4, val5)
def _write441(self, address, cmd, val1, val2, val3)
def _write4S44S4(self, address, cmd, val1, val2, val3, val4)
def TurnRightMixed(self, address, val)
def BackwardMixed(self, address, val)
def SpeedAccelDistanceM2(self, address, accel, speed, distance, buffer)
def SetMinVoltageLogicBattery(self, address, val)
def WriteNVM(self, address)
def ReadError(self, address)
def GetDeadBand(self, address)
def ReadISpeedM2(self, address)
def SpeedM2(self, address, val)
def _writeS4(self, address, cmd, val)
def SetM1DefaultAccel(self, address, accel)
def ReadMainBatteryVoltage(self, address)
def ReadM2VelocityPID(self, address)
def SetMaxVoltageMainBattery(self, address, val)
def DutyM1(self, address, val)
def LeftRightMixed(self, address, val)
def _writeS22(self, address, cmd, val1, val2)
def _write111(self, address, cmd, val1, val2, val3)
def SpeedAccelDeccelPositionM2(self, address, accel, speed, deccel, position, buffer)
def _writeslong(self, val)
def _write4S441(self, address, cmd, val1, val2, val3, val4)
def _write4S4(self, address, cmd, val1, val2)