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