device_info = swift1.get_device_info() print(swift1.port, device_info) firmware_version = device_info['firmware_version'] if firmware_version and not firmware_version.startswith( ('0.', '1.', '2.', '3.')): swift1.set_speed_factor(0.00001) swift2.waiting_ready() device_info = swift2.get_device_info() print(swift2.port, device_info) firmware_version = device_info['firmware_version'] if firmware_version and not firmware_version.startswith( ('0.', '1.', '2.', '3.')): swift2.set_speed_factor(0.00001) X = 0 Y = 1 Z = 2 R = 3 swift1.set_servo_detach() swift1.register_report_position_callback(lambda position: swift2.set_position( x=position[X], y=position[Y], z=position[Z], speed=100000000, timeout=1)) # swift1.register_report_position_callback(lambda position: swift2.set_position(x=position[X] + random.random() * 5, y=position[Y] + random.random() * 5 , z=position[Z], speed=100000000, timeout=1)) swift1.set_report_position(interval=0.001) input() swift1.disconnect()
def key_callback(ret, key=None): print('report {}: {}, time: {}'.format(key, ret, time.time())) def limit_switch_callback(ret): print('report limit switch: {}, time: {}'.format(ret, time.time())) swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042'}, do_not_open=True) swift.register_power_callback(callback=power_callback) swift.register_report_position_callback(callback=pos_callback) swift.register_key0_callback( callback=functools.partial(key_callback, key='key0')) swift.register_key1_callback( callback=functools.partial(key_callback, key='key1')) swift.register_limit_switch_callback(callback=limit_switch_callback) swift.connect() swift.waiting_ready() swift.set_report_position(interval=0.1) swift.set_report_keys(on=True) swift.set_servo_detach() time.sleep(60) swift.set_report_position(interval=0) swift.set_report_keys(on=False) swift.set_servo_attach() swift.disconnect()