Skip to content

fix: fixes #76, adding more error checking and unifying calculation returns #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions evasdk/eva_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,16 @@ def control_acknowledge_collision(self, wait_for_ready=True):
self.control_wait_for(RobotState.READY)

# CALCULATIONS
def calc_forward_kinematics(self, joints, fk_type='both', tcp_config=None):
def __check_calculation(self, r, name, kind):
res = r.json()
if res[kind]['result'] != 'success':
eva_error(f'{name} error: {res[kind]["error"]}')
return res[kind]

def calc_forward_kinematics(self, joints, fk_type=None, tcp_config=None):
if fk_type is not None:
self.__logger.warn('deprecated fk_type keyword, now all FK data is being returned')

body = {'joints': joints}
if tcp_config is not None:
body['tcp_config'] = tcp_config
Expand All @@ -456,13 +465,7 @@ def calc_forward_kinematics(self, joints, fk_type='both', tcp_config=None):

if r.status_code != 200:
eva_error('calc_forward_kinematics error', r)

if (fk_type == 'position') or (fk_type == 'orientation'):
return r.json()['fk'][fk_type]
elif (fk_type == 'both'):
return r.json()['fk']
else:
eva_error('calc_forward_kinematics invalid fk_type {}'.format(fk_type), r)
return self.__check_calculation(r, 'calc_forward_kinematics', 'fk')

def __ensure_pyt3d(self):
if not has_pyt3d:
Expand Down Expand Up @@ -523,8 +526,7 @@ def calc_inverse_kinematics(self, guess, target_position, target_orientation, tc

if r.status_code != 200:
eva_error('inverse_kinematics error', r)
return r.json()

return self.__check_calculation(r, 'calc_inverse_kinematics', 'ik')['joints']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this 'calc_inverse_kinematics' and similar 'calc_forward_kinematics', 'calc_nudge' and 'calc_rotate' could use <function>.__name__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this?

return self.__check_calculation(r, self.calc_inverse_kinematics.__name__, 'ik')['joints']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant like that yea, but now you typed it out seems a bit much ado about nothing... lol. Maybe enum would be nicer 🤷‍♂️. But I don't think this is important


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

if r.status_code != 200:
eva_error('calc_nudge error', r)
return r.json()['nudge']['joints']

return self.__check_calculation(r, 'calc_nudge', 'nudge')['joints']

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

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