#!/usr/bin/env python3 # Software License Agreement (BSD License) # # Copyright (c) 2019, UFACTORY, Inc. # All rights reserved. # # Author: Vinman """ Description: this is just an example template 1. Instantiate XArmAPI and specify do_not_open to be true 2. Registration error callback function 3. Connect 4. Enable motion 5. Setting mode 6. Setting state """ import os import sys import time sys.path.append(os.path.join(os.path.dirname(__file__), '../../..')) from xarm.wrapper import XArmAPI ####################################################### """ Just for test example """ if len(sys.argv) >= 2: ip = sys.argv[1] else: try: from configparser import ConfigParser parser = ConfigParser() parser.read('../robot.conf') ip = parser.get('xArm', 'ip') except: ip = input('Please input the xArm ip address:') if not ip: print('input error, exit') sys.exit(1) ######################################################## def hangle_err_warn_changed(item): print('ErrorCode: {}, WarnCode: {}'.format(item['error_code'], item['warn_code'])) # TODO:Do different processing according to the error code arm = XArmAPI(ip, do_not_open=True) arm.register_error_warn_changed_callback(hangle_err_warn_changed) arm.connect() # enable motion arm.motion_enable(enable=True) # set mode: position control mode arm.set_mode(0) # set state: sport state arm.set_state(state=0) time.sleep(10) arm.disconnect()