Skip to content

Commit e5f699a

Browse files
committed
[feat] add set_external_device_monitor_params/get_external_device_monitor_params
1. add `set_external_device_monitor_params`/`get_external_device_monitor_params` 2. fix core.set_modbus_baudrate 3. remove pretty_print 4. fix move_servo_cartesian_aa
1 parent 908662a commit e5f699a

8 files changed

Lines changed: 153 additions & 68 deletions

File tree

doc/api/xarm_api.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
xArm-Python-SDK API Documentation (V1.17.2): class XArmAPI in module xarm.wrapper.xarm_api
1+
xArm-Python-SDK API Documentation (V1.17.3): class XArmAPI in module xarm.wrapper.xarm_api
22

33
## class __XArmAPI__
44
****************************************
@@ -527,6 +527,13 @@ xArm-Python-SDK API Documentation (V1.17.2): class XArmAPI in module xarm.wrappe
527527

528528
#### def __get_external_device_monitor_params__(self):
529529

530+
> Get the monitor params of the external device
531+
> Note:
532+
>     1. only available if firmware_version >= 2.7.110
533+
>
534+
> :return: tuple((code, params)), only when code is 0, the returned result is correct.
535+
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
536+
>     params: [dev_type, frequency]
530537
531538

532539
#### def __get_fdb_mat_history_num__(self):
@@ -2368,6 +2375,23 @@ xArm-Python-SDK API Documentation (V1.17.2): class XArmAPI in module xarm.wrappe
23682375

23692376
#### def __set_external_device_monitor_params__(self, dev_type, frequency):
23702377

2378+
> Set the monitor params of the external device
2379+
> Note:
2380+
>     1. only available if firmware_version >= 2.7.110
2381+
>     2. after it is turned on, the position/speed/current information of the external device will be reported through port 30000
2382+
>     3. once an error occurs, you need to restart to monitor
2383+
>
2384+
> :param dev_type: the type of the external device
2385+
>     0: Turn off monitoring
2386+
>     1: xArm Gripper
2387+
>     2: xArm Gripper G2
2388+
>     3: BIO Gripper G2
2389+
>     4: Robotiq 2F-85
2390+
>     5: Robotiq 2F-140
2391+
> :param frequency: the frequency of communication with the external device
2392+
>
2393+
> :return code
2394+
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
23712395
23722396

23732397
#### def __set_fdb_mat_history_num__(self, num):

xarm/core/utils/log.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def __new__(cls, *args, **kwargs):
8888
'light_cyan': '\033[96m{}\033[0m',
8989
}
9090

91+
origin_logger = logging.getLogger("origin.print")
92+
origin_logger.handlers.clear()
93+
stream_handler = logging.StreamHandler(sys.stdout)
94+
stream_handler.setLevel(logging.INFO)
95+
origin_logger.addHandler(stream_handler)
96+
origin_logger.setLevel(logging.INFO)
97+
9198

9299
def pretty_print(*args, sep=' ', end='\n', file=None, color='none'):
93100
msg = ''

