1515# - Neither the name of Carnegie Mellon University nor the names of its
1616# contributors may be used to endorse or promote products derived from this
1717# software without specific prior written permission.
18- #
18+ #
1919# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2020# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2121# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2828# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929# POSSIBILITY OF SUCH DAMAGE.
3030
31- import numpy , openravepy
31+ import numpy
32+ import openravepy
3233from ..util import SetTrajectoryTags
3334from base import (BasePlanner , PlanningError , UnsupportedPlanningError ,
3435 PlanningMethod , Tags )
35- import prpy .kin , prpy .tsr
36+ import prpy .kin
37+ import prpy .tsr
3638
3739
3840class CBiRRTPlanner (BasePlanner ):
@@ -112,21 +114,21 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
112114 H_world_ee = manip .GetEndEffectorTransform ()
113115
114116 # '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 )
116118 H_w_ee = numpy .dot (prpy .kin .invert_H (H_world_w ), H_world_ee )
117119
118120 # Serialize TSR string (goal)
119121 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 ])
128130 # Serialize TSR string (whole-trajectory constraint)
129- Bw = numpy .zeros ((6 ,2 ))
131+ Bw = numpy .zeros ((6 , 2 ))
130132 epsilon = 0.001
131133 Bw = numpy .array ([[- epsilon , epsilon ],
132134 [- epsilon , epsilon ],
@@ -135,15 +137,16 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
135137 [- epsilon , epsilon ],
136138 [- epsilon , epsilon ]])
137139
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 ])
143145
144146 kw_args .setdefault ('psample' , 0.1 )
145147
146- return self .Plan (robot ,
148+ return self .Plan (
149+ robot ,
147150 tsr_chains = [goal_tsr_chain , traj_tsr_chain ],
148151 # Smooth since this is a constrained trajectory.
149152 smoothingitrs = smoothingitrs ,
@@ -162,7 +165,6 @@ def PlanToTSR(self, robot, tsr_chains, smoothingitrs=100, **kw_args):
162165 @param smoothingitrs number of smoothing iterations to run
163166 @return traj output path
164167 """
165- psample = None
166168 is_constrained = False
167169
168170 for chain in tsr_chains :
@@ -176,7 +178,8 @@ def PlanToTSR(self, robot, tsr_chains, smoothingitrs=100, **kw_args):
176178 if not is_constrained :
177179 smoothingitrs = 0
178180
179- return self .Plan (robot ,
181+ return self .Plan (
182+ robot ,
180183 smoothingitrs = smoothingitrs ,
181184 tsr_chains = tsr_chains ,
182185 ** kw_args
@@ -187,41 +190,42 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
187190 extra_args = None , ** kw_args ):
188191 from openravepy import CollisionOptions , CollisionOptionsStateSaver
189192
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())
193196
194197 self .env .LoadProblem (self .problem , robot .GetName ())
195198
196- args = [ 'RunCBiRRT' ]
199+ args = ['RunCBiRRT' ]
197200
198201 if extra_args is not None :
199202 args += extra_args
200203
201204 if smoothingitrs is not None :
202205 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 ))
206209
207- args += [ 'smoothingitrs' , str (smoothingitrs ) ]
210+ args += ['smoothingitrs' , str (smoothingitrs )]
208211
209212 if timelimit is not None :
210213 if not (timelimit > 0 ):
211214 raise ValueError ('Invalid value for "timelimit". Limit must be'
212215 ' non-negative; got {:f}.' .format (timelimit ))
213216
214- args += [ 'timelimit' , str (timelimit ) ]
217+ args += ['timelimit' , str (timelimit )]
215218
216219 if allowlimadj is not None :
217- args += [ 'allowlimadj' , str (int (allowlimadj )) ]
220+ args += ['allowlimadj' , str (int (allowlimadj ))]
218221
219222 if psample is not None :
220223 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 ))
223227
224- args += [ 'psample' , str (psample ) ]
228+ args += ['psample' , str (psample )]
225229
226230 if jointstarts is not None :
227231 for start_config in jointstarts :
@@ -233,7 +237,8 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
233237 )
234238 )
235239
236- args += ['jointstarts' ] + self .serialize_dof_values (start_config )
240+ args += (['jointstarts' ] +
241+ self .serialize_dof_values (start_config ))
237242
238243 if jointgoals is not None :
239244 for goal_config in jointgoals :
@@ -254,7 +259,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
254259 # FIXME: Why can't we write to anything other than cmovetraj.txt or
255260 # /tmp/cmovetraj.txt with CBiRRT?
256261 traj_path = 'cmovetraj.txt'
257- args += [ 'filename' , traj_path ]
262+ args += ['filename' , traj_path ]
258263 args_str = ' ' .join (args )
259264
260265 with CollisionOptionsStateSaver (self .env .GetCollisionChecker (),
@@ -267,12 +272,13 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
267272 # Construct the output trajectory.
268273 with open (traj_path , 'rb' ) as traj_file :
269274 traj_xml = traj_file .read ()
270- traj = openravepy .RaveCreateTrajectory (self .env , 'GenericTrajectory' )
275+ traj = openravepy .RaveCreateTrajectory (
276+ self .env , 'GenericTrajectory' )
271277 traj .deserialize (traj_xml )
272278
273279 # 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 )):
276282 SetTrajectoryTags (traj , {Tags .CONSTRAINED : True }, append = True )
277283
278284 # Strip extraneous groups from the output trajectory.
@@ -289,11 +295,10 @@ def ClearIkSolver(self, manip):
289295 if manip .GetIkSolver () is not None :
290296 raise ValueError ('Unable to clear IkSolver' )
291297
292-
293298 @staticmethod
294299 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 ])]
297302
298303
299304def SerializeTransform12Col (tm , format = '%.5f' ):
0 commit comments