Skip to content

Commit 473af74

Browse files
author
vinman
committed
add new api
1 parent d669c72 commit 473af74

File tree

11 files changed

+615
-1342
lines changed

11 files changed

+615
-1342
lines changed

doc/api/xarm_api.md

+218-1,230
Large diffs are not rendered by default.

doc/tool/gen_api.py

+40-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,54 @@
77
# Author: Duke Fong <[email protected]>
88

99

10-
import sys, os
10+
import sys
11+
import os
1112
import pydoc
13+
import re
1214

1315
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
1416

1517
from xarm.wrapper import XArmAPI
1618

1719
from doc.tool.markdown_doc import MarkdownDoc
1820

19-
open('../api/xarm_api.md', 'w', encoding='utf-8').write(
20-
pydoc.render_doc(XArmAPI,
21-
title='xArm-Python-SDK API Documentation: %s',
22-
renderer=MarkdownDoc()))
21+
# open('../api/xarm_api.md', 'w', encoding='utf-8').write(
22+
# pydoc.render_doc(XArmAPI,
23+
# title='xArm-Python-SDK API Documentation: %s',
24+
# renderer=MarkdownDoc()))
25+
26+
docs = pydoc.render_doc(XArmAPI,
27+
title='xArm-Python-SDK API Documentation: %s',
28+
renderer=MarkdownDoc()).split('\n')
29+
d = {'#': 1, '##': 2, '###': 3, '####': 4, '#####': 5, '######': 6}
30+
pattern = '#+\s'
31+
32+
33+
head_id = 0
34+
targetname = "../api/xarm_api.md"
35+
with open(targetname, 'w+') as f2:
36+
for i in docs:
37+
if not re.match(pattern, i.strip(' \t\n')):
38+
continue
39+
i = i.strip(' \t\n')
40+
head = i.split(' ')[0]
41+
f2.write('|' + '-----' * (len(head) - 1) + '@[' + i[len(head):].strip(' \t\n') + '](#id' + str(
42+
head_id) + ') \n')
43+
head_id += 1
44+
f2.write('\n')
45+
head_id = 0
46+
for i in docs:
47+
if not re.match(pattern, i.strip(' \t\n')):
48+
f2.write(i)
49+
else:
50+
i = i.strip(' \t\n')
51+
head = i.split(' ')[0]
52+
if head in d.keys():
53+
menu = ''.join(
54+
['<h', str(len(head)), ' id=id', str(head_id), '>', i[len(head):].strip(' \t\n'), '</h',
55+
str(len(head)), '> \n'])
56+
f2.write(menu)
57+
head_id += 1
2358

2459
print('done ...')
2560

doc/tool/markdown_doc.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def docclass(self, cls, name=None, mod=None):
9898

9999
if descriptors:
100100
# start the descriptors section
101-
document.append(self.process_subsection(self.bold("descriptors")))
101+
document.append(self.process_subsection(self.bold("Attributes")))
102102
document.append(self.underline)
103103

104104
# process your descriptors
@@ -108,12 +108,13 @@ def docclass(self, cls, name=None, mod=None):
108108
if methods:
109109
# start the methods section
110110
document.append(self.underline)
111-
document.append(self.process_subsection(self.bold("methods")))
111+
document.append(self.process_subsection(self.bold("Methods")))
112112
document.append(self.underline)
113113

114114
# process your methods
115115
for name, kind, classname, value in methods:
116-
document.append(self.document(getattr(cls, name), name, mod, cls))
116+
if name == '__init__' or not name.startswith('__'):
117+
document.append(self.document(getattr(cls, name), name, mod, cls))
117118

118119
return "\n".join(document)
119120

example/wrapper/common/1001-get_gpio_digital.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
arm.clean_error()
2727

2828
last_digitals = [-1, -1]
29-
while arm.connected and arm.error_code == 0:
29+
while arm.connected and arm.error_code != 28:
3030
code, digitals = arm.get_gpio_digital()
3131
if code == 0:
3232
if digitals[0] == 1 and digitals[0] != last_digitals[0]:

