@@ -447,7 +447,16 @@ def control_acknowledge_collision(self, wait_for_ready=True):
447
447
self .control_wait_for (RobotState .READY )
448
448
449
449
# 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
+
451
460
body = {'joints' : joints }
452
461
if tcp_config is not None :
453
462
body ['tcp_config' ] = tcp_config
@@ -456,13 +465,7 @@ def calc_forward_kinematics(self, joints, fk_type='both', tcp_config=None):
456
465
457
466
if r .status_code != 200 :
458
467
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' )
466
469
467
470
def __ensure_pyt3d (self ):
468
471
if not has_pyt3d :
@@ -523,8 +526,7 @@ def calc_inverse_kinematics(self, guess, target_position, target_orientation, tc
523
526
524
527
if r .status_code != 200 :
525
528
eva_error ('inverse_kinematics error' , r )
526
- return r .json ()
527
-
529
+ return self .__check_calculation (r , 'calc_inverse_kinematics' , 'ik' )['joints' ]
528
530
529
531
def calc_nudge (self , joints , direction , offset , tcp_config = None ):
530
532
body = {'joints' : joints , 'direction' : direction , 'offset' : offset }
@@ -535,8 +537,7 @@ def calc_nudge(self, joints, direction, offset, tcp_config=None):
535
537
536
538
if r .status_code != 200 :
537
539
eva_error ('calc_nudge error' , r )
538
- return r .json ()['nudge' ]['joints' ]
539
-
540
+ return self .__check_calculation (r , 'calc_nudge' , 'nudge' )['joints' ]
540
541
541
542
def calc_pose_valid (self , joints , tcp_config = None ):
542
543
body = {'joints' : joints }
@@ -559,4 +560,4 @@ def calc_rotate(self, joints, axis, offset, tcp_config=None):
559
560
560
561
if r .status_code != 200 :
561
562
eva_error ('calc_rotate error' , r )
562
- return r . json ()
563
+ return self . __check_calculation ( r , 'calc_rotate' , 'rotate' )[ 'joints' ]
0 commit comments