@@ -96,17 +96,23 @@ def CreatePlannerParametersString(options, params=None,
96
96
97
97
return lxml .etree .tostring (params_xml )
98
98
99
+ def HasGroup (cspec , group_name ):
100
+ try :
101
+ cspec .GetGroupFromName (group_name )
102
+ return True
103
+ except openravepy .openrave_exception :
104
+ return False
105
+
99
106
def HasAffineDOFs (cspec ):
100
- def has_group (cspec , group_name ):
101
- try :
102
- cspec .GetGroupFromName (group_name )
103
- return True
104
- except openravepy .openrave_exception :
105
- return False
107
+ return (HasGroup (cspec , 'affine_transform' )
108
+ or HasGroup (cspec , 'affine_velocities' )
109
+ or HasGroup (cspec , 'affine_accelerations' ))
106
110
107
- return (has_group (cspec , 'affine_transform' )
108
- or has_group (cspec , 'affine_velocities' )
109
- or has_group (cspec , 'affine_accelerations' ))
111
+ def HasJointDOFs (cspec ):
112
+ return (HasGroup (cspec , 'joint_values' )
113
+ or HasGroup (cspec , 'joint_velocities' )
114
+ or HasGroup (cspec , 'joint_accelerations' )
115
+ or HasGroup (cspec , 'joint_torques' ))
110
116
111
117
def GetTrajectoryIndices (traj ):
112
118
try :
@@ -710,29 +716,56 @@ def IsAtTrajectoryStart(robot, trajectory):
710
716
@returns: True if the robot's active DOFs match the given trajectory
711
717
False if one or more active DOFs differ by DOF resolution
712
718
"""
713
- # Get used indices and starting configuration from trajectory.
714
719
cspec = trajectory .GetConfigurationSpecification ()
715
- dof_indices , _ = cspec .ExtractUsedIndices (robot )
716
- traj_values = cspec .ExtractJointValues (
717
- trajectory .GetWaypoint (0 ), robot , dof_indices )
718
-
719
- # Get current configuration of robot for used indices.
720
- with robot .GetEnv ():
721
- robot_values = robot .GetDOFValues (dof_indices )
722
- dof_resolutions = robot .GetDOFResolutions (dof_indices )
723
-
724
- # Check deviation in each DOF, using OpenRAVE's SubtractValue function.
725
- dof_infos = zip (dof_indices , traj_values , robot_values , dof_resolutions )
726
- for dof_index , traj_value , robot_value , dof_resolution in dof_infos :
727
- # Look up the Joint and Axis of the DOF from the robot.
728
- joint = robot .GetJointFromDOFIndex (dof_index )
729
- axis = dof_index - joint .GetDOFIndex ()
730
-
731
- # If any joint deviates too much, return False.
732
- delta_value = abs (joint .SubtractValue (traj_value , robot_value , axis ))
733
- if delta_value > dof_resolution :
720
+ needs_base = HasAffineDOFs (cspec )
721
+ needs_joints = HasJointDOFs (cspec )
722
+
723
+ if needs_base and needs_joints :
724
+ raise ValueError ('Trajectories with affine and joint DOFs are not supported' )
725
+
726
+ if needs_base :
727
+ doft = openravepy .DOFAffine .X | openravepy .DOFAffine .Y | openravepy .DOFAffine .RotationAxis
728
+ current_pose = openravepy .RaveGetAffineDOFValuesFromTransform (robot .GetTransform (), doft )
729
+ start_transform = numpy .eye (4 )
730
+ start_transform = cspec .ExtractTransform (start_transform , trajectory .GetWaypoint (0 ), robot )
731
+ traj_start = openravepy .RaveGetAffineDOFValuesFromTransform (start_transform , doft )
732
+
733
+ # Compare translation distance
734
+ trans_delta_value = abs (current_pose [:2 ] - traj_start [:2 ])
735
+ trans_resolution = robot .GetAffineTranslationResolution ()[:2 ]
736
+ if trans_delta_value [0 ] > trans_resolution [0 ] or \
737
+ trans_delta_value [1 ] > trans_resolution [1 ]:
738
+ return False
739
+
740
+ # Compare rotation distance
741
+ rot_delta_value = (current_pose [2 ] - traj_start [2 ] + numpy .pi ) % (2. * numpy .pi ) - numpy .pi
742
+ rot_resolution = robot .GetAffineRotationAxisResolution ()[2 ] # Rotation about z?
743
+ if rot_delta_value > rot_resolution :
734
744
return False
735
745
746
+ else :
747
+ # Get used indices and starting configuration from trajectory.
748
+ dof_indices , _ = cspec .ExtractUsedIndices (robot )
749
+ traj_values = cspec .ExtractJointValues (
750
+ trajectory .GetWaypoint (0 ), robot , dof_indices )
751
+
752
+ # Get current configuration of robot for used indices.
753
+ with robot .GetEnv ():
754
+ robot_values = robot .GetDOFValues (dof_indices )
755
+ dof_resolutions = robot .GetDOFResolutions (dof_indices )
756
+
757
+ # Check deviation in each DOF, using OpenRAVE's SubtractValue function.
758
+ dof_infos = zip (dof_indices , traj_values , robot_values , dof_resolutions )
759
+ for dof_index , traj_value , robot_value , dof_resolution in dof_infos :
760
+ # Look up the Joint and Axis of the DOF from the robot.
761
+ joint = robot .GetJointFromDOFIndex (dof_index )
762
+ axis = dof_index - joint .GetDOFIndex ()
763
+
764
+ # If any joint deviates too much, return False.
765
+ delta_value = abs (joint .SubtractValue (traj_value , robot_value , axis ))
766
+ if delta_value > dof_resolution :
767
+ return False
768
+
736
769
# If all joints match, return True.
737
770
return True
738
771
0 commit comments