-
Notifications
You must be signed in to change notification settings - Fork 110
/
0001-event_register.py
86 lines (64 loc) · 2.11 KB
/
0001-event_register.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2019, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman <[email protected]> <[email protected]>
"""
Description: event callback registration and release
1. Instantiate XArmAPI and specify do_not_open to be true
2. Register different event callbacks as needed
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 callback_cmdnum_changed(item):
print('cmdnum changed:', item)
def callback_state_changed(item):
print('state changed:', item)
def callback_connect_changed(item):
print('connect changed:', item)
def callback_error_warn_changed(item):
print('error warn changed:', item)
def callback_maable_mtbrake_changed(item):
print('maable mtbrake changed:', item)
def callback_report_location(item):
print('location report:', item)
arm = XArmAPI(ip, do_not_open=True)
arm.register_cmdnum_changed_callback(callback=callback_cmdnum_changed)
arm.register_state_changed_callback(callback=callback_state_changed)
arm.register_connect_changed_callback(callback=callback_connect_changed)
arm.register_error_warn_changed_callback(callback=callback_error_warn_changed)
arm.register_mtable_mtbrake_changed_callback(callback=callback_maable_mtbrake_changed)
arm.register_report_location_callback(callback=callback_report_location)
arm.connect()
arm.motion_enable(enable=True)
arm.set_mode(0)
arm.set_state(state=0)
time.sleep(20)
arm.disconnect()