29
29
# POSSIBILITY OF SUCH DAMAGE.
30
30
31
31
import logging , numpy , openravepy , os , tempfile
32
- from ..util import CopyTrajectory , SimplifyTrajectory
33
- from base import BasePlanner , PlanningError , PlanningMethod
32
+ from ..util import CopyTrajectory , SimplifyTrajectory , HasAffineDOFs
33
+ from base import BasePlanner , PlanningError , PlanningMethod , UnsupportedPlanningError
34
34
from openravepy import PlannerStatus
35
35
36
36
@@ -44,6 +44,9 @@ def RetimeTrajectory(self, robot, path, **kw_args):
44
44
RetimeTrajectory = openravepy .planningutils .RetimeTrajectory
45
45
46
46
cspec = path .GetConfigurationSpecification ()
47
+ if HasAffineDOFs (cspec ):
48
+ raise UnsupportedPlanningError ('OpenRAVERetimer does not support paths with affine DOFs' )
49
+
47
50
"""
48
51
group = cspec.GetGroupFromName('joint_values')
49
52
if group.interpolation != 'linear':
@@ -83,3 +86,53 @@ def __init__(self):
83
86
class ParabolicSmoother (OpenRAVERetimer ):
84
87
def __init__ (self ):
85
88
super (ParabolicSmoother , self ).__init__ ('HauserParabolicSmoother' )
89
+
90
+ class OpenRAVEAffineRetimer (BasePlanner ):
91
+
92
+ def __init__ (self ,):
93
+ super (OpenRAVEAffineRetimer , self ).__init__ ()
94
+
95
+ @PlanningMethod
96
+ def RetimeTrajectory (self , robot , path , ** kw_args ):
97
+
98
+ RetimeTrajectory = openravepy .planningutils .RetimeAffineTrajectory
99
+
100
+ cspec = path .GetConfigurationSpecification ()
101
+
102
+ # Check for anything other than affine dofs in the traj
103
+ # TODO: Better way to do this?
104
+ affine_groups = ['affine_transform' ,
105
+ 'affine_velocities' ,
106
+ 'affine_accelerations' ]
107
+
108
+ for group in cspec .GetGroups ():
109
+ found = False
110
+ for group_name in affine_groups :
111
+ if group_name in group .name : # group.name contains more stuff than just the name
112
+ found = True
113
+ break
114
+
115
+ if not found :
116
+ raise UnsupportedPlanningError ('OpenRAVEAffineRetimer only supports untimed paths with affine DOFs. Found group: %s' % group .name )
117
+
118
+
119
+
120
+ # Copy the input trajectory into the planning environment. This is
121
+ # necessary for two reasons: (1) the input trajectory may be in another
122
+ # environment and/or (2) the retimer modifies the trajectory in-place.
123
+ output_traj = CopyTrajectory (path , env = self .env )
124
+
125
+ # Compute the timing. This happens in-place.
126
+ max_velocities = [robot .GetAffineTranslationMaxVels ()[0 ],
127
+ robot .GetAffineTranslationMaxVels ()[1 ],
128
+ robot .GetAffineRotationAxisMaxVels ()[2 ]]
129
+ max_accelerations = [3. * v for v in max_velocities ]
130
+ status = RetimeTrajectory (output_traj , max_velocities , max_accelerations ,
131
+ False )
132
+
133
+ if status not in [ PlannerStatus .HasSolution ,
134
+ PlannerStatus .InterruptedWithSolution ]:
135
+ raise PlanningError ('Retimer returned with status {0:s}.' .format (
136
+ str (status )))
137
+
138
+ return output_traj
0 commit comments