Python Library Documentation: class SwiftAPI in module uarm.wrapper.swift_api
The API wrapper of Swift and SwiftPro
:param port: default is select the first port
:param baudrate: default is 115200
:param timeout: tiemout of serial read, default is None
:param filters: like {'hwid': 'USB VID:PID=2341:0042'}
:param do_not_open: default is False
:param kwargs:
dev_port: compatible the pyuf params, default is None
baud: compatible the pyuf params, default is None
filters: like {'hwid': 'USB VID:PID=2341:0042'}
do_not_open: default is False
cmd_pend_size: cmd cache size, default is 2
cmd_timeout: cmd wait response timeout, default is 2
callback_thread_pool_size: callback thread poll size, default is 0 (not use thread)
==0: not use thread
==1: use asyncio if asyncio exist else not use thread
>2: use thread pool
enable_handle_thread: True/False, default is True
enable_write_thread: True/False, default is False
enable_handle_report_thread: True/False, default is False
default cmd timeout is 2s
Connect
:param port: default is use the port in initialization
:param baudrate: default is use the baudrate in initialization
:param timeout: default is use the timeout in initialization
Disconnect
:param is_clean: clean the thread pool or not, default is True
Wait until all async command return or timeout
:param timeout: timeout, default is None(wait all async cmd return)
:param wait_stop: True/False, default is False, if set True, will waiting the uArm not in moving or timeout
:return: 'OK' or 'TIMEOUT'
Get the analog value from specific pin
:param pin: pin, default is 0
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: analog value or 'TIMEOUT' if wait is True else None
Get the uArm info
:param timeout: default is 10s
:return: {
"device_type": "SwiftPro",
"hardware_version": "3.2.0",
"firmware_version": "3.3.0",
"api_version": "3.2.0",
"device_unique": "D43639DB0CEE"
}
Get the digital value from specific pin
:param pin: pin, default is 0
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: digital value (0 or 1) or 'TIMEOUT' if wait is True else None
Get the status of the gripper
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: int value (0: stop, 1: working, 2: catch thing) or 'TIMEOUT' if wait is True else None
Check uArm is moving or not
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: True/False if wait is True else None
Get the status of the limit switch
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: True/False or 'TIMEOUT' if wait is True else None
Get the mode, only support SwiftPro
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: mode if wait is True else None
Get the polar coordinate
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: [stretch, rotation, height] or 'TIMEOUT' if wait is True else None
Get the position
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: [x, y, z] or 'TIMEOUT' if wait is True else None
Get the power status
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: power status if wait is True else None
Get the status of the pump
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: int value (0: stop, 1: working, 2: pump thing) or 'TIMEOUT' if wait is True else None
Get data from eeprom
:param address: 0 - 64K byte
:param data_type: 4: EEPROM_DATA_TYPE_FLOAT, 2: EEPROM_DATA_TYPE_INTEGER, 1: EEPROM_DATA_TYPE_BYTE
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: int or float value or 'TIMEOUT' if wait is True
Notes:
EEPROM default data format, each item is one offline record data (no header at beginning):
[p0, p1, p2, p3, p4, p5 ... p_end]
each record data is 10 bytes, and each item inside is 2 bytes:
[a0, a1, a2, a3, accessories_state]
a0~3: unsigned fixed point of servos' angle (multiply by 100)
accessories_state:
bit0: pump on/off
bit4: griper on/off
p_end indicate the end of records, filled by 0xffff
Get the servo angle
:param servo_id: servo id, default is None(get the all servo angle), 0: BOTTOM, 1: LEFT, 2: RIGHT
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: angle or angle list if wait is True else None
Get servo attach status
:param servo_id: servo id, default is 0
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: True/False or 'TIMEOUT' if wait is True else None
Get the temperature
:return: {
'current_temperature': current_temperature,
'target_temperature': target_temperature
}
Grove control, cmd: M2307 P{pin} V{value}
:param pin: pin/port, default is None, you must set the pin
:param value:
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
def grove_init(self, pin=None, grove_type=None, value=None, wait=True, timeout=None, callback=None):
Grove init, cmd: M2305 P{pin} N{grove_type} V{value}
:param pin: pin/port, default is None, you must set the pin
:param grove_type:
:param value:
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set the callback to handle grove report
:param pin: pin/port, default is None, you must set it
:param callback: callback, default is None
:return: True/False
Set the callback to handle key0 (BUTTON MENU) event
:param callback: callback, default is None
:return: True/False
Set the callback to handle key1 (BUTTON PLAY) event
:param callback: callback, default is None
:return: True/False
Set the callback to handle limit switch status change
:param callback: callback, default is None
:return: True/False
Set the callback to handle power status change
:param callback: callback, default is None
:return: True/False
Set the callback to handle postiton report
:param callback: callback, default is None
:return: True/False
Release the register callback
:param pin: pin/port, default is None, you must set it
:param callback: callback, default is None, will release all callback by pin
:return:
Release the register callback
:param callback: callback, default is None, will release all key0 callback
:return:
Release the register callback
:param callback: callback, default is None, will release all key1 callback
:return:
Release the register callback
:param callback: callback, default is None, will release all limit switch callback
:return:
Release the register callback
:param callback: callback, default is None, will release all power callback
:return:
Release the register callback
:param callback: callback, default is None, will release all report position callback
:return:
Reset the uArm
:param speed: reset speed, default is the last speed in use or 1000
:param wait: True/False, default is True
:param timeout: timeout, default is 10s
:param x: reset-position-x, default is 200
:param y: reset-position-y, default is 0
:param z: reset-position-z, default is 150
Send cmd async
:param msg: cmd
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
Send cmd sync
:param msg: cmd, example: G0 X150 F1000
:param timeout: timeout of waiting, default is use the default cmd timeout
:param no_cnt: do not add cnt prefix or not, default is False
:return: result
def set_3d_feeding(self, distance=0, speed=None, relative=True, x=None, y=None, z=None, wait=True, timeout=30, callback=None):
Control the feeding, only support SwiftPro, you must set the mode to the 3D printing mode (2) and set temperature over 170 °C
:param distance: feeding distance, default is 0
:param speed: feeding or move speed, default is the last speed in use or 1000
:param relative: relative or not, default is True, if you set it to False, you must calc the distance of feeding
:param x: move postition-X, default is None, not move it
:param y: move postition-Y, default is None, not move it
:param z: move postition-Z, default is None, not move it
:param wait: True/False, default is True
:param timeout: timeout, default is 30s
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set the acceleration
:param acc: acc value
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
def set_acceleration2(self, printing_moves=None, retract_moves=None, travel_moves=None, min_feedrate=None, min_travel_feedrate=None, min_segment_time=None, max_xy_jerk=None, max_z_jerk=None, max_e_jerk=None):
Set the acceleration
:param printing_moves: Printing moves, default is None (not set it)
:param retract_moves: Retract only (no X, Y, Z) moves, default is None (not set it)
:param travel_moves: Travel (non printing) moves, default is None (not set it)
:param min_feedrate: Min Feed Rate (units/s), default is None (not set it)
:param min_travel_feedrate: Min Travel Feed Rate (units/s), default is None (not set it)
:param min_segment_time: Min Segment Time (us), default is None (not set it)
:param max_xy_jerk: Max XY Jerk (units/sec^2), default is None (not set it)
:param max_z_jerk: Max Z Jerk (units/sec^2), default is None (not set it)
:param max_e_jerk: Max E Jerk (unit/sec^2), default is None (not set it)
:return: 'OK'
def set_buzzer(self, frequency=None, duration=None, wait=False, timeout=None, callback=None, **kwargs):
Control the buzzer
:param frequency: frequency, default is 1000
:param duration: duration, default is 2s
:param wait: True/False, default is False
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:param kwargs: compatible the pyuf params
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set digital direction
:param pin: pin
:param value: 0: input, 1: output
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set digital output value
:param pin: pin
:param value: digital value
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK'/'Ex' or 'TIMEOUT' if wait is True else None
Control the fan, only support SwiftPro, will auto set the mode to 3D printing mode (2)
:param on: True/False, default is False(close the fan)
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Control the gripper
:param catch: True/False, default is False (Open)
:param wait: True/False, default is True
:param check: True/False, default is False, check the catch status or not if wait is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set the mode, only support SwiftPro
:param mode: mode, 0: general mode, 1: laser mode, 2: 3D Print mode, 3: pen/gripper mode
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: mode if wait is True else None
def set_polar(self, stretch=None, rotation=None, height=None, speed=None, relative=False, wait=False, timeout=10, callback=None, **kwargs):
Set the polar coordinate
:param stretch: (mm), default is the last stretch in use or 200
:param rotation: (degree), default is the last rotation in use or 90
:param height: (mm), default is the last height in use or 150
:param speed: (mm/min) speed of move, default is the last speed in use or 1000
:param relative: True/False, default is False
:param wait: True/False, default is False
:param timeout: timeout, default is 10s
:param callback: callback, default is None
:param kwargs: compatible the pyuf params
:return: 'OK' or 'TIMEOUT' if wait is True else None
def set_position(self, x=None, y=None, z=None, speed=None, relative=False, wait=False, timeout=10, callback=None, cmd='G0'):
Set the position
:param x: (mm) location X, default is the last x in use or 150
:param y: (mm) location Y, default is the last y in use or 0
:param z: (mm) location Z, default is the last z in use or 150
:param speed: (mm/min) speed of move, default is the last speed in use or 1000
:param relative: True/False, default is False
:param wait: True/False, default is False
:param timeout: timeout, default is 10s
:param callback: callback, default is None
:param cmd: 'GO' or 'G1', default is 'G0'
:return: 'OK' or 'TIMEOUT' if wait is True else None
Control the pump
:param on: True/False, default is False (Off)
:param wait: True/False, default is True
:param check: True/False, default is False, check the pump status or not if wait is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Report the grove from specific pin, cmd: M2306 P{pin} V{interval}
:param pin: pin/port, default is None, you must set the pin
:param interval: seconds, default is 0, disable report if interval is 0
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Report the buttons event
:param on: True/False, default is True (report)
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:param kwargs: compatible the pyuf params
:return: 'OK' or 'TIMEOUT' if wait is True else None
Report position in (interval) seconds
:param interval: seconds, default is 0, disable report if interval is 0
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set data to eeprom
:param address: 0 - 64K byte
:param data: data
:param data_type: 4: EEPROM_DATA_TYPE_FLOAT, 2: EEPROM_DATA_TYPE_INTEGER, 1: EEPROM_DATA_TYPE_BYTE
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set the servo angle
:param servo_id: servo id, default is 0 (set the servo bottom angle)
:param angle: (degree, 0~180), default is 90
:param wait: True/False, default is False
:param timeout: timeout, default is 10s
:param speed: (degree/min) speed of move, default is the last speed in use or 1000
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set servo attach
:param servo_id: servo id, default is None, attach all the servo
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set servo detach
:param servo_id: servo id, default is None, detach all the servo
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set the speed factor, the speed will multiply factor
:param factor: factor
:return:
Set the temperature, only support SwiftPro, will auto set the mode to 3D printing mode (2)
:param temperature: temperature, default is 0
:param block: True/False, default is False, if block is True, the uArm system will block until the temperature over you set
:param wait: True/False, default is True
:param timeout: timeout, default is use the default cmd timeout
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Set the wrist angle (SERVO HAND)
:param angle: (degree, 0~180), default is 90
:param wait: True/False, default is False
:param timeout: timeout, default is 10s
:param speed: (degree/min) speed of move, default is the last speed in use or 1000
:param callback: callback, default is None
:return: 'OK' or 'TIMEOUT' if wait is True else None
Waiting the uArm ready
:param timeout: waiting timeout, default is 5s