Skip to content

Commit 32ea050

Browse files
authored
fix: fixes #76, adding more error checking and unifying calculation returns (#86)
1 parent 4ecbc82 commit 32ea050

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

evasdk/eva_http_client.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,16 @@ 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+
res = r.json()
452+
if res[kind]['result'] != 'success':
453+
eva_error(f'{name} error: {res[kind]["error"]}')
454+
return res[kind]
455+
456+
def calc_forward_kinematics(self, joints, fk_type=None, tcp_config=None):
457+
if fk_type is not None:
458+
self.__logger.warn('deprecated fk_type keyword, now all FK data is being returned')
459+
451460
body = {'joints': joints}
452461
if tcp_config is not None:
453462
body['tcp_config'] = tcp_config
@@ -456,13 +465,7 @@ def calc_forward_kinematics(self, joints, fk_type='both', tcp_config=None):
456465

457466
if r.status_code != 200:
458467
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)
468+
return self.__check_calculation(r, 'calc_forward_kinematics', 'fk')
466469

467470
def __ensure_pyt3d(self):
468471
if not has_pyt3d:
@@ -523,8 +526,7 @@ def calc_inverse_kinematics(self, guess, target_position, target_orientation, tc
523526

524527
if r.status_code != 200:
525528
eva_error('inverse_kinematics error', r)
526-
return r.json()
527-
529+
return self.__check_calculation(r, 'calc_inverse_kinematics', 'ik')['joints']
528530

529531
def calc_nudge(self, joints, direction, offset, tcp_config=None):
530532
body = {'joints': joints, 'direction': direction, 'offset': offset}
@@ -535,8 +537,7 @@ def calc_nudge(self, joints, direction, offset, tcp_config=None):
535537

536538
if r.status_code != 200:
537539
eva_error('calc_nudge error', r)
538-
return r.json()['nudge']['joints']
539-
540+
return self.__check_calculation(r, 'calc_nudge', 'nudge')['joints']
540541

541542
def calc_pose_valid(self, joints, tcp_config=None):
542543
body = {'joints': joints}
@@ -559,4 +560,4 @@ def calc_rotate(self, joints, axis, offset, tcp_config=None):
559560

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

0 commit comments

Comments
 (0)