Exemplo n.º 1
0
 def set_acc_dec_time(self, time):
     commando = b"\x10\x06\x00\x00\x02\x04"
     time = time.to_bytes(4, "big")
     commando = self.unit_id + commando + time
     crc = calc_crc16(commando)
     commando = commando + crc
     self.client.write(commando)
     result = self.client.read()
Exemplo n.º 2
0
 def set_speed(self, speed):
     commando = b"\x10\x04\x80\x00\x02\x04"
     speed = speed.to_bytes(4, 'big')
     commando = self.unit_id + commando + speed
     crc = calc_crc16(commando)
     commando = commando + crc
     self.client.write(commando)
     time.sleep(0.01)
Exemplo n.º 3
0
 def set_position_deviation(self,rev_value):
     commando = b"\x10\x03\x02\x00\x02\x04" 
     rev_value = rev_value.to_bytes(4,'big')
     commando = self.unit_id + commando + rev_value
     crc = calc_crc16(commando)
     commando = commando + crc
     self.client.write(commando)
     result = self.client.read()
Exemplo n.º 4
0
 def go(self,point,speed=2000,rate=1500,stop_rate=1500):
     commando = b"\x10\x00\x58\x00\x10\x20\x00\x00\x00\x00\x00\x00\x00\x01" 
     point = point.to_bytes(4,'big')
     speed = speed.to_bytes(4,'big')
     rate  = rate.to_bytes(4,'big')
     stop_rate = stop_rate.to_bytes(4,'big')
     op_current = b"\x00\x00\x03\xE8" #100%
     trigger = b"\x00\x00\x00\x01"
     commando = self.unit_id + commando + point + speed + rate + stop_rate + op_current + trigger
     crc = calc_crc16(commando)
     commando = commando + crc
     self.client.write(commando)
     result = self.client.read()
    def send_init_packet(self,firmware):
#        super(DfuTransportSerial, self).send_init_packet(init_packet)

	init_packet = 'ffffffffffffffff0100feff'
	init_packet += binascii.hexlify(struct.pack('<H', crc16.calc_crc16(firmware, crc=0xffff)))
	init_packet = binascii.unhexlify(init_packet)
	
        frame = int32_to_bytes(DFU_INIT_PACKET)
        frame += init_packet
        frame += int16_to_bytes(0x0000)  # Padding required

        packet = HciPacket(frame)
        self.send_packet(packet)
        time.sleep(DfuTransportSerial.SEND_INIT_PACKET_WAIT_TIME)
Exemplo n.º 6
0
    def send_init_packet(self, firmware):
        #        super(DfuTransportSerial, self).send_init_packet(init_packet)

        init_packet = 'ffffffffffffffff0100feff'
        init_packet += binascii.hexlify(
            struct.pack('<H', crc16.calc_crc16(firmware, crc=0xffff)))
        init_packet = binascii.unhexlify(init_packet)

        frame = int32_to_bytes(DFU_INIT_PACKET)
        frame += init_packet
        frame += int16_to_bytes(0x0000)  # Padding required

        packet = HciPacket(frame)
        self.send_packet(packet)
        time.sleep(DfuTransportSerial.SEND_INIT_PACKET_WAIT_TIME)
Exemplo n.º 7
0
 def go(self, fw, rev, stop=1):  #fw : 正回転方向のフラグ , rev : 反対回転方向のフラグ
     commando = b"\x10\x00\x7C\x00\x02\x04\x00\x00\x00"
     data = 0
     stop = stop << 5
     rev = rev << 4
     fw = fw << 3
     data = data | stop
     data = data | rev
     data = data | fw
     data = data.to_bytes(1, "big")
     commando = self.unit_id + commando + data
     crc = calc_crc16(commando)
     commando = commando + crc
     self.client.write(commando)
     time.sleep(0.01)
Exemplo n.º 8
0
 def go_list(self,list_number,speed=6000,rate=3000,stop_rate=3000):
     if(self.move_list):
         commando = b"\x10\x00\x58\x00\x10\x20\x00\x00\x00\x00\x00\x00\x00\x01" 
         point = self.move_list[list_number]
         point = point.to_bytes(4,'big')
         speed = speed.to_bytes(4,'big')
         rate  = rate.to_bytes(4,'big')
         stop_rate = stop_rate.to_bytes(4,'big')
         op_current = b"\x00\x00\x03\xE8" #100%
         trigger = b"\x00\x00\x00\x01"
         commando = self.unit_id + commando + point + speed + rate + stop_rate + op_current + trigger
         crc = calc_crc16(commando)
         commando = commando + crc
         self.client.write(commando)
         result = self.client.read()
     else:
         print("Error")
Exemplo n.º 9
0
    def __init__(self, data=''):
        HciPacket.sequence_number = (HciPacket.sequence_number + 1) % 8
        self.temp_data = ''
        self.temp_data += slip_parts_to_four_bytes(
            HciPacket.sequence_number, DATA_INTEGRITY_CHECK_PRESENT,
            RELIABLE_PACKET, HCI_PACKET_TYPE, len(data))
        self.temp_data += data
        # Add escape characters
        crc = crc16.calc_crc16(self.temp_data, crc=0xffff)

        self.temp_data += chr(crc & 0xFF)
        self.temp_data += chr((crc & 0xFF00) >> 8)

        self.temp_data = slip_encode_esc_chars(self.temp_data)

        self.data = chr(0xc0)
        self.data += self.temp_data
        self.data += chr(0xc0)
    def __init__(self, data=''):
        HciPacket.sequence_number = (HciPacket.sequence_number + 1) % 8
        self.temp_data = ''
        self.temp_data += slip_parts_to_four_bytes(HciPacket.sequence_number,
                                                   DATA_INTEGRITY_CHECK_PRESENT,
                                                   RELIABLE_PACKET,
                                                   HCI_PACKET_TYPE,
                                                   len(data))
        self.temp_data += data
        # Add escape characters
        crc = crc16.calc_crc16(self.temp_data, crc=0xffff)

        self.temp_data += chr(crc & 0xFF)
        self.temp_data += chr((crc & 0xFF00) >> 8)

        self.temp_data = slip_encode_esc_chars(self.temp_data)

        self.data = chr(0xc0)
        self.data += self.temp_data
        self.data += chr(0xc0)
Exemplo n.º 11
0
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
import crc16
#off/off/on
client = serial.Serial("/dev/ttyACM0",
                       115200,
                       timeout=10,
                       parity=serial.PARITY_EVEN,
                       stopbits=serial.STOPBITS_ONE)  # COMポートは自分の奴を入れる

size = 16

#速度設定
commando = b"\x01\x10\x04\x80\x00\02\x04\x00\x00\x0F\xA0"
print(commando)
result = crc16.calc_crc16(commando)
print("result")
print(commando + result)
commando = commando + result
client.write(commando)
result = client.read()
print(result)

#回転開始
commando = b"\x01\x10\x00\x7C\x00\02\x04\x00\x00\x00\x28"
print(commando)
result = crc16.calc_crc16(commando)
print("result")
print(commando + result)
commando = commando + result
client.write(commando)