15
15
# - Neither the name of Carnegie Mellon University nor the names of its
16
16
# contributors may be used to endorse or promote products derived from this
17
17
# software without specific prior written permission.
18
- #
18
+ #
19
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
28
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
29
# POSSIBILITY OF SUCH DAMAGE.
30
30
31
- import numpy , openravepy
31
+ import numpy
32
+ import openravepy
32
33
from ..util import SetTrajectoryTags
33
34
from base import (BasePlanner , PlanningError , UnsupportedPlanningError ,
34
35
PlanningMethod , Tags )
35
- import prpy .kin , prpy .tsr
36
+ import prpy .kin
37
+ import prpy .tsr
36
38
37
39
38
40
class CBiRRTPlanner (BasePlanner ):
@@ -112,21 +114,21 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
112
114
H_world_ee = manip .GetEndEffectorTransform ()
113
115
114
116
# 'object frame w' is at ee, z pointed along direction to move
115
- H_world_w = prpy .kin .H_from_op_diff (H_world_ee [0 :3 ,3 ], direction )
117
+ H_world_w = prpy .kin .H_from_op_diff (H_world_ee [0 :3 , 3 ], direction )
116
118
H_w_ee = numpy .dot (prpy .kin .invert_H (H_world_w ), H_world_ee )
117
119
118
120
# Serialize TSR string (goal)
119
121
Hw_end = numpy .eye (4 )
120
- Hw_end [2 ,3 ] = distance
121
-
122
- goaltsr = prpy .tsr .tsr .TSR (T0_w = numpy .dot (H_world_w ,Hw_end ),
123
- Tw_e = H_w_ee ,
124
- Bw = numpy .zeros ((6 ,2 )),
125
- manip = robot .GetActiveManipulatorIndex ())
126
- goal_tsr_chain = prpy .tsr .tsr .TSRChain (sample_goal = True ,
127
- TSRs = [goaltsr ])
122
+ Hw_end [2 , 3 ] = distance
123
+
124
+ goaltsr = prpy .tsr .tsr .TSR (T0_w = numpy .dot (H_world_w , Hw_end ),
125
+ Tw_e = H_w_ee ,
126
+ Bw = numpy .zeros ((6 , 2 )),
127
+ manip = robot .GetActiveManipulatorIndex ())
128
+ goal_tsr_chain = prpy .tsr .tsr .TSRChain (sample_goal = True ,
129
+ TSRs = [goaltsr ])
128
130
# Serialize TSR string (whole-trajectory constraint)
129
- Bw = numpy .zeros ((6 ,2 ))
131
+ Bw = numpy .zeros ((6 , 2 ))
130
132
epsilon = 0.001
131
133
Bw = numpy .array ([[- epsilon , epsilon ],
132
134
[- epsilon , epsilon ],
@@ -135,15 +137,16 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
135
137
[- epsilon , epsilon ],
136
138
[- epsilon , epsilon ]])
137
139
138
- trajtsr = prpy .tsr .tsr .TSR (T0_w = H_world_w ,
139
- Tw_e = H_w_ee ,
140
- Bw = Bw ,
141
- manip = robot . GetActiveManipulatorIndex ())
142
- traj_tsr_chain = prpy . tsr . tsr . TSRChain ( constrain = True , TSRs = [trajtsr ])
140
+ traj_tsr = prpy .tsr .tsr .TSR (
141
+ T0_w = H_world_w , Tw_e = H_w_ee , Bw = Bw ,
142
+ manip = robot . GetActiveManipulatorIndex ())
143
+ traj_tsr_chain = prpy . tsr . tsr . TSRChain ( constrain = True ,
144
+ TSRs = [traj_tsr ])
143
145
144
146
kw_args .setdefault ('psample' , 0.1 )
145
147
146
- return self .Plan (robot ,
148
+ return self .Plan (
149
+ robot ,
147
150
tsr_chains = [goal_tsr_chain , traj_tsr_chain ],
148
151
# Smooth since this is a constrained trajectory.
149
152
smoothingitrs = smoothingitrs ,
@@ -162,7 +165,6 @@ def PlanToTSR(self, robot, tsr_chains, smoothingitrs=100, **kw_args):
162
165
@param smoothingitrs number of smoothing iterations to run
163
166
@return traj output path
164
167
"""
165
- psample = None
166
168
is_constrained = False
167
169
168
170
for chain in tsr_chains :
@@ -176,7 +178,8 @@ def PlanToTSR(self, robot, tsr_chains, smoothingitrs=100, **kw_args):
176
178
if not is_constrained :
177
179
smoothingitrs = 0
178
180
179
- return self .Plan (robot ,
181
+ return self .Plan (
182
+ robot ,
180
183
smoothingitrs = smoothingitrs ,
181
184
tsr_chains = tsr_chains ,
182
185
** kw_args
@@ -187,41 +190,42 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
187
190
extra_args = None , ** kw_args ):
188
191
from openravepy import CollisionOptions , CollisionOptionsStateSaver
189
192
190
- # TODO We may need this work-around because CBiRRT doesn't like it when
191
- # an IK solver other than GeneralIK is loaded (e.g. nlopt_ik).
192
- #self.ClearIkSolver(robot.GetActiveManipulator())
193
+ # TODO We may need this work-around because CBiRRT doesn't like it
194
+ # when an IK solver other than GeneralIK is loaded (e.g. nlopt_ik).
195
+ # self.ClearIkSolver(robot.GetActiveManipulator())
193
196
194
197
self .env .LoadProblem (self .problem , robot .GetName ())
195
198
196
- args = [ 'RunCBiRRT' ]
199
+ args = ['RunCBiRRT' ]
197
200
198
201
if extra_args is not None :
199
202
args += extra_args
200
203
201
204
if smoothingitrs is not None :
202
205
if smoothingitrs < 0 :
203
- raise ValueError ('Invalid number of smoothing iterations. Value '
204
- 'must be non-negative; got {:d}.' . format (
205
- smoothingitrs ))
206
+ raise ValueError ('Invalid number of smoothing iterations. '
207
+ 'Value must be non-negative; got {:d}.'
208
+ . format ( smoothingitrs ))
206
209
207
- args += [ 'smoothingitrs' , str (smoothingitrs ) ]
210
+ args += ['smoothingitrs' , str (smoothingitrs )]
208
211
209
212
if timelimit is not None :
210
213
if not (timelimit > 0 ):
211
214
raise ValueError ('Invalid value for "timelimit". Limit must be'
212
215
' non-negative; got {:f}.' .format (timelimit ))
213
216
214
- args += [ 'timelimit' , str (timelimit ) ]
217
+ args += ['timelimit' , str (timelimit )]
215
218
216
219
if allowlimadj is not None :
217
- args += [ 'allowlimadj' , str (int (allowlimadj )) ]
220
+ args += ['allowlimadj' , str (int (allowlimadj ))]
218
221
219
222
if psample is not None :
220
223
if not (0 <= psample <= 1 ):
221
- raise ValueError ('Invalid value for "psample". Value must be in'
222
- ' the range [0, 1]; got {:f}.' .format (psample ))
224
+ raise ValueError ('Invalid value for "psample". Value must be '
225
+ 'in the range [0, 1]; got {:f}.'
226
+ .format (psample ))
223
227
224
- args += [ 'psample' , str (psample ) ]
228
+ args += ['psample' , str (psample )]
225
229
226
230
if jointstarts is not None :
227
231
for start_config in jointstarts :
@@ -233,7 +237,8 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
233
237
)
234
238
)
235
239
236
- args += ['jointstarts' ] + self .serialize_dof_values (start_config )
240
+ args += (['jointstarts' ] +
241
+ self .serialize_dof_values (start_config ))
237
242
238
243
if jointgoals is not None :
239
244
for goal_config in jointgoals :
@@ -254,7 +259,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
254
259
# FIXME: Why can't we write to anything other than cmovetraj.txt or
255
260
# /tmp/cmovetraj.txt with CBiRRT?
256
261
traj_path = 'cmovetraj.txt'
257
- args += [ 'filename' , traj_path ]
262
+ args += ['filename' , traj_path ]
258
263
args_str = ' ' .join (args )
259
264
260
265
with CollisionOptionsStateSaver (self .env .GetCollisionChecker (),
@@ -267,12 +272,13 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
267
272
# Construct the output trajectory.
268
273
with open (traj_path , 'rb' ) as traj_file :
269
274
traj_xml = traj_file .read ()
270
- traj = openravepy .RaveCreateTrajectory (self .env , 'GenericTrajectory' )
275
+ traj = openravepy .RaveCreateTrajectory (
276
+ self .env , 'GenericTrajectory' )
271
277
traj .deserialize (traj_xml )
272
278
273
279
# Tag the trajectory as constrained if a constraint TSR is present.
274
- if (tsr_chains is not None
275
- and any (tsr_chain .constrain for tsr_chain in tsr_chains )):
280
+ if (tsr_chains is not None and
281
+ any (tsr_chain .constrain for tsr_chain in tsr_chains )):
276
282
SetTrajectoryTags (traj , {Tags .CONSTRAINED : True }, append = True )
277
283
278
284
# Strip extraneous groups from the output trajectory.
@@ -289,11 +295,10 @@ def ClearIkSolver(self, manip):
289
295
if manip .GetIkSolver () is not None :
290
296
raise ValueError ('Unable to clear IkSolver' )
291
297
292
-
293
298
@staticmethod
294
299
def serialize_dof_values (dof_values ):
295
- return [ str (len (dof_values )),
296
- ' ' .join ([ str (x ) for x in dof_values ]) ]
300
+ return [str (len (dof_values )),
301
+ ' ' .join ([str (x ) for x in dof_values ])]
297
302
298
303
299
304
def SerializeTransform12Col (tm , format = '%.5f' ):
0 commit comments