example/wrapper/common/1002-get_gpio_analog.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
if arm.error_code != 0:
2626
arm.clean_error()
2727

28-
last_analogs = [-1, -1]
29-
while arm.connected and arm.error_code == 0:
28+
while arm.connected and arm.error_code != 28:
3029
code, analogs = arm.get_gpio_analog()
3130
print('code: {}, analogs={}'.format(code, analogs))
3231
time.sleep(1)

example/wrapper/tool/blockly_to_python.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import sys
1515
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
1616

17-
from xarm.tools.xml_tool import XmlTool
17+
from xarm.tools.blockly_tool import BlocklyTool
1818

1919
# blockly app path
2020
source_path = './example.xml'
2121
# the path is the python code to save
22-
target_path = './py_blockly.py'
23-
xml = XmlTool(source_path)
24-
xml.to_python(target_path)
22+
target_path = './blockly_app.py'
23+
blockly = BlocklyTool(source_path)
24+
blockly.to_python(target_path)

xarm/core/config/x_config.py

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class SocketConf:
148148

149149
class UxbusReg:
150150
GET_VERSION = 1
151+
SHUTDOWN_SYSTEM = 10
151152
MOTION_EN = 11
152153
SET_STATE = 12
153154
GET_STATE = 13
@@ -163,6 +164,7 @@ class UxbusReg:
163164
MOVE_JOINT = 23
164165
MOVE_HOME = 25
165166
SLEEP_INSTT = 26
167+
MOVE_CIRCLE = 27
166168
MOVE_SERVOJ = 29
167169

168170
SET_TCP_JERK = 31
@@ -183,6 +185,8 @@ class UxbusReg:
183185
IS_JOINT_LIMIT = 45
184186
IS_TCP_LIMIT = 46
185187

188+
SET_GRAVITY_DIR = 51
189+
186190
SERVO_W16B = 101
187191
SERVO_R16B = 102
188192
SERVO_W32B = 103

xarm/core/wrapper/uxbus_cmd.py

+19
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def get_nu16(self, funcode, num):
107107
def get_version(self):
108108
return self.get_nu8(XCONF.UxbusReg.GET_VERSION, 40)
109109

110+
def shutdown_system(self, value):
111+
txdata = [value]
112+
return self.set_nu8(XCONF.UxbusReg.SHUTDOWN_SYSTEM, txdata, 1)
113+
110114
def motion_en(self, axis_id, enable):
111115
txdata = [axis_id, int(enable)]
112116
return self.set_nu8(XCONF.UxbusReg.MOTION_EN, txdata, 2)
@@ -166,6 +170,18 @@ def sleep_instruction(self, sltime):
166170
txdata = [sltime]
167171
return self.set_nfp32(XCONF.UxbusReg.SLEEP_INSTT, txdata, 1)
168172

173+
def move_circle(self, pose1, pose2, mvvelo, mvacc, mvtime, percent):
174+
txdata = [0] * 16
175+
for i in range(6):
176+
txdata[i] = pose1[i]
177+
txdata[6 + i] = pose2[i]
178+
txdata[12] = mvvelo
179+
txdata[13] = mvacc
180+
txdata[14] = mvtime
181+
txdata[15] = percent
182+
ret = self.set_nfp32(XCONF.UxbusReg.MOVE_CIRCLE, txdata, 16)
183+
return ret
184+
169185
def set_tcp_jerk(self, jerk):
170186
txdata = [jerk]
171187
return self.set_nfp32(XCONF.UxbusReg.SET_TCP_JERK, txdata, 1)
@@ -198,6 +214,9 @@ def set_teach_sens(self, value):
198214
txdata = [value]
199215
return self.set_nu8(XCONF.UxbusReg.SET_TEACH_SENS, txdata, 1)
200216

217+
def set_gravity_dir(self, gravity_dir):
218+
return self.set_nfp32(XCONF.UxbusReg.SET_GRAVITY_DIR, gravity_dir, 3)
219+
201220
def clean_conf(self):
202221
return self.set_nu8(XCONF.UxbusReg.CLEAN_CONF, 0, 0)
203222

0 commit comments

Comments
 (0)