5 from threading
import Lock
11 def open_port(self,port='/dev/ttyACM0',baud=115200):
12 self.
ser=serial.Serial(port, baud, timeout=0.1)
16 self.ser.write(
"Z0\r")
26 if value < 0: value = 0xFFFFFF + 1 + value
27 return str(hex(value).upper()[2:][-2:].rjust(2**byte,
"0"))
31 if value < 0:value = 0xFFFFFF + 1 + value
32 return hex(value).upper()[2:][-2:].rjust(2**byte,
"0")
36 can_data =
''.join(send_data) +
'\r' 37 self.ser.write(can_data)
45 if d3 == 0x53: send_data[1] = self.
int2str(0x00,0)
46 else: send_data[1] = self.
int2str(0x03,0)
48 send_data[2] = self.
int2str(id_num)
49 send_data[3] = self.
int2str(8,0)
50 send_data[4] = self.
int2str(0xF0 + id_num)
51 send_data[5] = self.
int2str(0x00)
56 send_data[10] = self.
int2str(d7)
57 send_data[11] = self.
int2str(d8)
63 while(self.ser.inWaiting() < 1):
65 while(self.ser.read(1) !=
't'):
69 ret = self.ser.read(4)
70 data_len = int(ret[-1],16)
73 ret = self.ser.read(data_len*2)
81 self.ser.flushOutput()
88 cmd = int(data[9]+data[10],16)
89 if(cmd != 0x42):
return [
False,0,0]
91 speed = int(data[11]+data[12]+data[13]+data[14],16)
92 position = int(data[15]+data[16]+data[17]+data[18]+data[19]+data[20],16)
94 if position > 0xFFFFFF/2: position = position - 0xFFFFFF
95 elif position == 0xFFFFFF: position = 0
96 else : position = position
98 return [
True,speed,position]
108 if s_num > 0x00
and s_num < 0x0F :
114 if( number_of_end < _number):
115 while(signal != 0xFF):
117 signal = int(response[13]+response[14],16)
123 if pos >= 0xFFFFFF/2: pos = 0xFFFFFF/2
124 elif pos <= -0xFFFFFF/2: pos = -0xFFFFFF/2
def get_position(self, id_num)
def run_script(self, id_num, s_num)
def stop_motor(self, id_num)
def read_serial_command(self)
def write_serial_command(self, id_num, d3, d4, d5, d6, d7, d8)
def on_servo(self, id_num, data)
def wait_for_script_end(self, _number)
def actuate_continuous_absolute_position(self, id_num, time, pos)
def open_port(self, port='/dev/ttyACM0', baud=115200)
def int2hex(self, value, byte=1)
def int2str(self, value, byte=1)
def write_buffer(self, send_data)