def main(): args = handleArgs() port = args['port'] if args['all']: ID = xl320.XL320_BROADCAST_ADDR else: ID = args['id'] if port.lower() == 'dummy': ser = ServoSerial(port=port, fake=True) else: ser = ServoSerial(port=port) ser.open() pkt = Packet.makeRebootPacket(ID) # print('pkt', pkt) ser.write(pkt) gramar = 'is' if ID == xl320.XL320_BROADCAST_ADDR: ID = 'all' gramar = 'are' print('Servo[{}] {} rebooting'.format(ID, gramar))
def sweep(port, rate, ID, retry=3): """ Sends a ping packet to ID's from 0 to maximum and prints out any returned messages. Actually send a broadcast and will retry (resend) the ping 3 times ... """ if port == 'dummy': s = ServoSerial(port, rate, fake=True) else: s = ServoSerial(port, rate) if ID < 0: ID = xl320.XL320_BROADCAST_ADDR try: s.open() except SerialException as e: # print('Error opening serial port:') print('-' * 40) print(sys.argv[0], ':') print(e) exit(1) pkt = makePingPacket(ID) # print('ping', pkt) s.write(pkt) # as more servos add up, I might need to increase the cnt number??? for cnt in range(retry): ans = s.read() if ans: for pkt in ans: servo = packetToDict(pkt) utils.prettyPrintPacket(servo) print('raw pkt: {}'.format(pkt)) else: print('Try {}: no servos found'.format(cnt)) time.sleep(0.1) s.close()
pkt = Packet.makeResetPacket(ID, level) if args['all']: servo_str = 'all servos' else: servo_str = 'servo ID {}'.format(args['id']) if level == xl320.XL320_RESET_ALL: level_str = 'all parameters' elif level == xl320.XL320_RESET_ALL_BUT_ID: level_str = 'all parameters but ID' elif level == xl320.XL320_RESET_ALL_BUT_ID_BAUD_RATE: level_str = 'all parameters but ID and baudrate' print('\nResetting {}: {} set to default'.format(servo_str, level_str)) ser.write(pkt) # print('packet', pkt) sleep(1) # do a reboot ----------------------------------------------------------- pkt = Packet.makeRebootPacket(ID) ser.write(pkt) print('\nYour servo(s) should be reset now') sleep(1) # maybe include smarter logic than just spamming every servo ------------ pkt = Packet.makePingPacket(xl320.XL320_BROADCAST_ADDR) ser.write(pkt) for cnt in range(3): ans = ser.read()
# parser.add_argument('-g', '--gpio', help='Raspberry Pi GPIO pin number', type=int, default=17) args = vars(parser.parse_args()) return args args = handleArgs() port = args['port'] angle = args['angle'] if port: print('Opening: {}'.format(port)) serial = ServoSerial(port) # use this if you want to talk to real servos else: print('Using dummy serial port for testing') serial = DummySerial(port) # use this for simulation serial.open() data = [(1, angle), (2, angle), (3, angle), (4, angle), (5, angle), (6, angle), (7, angle), (8, angle), (9, angle), (10, angle), (11, angle), (12, angle)] pkt = Packet.makeBulkAnglePacket(data) serial.write(pkt) # there is no returned status packet, so just write # serial.write(pkt) print('Raw Packet:', pkt) serial.close()