xarm/core/wrapper/uxbus_cmd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,10 @@ def move_line_aa(self, mvpose, mvvelo, mvacc, mvtime, mvcoord, relative, only_ch
439439

440440
def move_servo_cart_aa(self, mvpose, mvvelo, mvacc, tool_coord, relative):
441441
float_data = [mvpose[i] for i in range(6)]
442-
float_data += [mvvelo, mvacc, tool_coord]
443-
byte_data = bytes([relative])
444-
return self.set_nfp32_with_bytes(XCONF.UxbusReg.MOVE_SERVO_CART_AA, float_data, 9, byte_data)
442+
float_data += [mvvelo, mvacc]
443+
byte_data = convert.int32_to_bytes(tool_coord)
444+
byte_data += bytes([relative])
445+
return self.set_nfp32_with_bytes(XCONF.UxbusReg.MOVE_SERVO_CART_AA, float_data, 8, byte_data)
445446

446447
def move_relative(self, pose, mvvelo, mvacc, mvtime, radius, is_joint_motion=False, is_angle_axis=False, only_check_type=0, motion_type=0, feedback_key=None):
447448
float_data = [0] * 7

xarm/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.17.2'
1+
__version__ = '1.17.3'

xarm/wrapper/xarm_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4549,9 +4549,37 @@ def get_ft_admittance_ctrl_threshold(self):
45494549
return self._arm.get_ft_admittance_ctrl_threshold()
45504550

45514551
def set_external_device_monitor_params(self, dev_type, frequency):
4552+
"""
4553+
Set the monitor params of the external device
4554+
Note:
4555+
1. only available if firmware_version >= 2.7.110
4556+
2. after it is turned on, the position/speed/current information of the external device will be reported through port 30000
4557+
3. once an error occurs, you need to restart to monitor
4558+
4559+
:param dev_type: the type of the external device
4560+
0: Turn off monitoring
4561+
1: xArm Gripper
4562+
2: xArm Gripper G2
4563+
3: BIO Gripper G2
4564+
4: Robotiq 2F-85
4565+
5: Robotiq 2F-140
4566+
:param frequency: the frequency of communication with the external device
4567+
4568+
:return code
4569+
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
4570+
"""
45524571
return self._arm.set_external_device_monitor_params(dev_type, frequency)
45534572

45544573
def get_external_device_monitor_params(self):
4574+
"""
4575+
Get the monitor params of the external device
4576+
Note:
4577+
1. only available if firmware_version >= 2.7.110
4578+
4579+
:return: tuple((code, params)), only when code is 0, the returned result is correct.
4580+
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
4581+
params: [dev_type, frequency]
4582+
"""
45554583
return self._arm.get_external_device_monitor_params()
45564584

45574585
############################ OLD API #############################

xarm/x3/base.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
except:
3939
SerialPort = None
4040
from ..core.wrapper import UxbusCmdSer, UxbusCmdTcp
41-
from ..core.utils.log import logger, pretty_print
41+
from ..core.utils.log import logger, origin_logger
4242
from ..core.utils import convert, crc16
4343
from ..core.config.x_code import ControllerWarn, ControllerError, ControllerErrorCodeMap, ControllerWarnCodeMap
4444
from .utils import compare_time, compare_version, filter_invaild_number
@@ -1053,7 +1053,7 @@ def _core_set_modbus_baudrate(self, baudrate, use_old=False):
10531053
:return [code, ...]
10541054
"""
10551055
if not use_old:
1056-
ret = self.set_tgpio_modbus_baudrate(baudrate)
1056+
ret = self.set_rs485_baudrate(baudrate)
10571057
return [ret, self.tgpio_modbus_baud]
10581058
else:
10591059
return self.arm_cmd.set_modbus_baudrate_old(baudrate)
@@ -1085,7 +1085,7 @@ def disconnect(self):
10851085
pass
10861086
self._report_connect_changed_callback(False, False)
10871087
with self._pause_cond:
1088-
self._pause_cond.notifyAll()
1088+
self._pause_cond.notify_all() if hasattr(self._pause_cond, 'notify_all') else self._pause_cond.notifyAll()
10891089
self._clean_thread()
10901090

10911091
def set_timeout(self, timeout):
@@ -1304,7 +1304,7 @@ def _report_thread_handle(self):
13041304
time.sleep(0.001)
13051305
if self._pause_cnts > 0:
13061306
with self._pause_cond:
1307-
self._pause_cond.notifyAll()
1307+
self._pause_cond.notify_all() if hasattr(self._pause_cond, 'notify_all') else self._pause_cond.notifyAll()
13081308
self.disconnect()
13091309

13101310
def _handle_report_data(self, data):
@@ -1324,15 +1324,15 @@ def __handle_report_normal_old(rx_data):
13241324
if error_code != self._error_code:
13251325
self._error_code = error_code
13261326
if self._error_code != 0:
1327-
pretty_print('Error, code: {}'.format(self._error_code), color='red')
1327+
origin_logger.error('Errorcode: {}'.format(self._error_code))
13281328
else:
1329-
pretty_print('Error had clean', color='blue')
1329+
origin_logger.info('Error had clean')
13301330
if warn_code != self._warn_code:
13311331
self._warn_code = warn_code
13321332
if self._warn_code != 0:
1333-
pretty_print('Warn, code: {}'.format(self._warn_code), color='yellow')
1333+
origin_logger.warning('Warn, code: {}'.format(self._warn_code))
13341334
else:
1335-
pretty_print('Warnning had clean', color='blue')
1335+
origin_logger.info('Warnning had clean')
13361336
self._report_error_warn_changed_callback()
13371337
logger.info('OnReport -> err={}, warn={}, state={}, cmdnum={}, mtbrake={}, mtable={}'.format(
13381338
error_code, warn_code, state, cmd_num, mtbrake, mtable
@@ -1361,11 +1361,11 @@ def __handle_report_normal_old(rx_data):
13611361
if not self._is_first_report:
13621362
if state in [4, 5] or not all([bool(item[0] & item[1]) for item in zip(mtbrake, mtable)][:self.axis]):
13631363
# if self._is_ready:
1364-
# pretty_print('[report], xArm is not ready to move', color='red')
1364+
# origin_logger.info('[report], xArm is not ready to move')
13651365
self._is_ready = False
13661366
else:
13671367
# if not self._is_ready:
1368-
# pretty_print('[report], xArm is ready to move', color='green')
1368+
# origin_logger.info('[report], xArm is ready to move')
13691369
self._is_ready = True
13701370
else:
13711371
self._is_ready = False
@@ -1417,7 +1417,7 @@ def __handle_report_normal_old(rx_data):
14171417
self._state = state
14181418
if self.state != 3 and (_state == 3 or self._pause_cnts > 0):
14191419
with self._pause_cond:
1420-
self._pause_cond.notifyAll()
1420+
self._pause_cond.notify_all() if hasattr(self._pause_cond, 'notify_all') else self._pause_cond.notifyAll()
14211421
self._cmd_num = cmd_num
14221422
self._arm_motor_brake_states = mtbrake
14231423
self._arm_motor_enable_states = mtable
@@ -1630,15 +1630,15 @@ def __handle_report_normal(rx_data):
16301630
if error_code != self._error_code:
16311631
self._error_code = error_code
16321632
if self._error_code != 0:
1633-
pretty_print('ControllerError, code: {}'.format(self._error_code), color='red')
1633+
origin_logger.error('ControllerError, code: {}'.format(self._error_code))
16341634
else:
1635-
pretty_print('ControllerError had clean', color='blue')
1635+
origin_logger.info('ControllerError had clean')
16361636
if warn_code != self._warn_code:
16371637
self._warn_code = warn_code
16381638
if self._warn_code != 0:
1639-
pretty_print('ControllerWarning, code: {}'.format(self._warn_code), color='yellow')
1639+
origin_logger.warning('ControllerWarning, code: {}'.format(self._warn_code))
16401640
else:
1641-
pretty_print('ControllerWarning had clean', color='blue')
1641+
origin_logger.info('ControllerWarning had clean')
16421642
self._report_error_warn_changed_callback()
16431643
logger.info('OnReport -> err={}, warn={}, state={}, cmdnum={}, mtbrake={}, mtable={}, mode={}'.format(
16441644
error_code, warn_code, state, cmd_num, mtbrake, mtable, mode
@@ -1675,11 +1675,11 @@ def __handle_report_normal(rx_data):
16751675
if not self._is_first_report:
16761676
if state in [4, 5] or not all([bool(item[0] & item[1]) for item in zip(mtbrake, mtable)][:self.axis]):
16771677
# if self._is_ready:
1678-
# pretty_print('[report], xArm is not ready to move', color='red')
1678+
# origin_logger.info('[report], xArm is not ready to move')
16791679
self._is_ready = False
16801680
else:
16811681
# if not self._is_ready:
1682-
# pretty_print('[report], xArm is ready to move', color='green')
1682+
# origin_logger.info('[report], xArm is ready to move')
16831683
self._is_ready = True
16841684
else:
16851685
self._is_ready = False
@@ -1694,7 +1694,7 @@ def __handle_report_normal(rx_data):
16941694
self._state = state
16951695
if self.state != 3 and (_state == 3 or self._pause_cnts > 0):
16961696
with self._pause_cond:
1697-
self._pause_cond.notifyAll()
1697+
self._pause_cond.notify_all() if hasattr(self._pause_cond, 'notify_all') else self._pause_cond.notifyAll()
16981698
self._mode = mode
16991699
self._cmd_num = cmd_num
17001700

@@ -1903,19 +1903,19 @@ def _auto_get_report_thread(self):
19031903

19041904
if self.state != 3 and (state == 3 or self._pause_cnts > 0):
19051905
with self._pause_cond:
1906-
self._pause_cond.notifyAll()
1906+
self._pause_cond.notify_all() if hasattr(self._pause_cond, 'notify_all') else self._pause_cond.notifyAll()
19071907
if cmd_num != self._cmd_num:
19081908
self._report_cmdnum_changed_callback()
19091909
if state != self._state:
19101910
self._report_state_changed_callback()
19111911
if state in [4, 5]:
19121912
# if self._is_ready:
1913-
# pretty_print('[report], xArm is not ready to move', color='red')
1913+
# origin_logger.info('[report], xArm is not ready to move')
19141914
self._sleep_finish_time = 0
19151915
self._is_ready = False
19161916
else:
19171917
# if not self._is_ready:
1918-
# pretty_print('[report], xArm is ready to move', color='green')
1918+
# origin_logger.info('[report], xArm is ready to move')
19191919
self._is_ready = True
19201920
if error_code != self._error_code or warn_code != self._warn_code:
19211921
self._report_error_warn_changed_callback()
@@ -2219,15 +2219,15 @@ def set_state(self, state=0):
22192219
self._report_state_changed_callback()
22202220
if self.state != 3 and (_state == 3 or self._pause_cnts > 0):
22212221
with self._pause_cond:
2222-
self._pause_cond.notifyAll()
2222+
self._pause_cond.notify_all() if hasattr(self._pause_cond, 'notify_all') else self._pause_cond.notifyAll()
22232223
if self._state in [4, 5]:
22242224
self._sleep_finish_time = 0
22252225
if self._is_ready:
2226-
pretty_print('[set_state], xArm is not ready to move', color='red')
2226+
origin_logger.info('[set_state], xArm is not ready to move')
22272227
self._is_ready = False
22282228
else:
22292229
if not self._is_ready:
2230-
pretty_print('[set_state], xArm is ready to move', color='green')
2230+
origin_logger.info('[set_state], xArm is ready to move')
22312231
self._is_ready = True
22322232
self.log_api_info('API -> set_state({}) -> code={}, state={}'.format(state, ret[0], self._state), code=ret[0])
22332233
return ret[0]
@@ -2267,25 +2267,23 @@ def get_err_warn_code(self, show=False, lang='en'):
22672267
self._error_code, self._warn_code = ret[1:3]
22682268
self._last_update_err_time = time.monotonic()
22692269
if show:
2270-
pretty_print('************* {}, {}: {} **************'.format(
2270+
origin_logger.info('************* {}, {}: {} **************'.format(
22712271
'获取控制器错误警告码' if lang == 'cn' else 'GetErrorWarnCode',
22722272
'状态' if lang == 'cn' else 'Status',
2273-
ret[0]), color='light_blue')
2273+
ret[0]))
22742274
controller_error = ControllerError(self._error_code, status=0)
22752275
controller_warn = ControllerWarn(self._warn_code, status=0)
2276-
pretty_print('* {}: {}, {}: {}'.format(
2276+
origin_logger.error('* {}: {}, {}: {}'.format(
22772277
'错误码' if lang == 'cn' else 'ErrorCode',
22782278
controller_error.code,
22792279
'信息' if lang == 'cn' else 'Info',
2280-
controller_error.title[lang]),
2281-
color='red' if self._error_code != 0 else 'white')
2282-
pretty_print('* {}: {}, {}: {}'.format(
2280+
controller_error.title[lang]))
2281+
origin_logger.warning('* {}: {}, {}: {}'.format(
22832282
'警告码' if lang == 'cn' else 'WarnCode',
22842283
controller_warn.code,
22852284
'信息' if lang == 'cn' else 'Info',
2286-
controller_warn.title[lang]),
2287-
color='yellow' if self._warn_code != 0 else 'white')
2288-
pretty_print('*' * 50, color='light_blue')
2285+
controller_warn.title[lang]))
2286+
origin_logger.info('*' * 50)
22892287
return ret[0], ret[1:3] if ret[0] == 0 else [self._error_code, self._warn_code]
22902288

22912289
@xarm_is_connected(_type='set')
@@ -2295,11 +2293,11 @@ def clean_error(self):
22952293
if self._state in [4, 5]:
22962294
self._sleep_finish_time = 0
22972295
if self._is_ready:
2298-
pretty_print('[clean_error], xArm is not ready to move', color='red')
2296+
origin_logger.info('[clean_error], xArm is not ready to move')
22992297
self._is_ready = False
23002298
else:
23012299
if not self._is_ready:
2302-
pretty_print('[clean_error], xArm is ready to move', color='green')
2300+
origin_logger.info('[clean_error], xArm is ready to move')
23032301
self._is_ready = True
23042302
self.log_api_info('API -> clean_error -> code={}'.format(ret[0]), code=ret[0])
23052303
return ret[0]
@@ -2325,11 +2323,11 @@ def motion_enable(self, enable=True, servo_id=None):
23252323
if self._state in [4, 5]:
23262324
self._sleep_finish_time = 0
23272325
if self._is_ready:
2328-
pretty_print('[motion_enable], xArm is not ready to move', color='red')
2326+
origin_logger.info('[motion_enable], xArm is not ready to move')
23292327
self._is_ready = False
23302328
else:
23312329
if not self._is_ready:
2332-
pretty_print('[motion_enable], xArm is ready to move', color='green')
2330+
origin_logger.info('[motion_enable], xArm is ready to move')
23332331
self._is_ready = True
23342332
self.log_api_info('API -> motion_enable -> code={}'.format(ret[0]), code=ret[0])
23352333
return ret[0]

0 commit comments

Comments
 (0)