Skip to content

Commit 56189a8

Browse files
committed
fix: fixes #76, adding more error checking and unifying calculation returns
1 parent 656f3a4 commit 56189a8

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

evasdk/eva_http_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,15 @@ def control_acknowledge_collision(self, wait_for_ready=True):
447447
self.control_wait_for(RobotState.READY)
448448

449449
# CALCULATIONS
450-
def calc_forward_kinematics(self, joints, fk_type='both', tcp_config=None):
450+
def __check_calculation(self, r, name, kind):
451+
if res[kind]['result'] != 'success':
452+
eva_error(f'{name} error: {res[kind]['error']}')
453+
return res[kind]
454+
455+
def calc_forward_kinematics(self, joints, fk_type=None, tcp_config=None):
456+
if fk_type is not None:
457+
self.__logger.warn('deprecated fk_type keyword, now all FK data is being returned')
458+
451459
body = {'joints': joints}
452460
if tcp_config is not None:
453461
body['tcp_config'] = tcp_config
@@ -456,13 +464,7 @@ def calc_forward_kinematics(self, joints, fk_type='both', tcp_config=None):
456464

457465
if r.status_code != 200:
458466
eva_error('calc_forward_kinematics error', r)
459-
460-
if (fk_type == 'position') or (fk_type == 'orientation'):
461-
return r.json()['fk'][fk_type]
462-
elif (fk_type == 'both'):
463-
return r.json()['fk']
464-
else:
465-
eva_error('calc_forward_kinematics invalid fk_type {}'.format(fk_type), r)
467+
return self.__check_calculation(r, 'calc_forward_kinematics', 'fk')
466468

467469
def __ensure_pyt3d(self):
468470
if not has_pyt3d:
@@ -523,8 +525,7 @@ def calc_inverse_kinematics(self, guess, target_position, target_orientation, tc
523525

524526
if r.status_code != 200:
525527
eva_error('inverse_kinematics error', r)
526-
return r.json()
527-
528+
return self.__check_calculation(r, 'calc_inverse_kinematics', 'ik')['joints']
528529

529530
def calc_nudge(self, joints, direction, offset, tcp_config=None):
530531
body = {'joints': joints, 'direction': direction, 'offset': offset}
@@ -535,8 +536,7 @@ def calc_nudge(self, joints, direction, offset, tcp_config=None):
535536

536537
if r.status_code != 200:
537538
eva_error('calc_nudge error', r)
538-
return r.json()['nudge']['joints']
539-
539+
return self.__check_calculation(r, 'calc_nudge', 'nudge')['joints']
540540

541541
def calc_pose_valid(self, joints, tcp_config=None):
542542
body = {'joints': joints}
@@ -559,4 +559,4 @@ def calc_rotate(self, joints, axis, offset, tcp_config=None):
559559

560560
if r.status_code != 200:
561561
eva_error('calc_rotate error', r)
562-
return r.json()
562+
return self.__check_calculation(r, 'calc_rotate', 'rotate')['joints']

0 commit comments

Comments
 (0)