-
Notifications
You must be signed in to change notification settings - Fork 110
/
5000-set_tgpio_modbus.py
66 lines (53 loc) · 1.86 KB
/
5000-set_tgpio_modbus.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
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2020, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman <[email protected]> <[email protected]>
"""
Example: Control the bio gripper through the modbus of the end tool
"""
import os
import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
from configparser import ConfigParser
parser = ConfigParser()
parser.read('../robot.conf')
try:
ip = parser.get('xArm', 'ip')
except:
ip = input('Please input the xArm ip address[192.168.1.194]:')
if not ip:
ip = '192.168.1.194'
arm = XArmAPI(ip)
time.sleep(0.5)
if arm.warn_code != 0:
arm.clean_warn()
if arm.error_code != 0:
arm.clean_error()
arm.motion_enable(True)
arm.set_mode(0)
arm.set_state(0)
# code = arm.set_tgpio_modbus_timeout(20)
# print('set_tgpio_modbus_timeout, code={}'.format(code))
# set tool gpio modbus baudrate
code = arm.set_tgpio_modbus_baudrate(2000000)
print('set_tgpio_modbus_baudrate, code={}'.format(code))
time.sleep(2)
# enable bio gripper
code, ret = arm.getset_tgpio_modbus_data([0x08, 0x06, 0x01, 0x00, 0x00, 0x01])
print('set_bio_gripper_enable, code={}, ret={}'.format(code, ret))
# set bio gripper speed
speed = 1000
code, ret = arm.getset_tgpio_modbus_data([0x08, 0x06, 0x03, 0x03, speed // 256 % 256, speed % 256])
print('set_bio_gripper_speed, code={}, ret={}'.format(code, ret))
while arm.connected and arm.error_code == 0:
code, ret = arm.getset_tgpio_modbus_data([0x08, 0x10, 0x07, 0x00, 0x00, 0x02, 0x04, 0x0, 0x0, 0x0, 0x82])
print('open_bio_gripper, code={}, ret={}'.format(code, ret))
time.sleep(2)
code, ret = arm.getset_tgpio_modbus_data([0x08, 0x10, 0x07, 0x00, 0x00, 0x02, 0x04, 0x0, 0x0, 0x0, 0x32])
print('close_bio_gripper, code={}, ret={}'.format(code, ret))
time.sleep(2)