Upload
doankien
View
243
Download
5
Embed Size (px)
Citation preview
Contents
1 pyuarm 31.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.4 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 pyuarm API 52.1 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.4 Module Functions and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Tools 113.1 pyuarm.tools.list_uarms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 pyuarm.tools.firmware.flash_firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3 pyuarm.tools.calibration.calibrate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 Examples 154.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5 Indices and tables 17
Python Module Index 19
i
pyuarm Documentation, Release 2.1.1
This module encapsulates the operations for uArm. It provides basic Movement on Python. Also providesFirmware_helper and Calibration. The module named “pyuarm” makes the API more pythonic.
Other pages (online)
• project page on Github
• Download Page with releases
• This page, when viewed online is at https://pyuarm.readthedocs.io/en/latest/.
Contents:
Contents 1
CHAPTER 1
pyuarm
Overview
This module encapsulates the operations for uArm. It provides basic Movement on Python. Also providesFirmware_helper and Calibration. The module named “pyuarm” makes the API more pythonic.
Other pages (online)
• project page on Github
• Download Page with releases
• This page, when viewed online is at https://pyuarm.readthedocs.io/en/latest/.
Features
• Auto uArm Port detection
• Provide firmware_helper, firmware upgrade online
• Provide Auto Calibration tool
Requirements
• Python 2.7x and Python 3.4x
• uArm Firmware ( uarm_helper firmware -d)
3
pyuarm Documentation, Release 2.1.1
Installation
pyuarm
This install a package that can be used from Python (import pyuarm).
To install for all users on the system, administrator rights (root) may be required.
From PyPI
pyuarm can be installed from PyPI, either manually downloading the files and installing as described below or using:
pip install pyuarm
From source (tar.gz or checkout)
Download the archive from http://pypi.python.org/pypi/pyuarm. Unpack the archive, enter the pyuarm-x.y direc-tory and run:
python setup.py install
4 Chapter 1. pyuarm
CHAPTER 2
pyuarm API
Classes
class pyuarm.uarm.UArm(port_name=None, logger=None, debug=False)Bases: object
connect()This function will open the port immediately. Function will wait for the READY Message for 5 secs. Oncereceived READY message, Function will send the Version search command. :return:
disconnect()disconnect will release/close the uarm port :return:
firmware_version = None
get_analog(pin)Get Analog Value from specific PIN :param pin: :return:
get_digital(pin)
get_firmware_version()Get the firmware version. Protocol Cmd: protocol.GET_FIRMWARE_VERSION :return: firmware ver-sion, if failed return False
get_hardware_version()Get the Product version. Protocol Cmd: protocol.GET_HARDWARE_VERSION :return: firmware version,if failed return False
get_position()Get Current uArm position (x,y,z) mm :return: Returns an array of the format [x, y, z] of the robots currentlocation
get_rom_data(address, data_type=1)Get DATA From EEPROM :param address: 0 - 2048 :param data_type: EEPROM_DATA_TYPE_FLOAT,EEPROM_DATA_TYPE_INTEGER, EEPROM_DATA_TYPE_BYTE :return:
5
pyuarm Documentation, Release 2.1.1
get_servo_angle(servo_number=None)Get Current uArm Servo Angles include offset :param servo_number: if None, Return 4 servos CurrentAngles :return: Returns an angle in degrees, of the servo
get_simulation(x, y, z)validate the coordinate (x,y,z) if it can be reached or not. :param x: :param y: :param z: :return:
get_sn_number()Get Serial Number :return:
get_tip_sensor()Get Status from Tip Sensor :return: True On/ False Off
hardware_version = None
is_connected()is_connected will return the uarm connected status :return: connected status
is_moving()Detect is uArm moving :return: Returns a 0 or a 1, depending on whether or not the robot is moving.
is_ready()
set_buzzer(frequency, duration)Turn on the uArm Buzzer :param frequency: The frequency, in Hz :param duration: The duration of thebuzz, in seconds :return:
set_gripper(catch)Turn On/Off Gripper :param catch: True On/ False Off :return:
set_position(x, y, z, speed=300, relative=False, wait=False)Move uArm to the position (x,y,z) unit is mm, speed unit is mm/sec :param x: :param y: :param z: :paramspeed: :return:
set_pump(ON)Control uArm Pump On or OFF :param ON: True On, False OFF :return: succeed True or Failed False
set_rom_data(address, data, data_type=1)Set DATA to EEPROM :param address: 0 - 2048 :param data: Value :param data_type: EEP-ROM_DATA_TYPE_FLOAT, EEPROM_DATA_TYPE_INTEGER, EEPROM_DATA_TYPE_BYTE :re-turn:
set_servo_angle(servo_number, angle)Set uArm Servo Angle, 0 - 180 degrees, this Function will include the manual servo offset.:param servo_number: lease reference protocol.py SERVO_BOTTOM, SERVO_LEFT, SERVO_RIGHT,SERVO_HAND :param angle: 0 - 180 degrees :return: succeed True or Failed False
set_servo_attach(servo_number=None)Set Servo status attach, Servo Attach will lock the servo, You can’t move uArm with your hands.:param servo_number: If None, will attach all servos, please reference protocol.py SERVO_BOTTOM,SERVO_LEFT, SERVO_RIGHT, SERVO_HAND :return: succeed True or Failed False
set_servo_detach(servo_number=None)Set Servo status detach, Servo Detach will unlock the servo, You can move uArm with your hands. Butmove function won’t be effect until you attach. :param servo_number: If None, will detach all servos,please reference protocol.py SERVO_BOTTOM, SERVO_LEFT, SERVO_RIGHT, SERVO_HAND :re-turn: succeed True or Failed False
set_wrist(angle)Set uArm Hand Wrist Angle. Include servo offset. :param angle: :return:
6 Chapter 2. pyuarm API
pyuarm Documentation, Release 2.1.1
pyuarm.uarm.get_uarm(logger=None)It will return the first uArm Port detected by pyuarm.tools.list_uarms, If no available uArm ports, will printThere is no uArm port available
>>> import pyuarm>>> uarm = pyuarm.get_uarm()There is no uArm port available
Returns uArm() Instance
Exception
class pyuarm.util.UArmConnectException(errno, message=None)
Constants
TO-DO
Module Functions and attributes
pyuarm.tools.list_uarms
pyuarm.tools.list_uarms.check_port_plug_in(serial_id)
pyuarm.tools.list_uarms.get_port_property(port_name)
pyuarm.tools.list_uarms.get_uarm_port_cli()
pyuarm.tools.list_uarms.uarm_ports()
pyuarm.tools.firmware.flash_firmware
class pyuarm.tools.firmware.flash_firmware.FlashFirmware
download_firmware()
flash_firmware()
pyuarm.tools.firmware.flash_firmware.download(url, filepath)
pyuarm.tools.firmware.flash_firmware.exit_fun()
pyuarm.tools.firmware.flash_firmware.flash(port, firmware_path, avrdude_path=None)
pyuarm.tools.firmware.flash_firmware.gen_flash_cmd(port, firmware_path, avr-dude_path=None)
pyuarm.tools.firmware.flash_firmware.get_uarm_port_cli()
pyuarm.tools.firmware.flash_firmware.resourcePath(relative_path)Get absolute path to resource, works for dev and for PyInstaller
2.2. Exception 7
pyuarm Documentation, Release 2.1.1
pyuarm.tools.firmware.flash_firmware.uarm_ports(hardware_id=’USBVID:PID=0403:6001’)
pyuarm.tools.calibration.calibrate
pyuarm.tools.calibration.calibrate.calibrate(port_name)
pyuarm.tools.calibration.calibrate.exit_fun()
pyuarm.tools.calibration.calibrate.get_serial_line(sp)
pyuarm.tools.calibration.calibrate.read_completed_flag(uarm, flag_type)
pyuarm.tools.calibration.calibrate.read_linear_offset(uarm)
pyuarm.tools.calibration.calibrate.read_manual_offset(uarm)
pyuarm.tools.miniterm
class pyuarm.tools.miniterm.SerialMode(uarm)Bases: cmd.Cmd
default(line)
do_EOF(args)
do_quit(args)
intro = ‘Welcome to Serial Mode.’
prompt = ‘Serial >>> ‘
uarm = None
class pyuarm.tools.miniterm.UArmCmd(port=None, debug=False, *args, **kwargs)Bases: cmd.Cmd
FIRMWARE = [’version’, ‘force’, ‘upgrade’]
ON_OFF = [’on’, ‘off’]
SERVO_STATUS = [’attach’, ‘detach’]
complete_pump(text, line, begidx, endidx)
complete_servo(text, line, begidx, endidx)
connect(port=None, debug=False)connect uArm. :param port: :return:
do_EOF(args)Quit, if uarm is connected, will disconnect before quit
do_alert(arg)alert control buzzer format: alert frequency duration eg. alert 1 1
do_connect(arg)connect, Open uArm Port, if more than one uArm Port found, will prompt options to choose. Pleaseconnect to uArm before you do any control action
do_disconnect(arg)disconnect, Release uarm port.
8 Chapter 2. pyuarm API
pyuarm Documentation, Release 2.1.1
do_get_angle(arg)get_angle Read current servo angle. format: read_angle servo_number servo_number:
0 bottom servo, 1 left servo, 2 right servo,
if no servo_number provide, will list all servos angle eg. >>> get_angle Current Servo Angles: b:17.97,l:112.72, r:17.97, h:151.14
do_get_position(arg)get_position get current coordinate
do_help(arg)
do_pump(arg)pump turn on/off pump
do_quit(args)Quit, if uarm is connected, will disconnect before quit
do_serial(arg)Raw Serial Mode You could direct input the communication protocol here.
do_servo(arg)Servo status format: servo attach servo_number
servo detach servo_number
servo_number: 0 bottom servo, 1 left servo, 2 right servo, 3 hand servo all
eg. servo attach all servo detach all
do_set_angle(arg)set_angle format: write_angle servo_number angle servo_number:
0 bottom servo, 1 left servo, 2 right servo, 3 hand servo
eg. >>> set_angle 0 90 succeed
do_set_position(arg)set_position, move to destination coordinate. format: set_position X Y Z or move_to X Y Z S X,Y,Z unitmillimeter, S means Speed, unit mm/s eg. set_position 100 200 150
do_sim(arg)sim format: sim X Y Z validate the coordinate. eg. sim 100 200 100 succeed
do_sp(args)same with set_position
help_msg = ‘Shortcut:\nQuit: Ctrl + D, or input: quit\nClear Screen: Ctrl + L’
intro = ‘Welcome to use uArm Command Line - v0.1.4\nShortcut:\nQuit: Ctrl + D, or input: quit\nClear Screen: Ctrl + L\n\nInput help for more usage’
prompt = ‘>>> ‘
ruler = ‘-‘
uarm = None
2.4. Module Functions and attributes 9
CHAPTER 3
Tools
pyuarm.tools.list_uarms
pyuarm.tools.list_uarms.main()
$ python -m pyuarm.tools.list_uarms/dev/cu.usbserial-A600CVS91 ports found
pyuarm.tools.firmware.flash_firmware
pyuarm.tools.firmware.flash_firmware.main(args)
pyuarm.tools.calibration.calibrate
pyuarm.tools.calibration.calibrate.main(args)
pyuarm.tools.miniterm
class pyuarm.tools.miniterm.SerialMode(uarm)Bases: cmd.Cmd
default(line)
do_EOF(args)
do_quit(args)
intro = ‘Welcome to Serial Mode.’
11
pyuarm Documentation, Release 2.1.1
prompt = ‘Serial >>> ‘
uarm = None
class pyuarm.tools.miniterm.UArmCmd(port=None, debug=False, *args, **kwargs)Bases: cmd.Cmd
FIRMWARE = [’version’, ‘force’, ‘upgrade’]
ON_OFF = [’on’, ‘off’]
SERVO_STATUS = [’attach’, ‘detach’]
complete_pump(text, line, begidx, endidx)
complete_servo(text, line, begidx, endidx)
connect(port=None, debug=False)connect uArm. :param port: :return:
do_EOF(args)Quit, if uarm is connected, will disconnect before quit
do_alert(arg)alert control buzzer format: alert frequency duration eg. alert 1 1
do_connect(arg)connect, Open uArm Port, if more than one uArm Port found, will prompt options to choose. Pleaseconnect to uArm before you do any control action
do_disconnect(arg)disconnect, Release uarm port.
do_get_angle(arg)get_angle Read current servo angle. format: read_angle servo_number servo_number:
0 bottom servo, 1 left servo, 2 right servo,
if no servo_number provide, will list all servos angle eg. >>> get_angle Current Servo Angles: b:17.97,l:112.72, r:17.97, h:151.14
do_get_position(arg)get_position get current coordinate
do_help(arg)
do_pump(arg)pump turn on/off pump
do_quit(args)Quit, if uarm is connected, will disconnect before quit
do_serial(arg)Raw Serial Mode You could direct input the communication protocol here.
do_servo(arg)Servo status format: servo attach servo_number
servo detach servo_number
servo_number: 0 bottom servo, 1 left servo, 2 right servo, 3 hand servo all
eg. servo attach all servo detach all
12 Chapter 3. Tools
pyuarm Documentation, Release 2.1.1
do_set_angle(arg)set_angle format: write_angle servo_number angle servo_number:
0 bottom servo, 1 left servo, 2 right servo, 3 hand servo
eg. >>> set_angle 0 90 succeed
do_set_position(arg)set_position, move to destination coordinate. format: set_position X Y Z or move_to X Y Z S X,Y,Z unitmillimeter, S means Speed, unit mm/s eg. set_position 100 200 150
do_sim(arg)sim format: sim X Y Z validate the coordinate. eg. sim 100 200 100 succeed
do_sp(args)same with set_position
help_msg = ‘Shortcut:\nQuit: Ctrl + D, or input: quit\nClear Screen: Ctrl + L’
intro = ‘Welcome to use uArm Command Line - v0.1.4\nShortcut:\nQuit: Ctrl + D, or input: quit\nClear Screen: Ctrl + L\n\nInput help for more usage’
prompt = ‘>>> ‘
ruler = ‘-‘
uarm = None
3.3. pyuarm.tools.calibration.calibrate 13
CHAPTER 4
Examples
Usage
Initialize uArm
There are two methods to Initialize uArm.
• Use get_uarm()
>>> import pyuarm>>> uarm = pyuarm.get_uarm()Firmware Version: 2.1.4
if no uArm connected, will return None and display “There is no uArm Port available”
>>> import pyuarm>>> uarm = pyuarm.get_uarm()There is no uArm port available>>> print uarmNone
• Use uArm()
>>> import pyuarm>>> uarm = pyuarm.UArm()Firmware Version: 2.1.4
If no uArm connected, will raise UArmConnectException.
>>> uarm = pyuarm.UArm()pyuarm - INFO - pyuarm version: 2.1.1Traceback (most recent call last):
File "<stdin>", line 1, in <module>File "/Users/alex/Worksapce/project/metal/python/pyuarm/pyuarm/uarm.py", line 35,
→˓in __init__
15
pyuarm Documentation, Release 2.1.1
raise UArmConnectException(0, "No uArm ports is found.")pyuarm.util.UArmConnectException: 'Unable to connect uArm-No uArm ports is found.'
You could turn on Debug Mode
>>> uarm = pyuarm.UArm(debug=True)pyuarm - INFO - pyuarm version: 2.1.1pyuarm - INFO - Connecting from port - /dev/cu.usbserial-A600CRE6...pyuarm - INFO - connected...pyuarm - DEBUG - Communication| [gVer] [SH2-2.1.4]pyuarm - INFO - Firmware Version: 2.1.4
Define the uArm port
>>> uarm = pyuarm.UArm(port_name='/dev/cu.usbserial-A600CRE6')pyuarm - INFO - pyuarm version: 2.1.1pyuarm - INFO - Connecting from port - /dev/cu.usbserial-A600CRE6...pyuarm - INFO - connected...pyuarm - INFO - Firmware Version: 2.1.4
Movement
>>> uarm.set_position(150, 150, 150) #default speed is 300 mm/sec>>> uarm.set_position(150, 150, 150, 100) ### set position in 100 mm/sec
Current Positions
>>> uarm.get_position() # Get Current position[354.62, 0.0, 90.0]
Pump control
>>> uarm.set_pump(True) ### Pump On>>> uarm.set_pump(False) ### Pump Off
Others
• List uArm Ports
>>> from pyuarm.tools.list_uarms import uarm_ports>>> uarm_ports()['/dev/cu.usbserial-A600CRE6']
16 Chapter 4. Examples
Python Module Index
ppyuarm.tools.calibration.calibrate, 11pyuarm.tools.firmware.flash_firmware,
11pyuarm.tools.list_uarms, 11pyuarm.tools.miniterm, 11pyuarm.uarm, 5
19
Index
Ccalibrate() (in module pyuarm.tools.calibration.calibrate),
8check_port_plug_in() (in module
pyuarm.tools.list_uarms), 7complete_pump() (pyuarm.tools.miniterm.UArmCmd
method), 8, 12complete_servo() (pyuarm.tools.miniterm.UArmCmd
method), 8, 12connect() (pyuarm.tools.miniterm.UArmCmd method), 8,
12connect() (pyuarm.uarm.UArm method), 5
Ddefault() (pyuarm.tools.miniterm.SerialMode method), 8,
11disconnect() (pyuarm.uarm.UArm method), 5do_alert() (pyuarm.tools.miniterm.UArmCmd method),
8, 12do_connect() (pyuarm.tools.miniterm.UArmCmd
method), 8, 12do_disconnect() (pyuarm.tools.miniterm.UArmCmd
method), 8, 12do_EOF() (pyuarm.tools.miniterm.SerialMode method),
8, 11do_EOF() (pyuarm.tools.miniterm.UArmCmd method),
8, 12do_get_angle() (pyuarm.tools.miniterm.UArmCmd
method), 8, 12do_get_position() (pyuarm.tools.miniterm.UArmCmd
method), 9, 12do_help() (pyuarm.tools.miniterm.UArmCmd method),
9, 12do_pump() (pyuarm.tools.miniterm.UArmCmd method),
9, 12do_quit() (pyuarm.tools.miniterm.SerialMode method),
8, 11do_quit() (pyuarm.tools.miniterm.UArmCmd method), 9,
12
do_serial() (pyuarm.tools.miniterm.UArmCmd method),9, 12
do_servo() (pyuarm.tools.miniterm.UArmCmd method),9, 12
do_set_angle() (pyuarm.tools.miniterm.UArmCmdmethod), 9, 12
do_set_position() (pyuarm.tools.miniterm.UArmCmdmethod), 9, 13
do_sim() (pyuarm.tools.miniterm.UArmCmd method), 9,13
do_sp() (pyuarm.tools.miniterm.UArmCmd method), 9,13
download() (in modulepyuarm.tools.firmware.flash_firmware), 7
download_firmware() (pyuarm.tools.firmware.flash_firmware.FlashFirmwaremethod), 7
Eexit_fun() (in module pyuarm.tools.calibration.calibrate),
8exit_fun() (in module pyuarm.tools.firmware.flash_firmware),
7
FFIRMWARE (pyuarm.tools.miniterm.UArmCmd at-
tribute), 8, 12firmware_version (pyuarm.uarm.UArm attribute), 5flash() (in module pyuarm.tools.firmware.flash_firmware),
7flash_firmware() (pyuarm.tools.firmware.flash_firmware.FlashFirmware
method), 7FlashFirmware (class in
pyuarm.tools.firmware.flash_firmware), 7
Ggen_flash_cmd() (in module
pyuarm.tools.firmware.flash_firmware), 7get_analog() (pyuarm.uarm.UArm method), 5get_digital() (pyuarm.uarm.UArm method), 5
21
pyuarm Documentation, Release 2.1.1
get_firmware_version() (pyuarm.uarm.UArm method), 5get_hardware_version() (pyuarm.uarm.UArm method), 5get_port_property() (in module pyuarm.tools.list_uarms),
7get_position() (pyuarm.uarm.UArm method), 5get_rom_data() (pyuarm.uarm.UArm method), 5get_serial_line() (in module
pyuarm.tools.calibration.calibrate), 8get_servo_angle() (pyuarm.uarm.UArm method), 5get_simulation() (pyuarm.uarm.UArm method), 6get_sn_number() (pyuarm.uarm.UArm method), 6get_tip_sensor() (pyuarm.uarm.UArm method), 6get_uarm() (in module pyuarm.uarm), 6get_uarm_port_cli() (in module
pyuarm.tools.firmware.flash_firmware), 7get_uarm_port_cli() (in module pyuarm.tools.list_uarms),
7
Hhardware_version (pyuarm.uarm.UArm attribute), 6help_msg (pyuarm.tools.miniterm.UArmCmd attribute),
9, 13
Iintro (pyuarm.tools.miniterm.SerialMode attribute), 8, 11intro (pyuarm.tools.miniterm.UArmCmd attribute), 9, 13is_connected() (pyuarm.uarm.UArm method), 6is_moving() (pyuarm.uarm.UArm method), 6is_ready() (pyuarm.uarm.UArm method), 6
Mmain() (in module pyuarm.tools.calibration.calibrate), 11main() (in module pyuarm.tools.firmware.flash_firmware),
11main() (in module pyuarm.tools.list_uarms), 11
OON_OFF (pyuarm.tools.miniterm.UArmCmd attribute),
8, 12
Pprompt (pyuarm.tools.miniterm.SerialMode attribute), 8,
11prompt (pyuarm.tools.miniterm.UArmCmd attribute), 9,
13pyuarm.tools.calibration.calibrate (module), 8, 11pyuarm.tools.firmware.flash_firmware (module), 7, 11pyuarm.tools.list_uarms (module), 7, 11pyuarm.tools.miniterm (module), 8, 11pyuarm.uarm (module), 5
Rread_completed_flag() (in module
pyuarm.tools.calibration.calibrate), 8
read_linear_offset() (in modulepyuarm.tools.calibration.calibrate), 8
read_manual_offset() (in modulepyuarm.tools.calibration.calibrate), 8
resourcePath() (in modulepyuarm.tools.firmware.flash_firmware), 7
ruler (pyuarm.tools.miniterm.UArmCmd attribute), 9, 13
SSerialMode (class in pyuarm.tools.miniterm), 8, 11SERVO_STATUS (pyuarm.tools.miniterm.UArmCmd at-
tribute), 8, 12set_buzzer() (pyuarm.uarm.UArm method), 6set_gripper() (pyuarm.uarm.UArm method), 6set_position() (pyuarm.uarm.UArm method), 6set_pump() (pyuarm.uarm.UArm method), 6set_rom_data() (pyuarm.uarm.UArm method), 6set_servo_angle() (pyuarm.uarm.UArm method), 6set_servo_attach() (pyuarm.uarm.UArm method), 6set_servo_detach() (pyuarm.uarm.UArm method), 6set_wrist() (pyuarm.uarm.UArm method), 6
UUArm (class in pyuarm.uarm), 5uarm (pyuarm.tools.miniterm.SerialMode attribute), 8, 12uarm (pyuarm.tools.miniterm.UArmCmd attribute), 9, 13uarm_ports() (in module
pyuarm.tools.firmware.flash_firmware), 7uarm_ports() (in module pyuarm.tools.list_uarms), 7UArmCmd (class in pyuarm.tools.miniterm), 8, 12UArmConnectException (class in pyuarm.util), 7
22 Index