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 copy , logging , numpy , openravepy , os , tempfile
31
+ import numpy , openravepy
32
32
from ..util import SetTrajectoryTags
33
33
from base import (BasePlanner , PlanningError , UnsupportedPlanningError ,
34
34
PlanningMethod , Tags )
35
35
import prpy .kin , prpy .tsr
36
36
37
+
37
38
class CBiRRTPlanner (BasePlanner ):
38
39
def __init__ (self ):
39
40
super (CBiRRTPlanner , self ).__init__ ()
@@ -109,7 +110,7 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
109
110
# 'object frame w' is at ee, z pointed along direction to move
110
111
H_world_w = prpy .kin .H_from_op_diff (H_world_ee [0 :3 ,3 ], direction )
111
112
H_w_ee = numpy .dot (prpy .kin .invert_H (H_world_w ), H_world_ee )
112
-
113
+
113
114
# Serialize TSR string (goal)
114
115
Hw_end = numpy .eye (4 )
115
116
Hw_end [2 ,3 ] = distance
@@ -135,7 +136,7 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
135
136
Bw = Bw ,
136
137
manip = robot .GetActiveManipulatorIndex ())
137
138
traj_tsr_chain = prpy .tsr .tsr .TSRChain (constrain = True , TSRs = [trajtsr ])
138
-
139
+
139
140
return self .Plan (robot ,
140
141
psample = 0.1 ,
141
142
tsr_chains = [goal_tsr_chain , traj_tsr_chain ],
@@ -227,7 +228,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
227
228
robot .GetActiveDOF (), len (start_config )
228
229
)
229
230
)
230
-
231
+
231
232
args += ['jointstarts' ] + self .serialize_dof_values (start_config )
232
233
233
234
if jointgoals is not None :
@@ -239,12 +240,12 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
239
240
robot .GetActiveDOF (), len (goal_config )
240
241
)
241
242
)
242
-
243
+
243
244
args += ['jointgoals' ] + self .serialize_dof_values (goal_config )
244
245
245
246
if tsr_chains is not None :
246
247
for tsr_chain in tsr_chains :
247
- args += [ 'TSRChain' , tsr_chain . serialize () ]
248
+ args += ['TSRChain' , _SerializeTSRChain ( tsr_chain ) ]
248
249
249
250
# FIXME: Why can't we write to anything other than cmovetraj.txt or
250
251
# /tmp/cmovetraj.txt with CBiRRT?
@@ -258,7 +259,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
258
259
259
260
if not response .strip ().startswith ('1' ):
260
261
raise PlanningError ('Unknown error: ' + response )
261
-
262
+
262
263
# Construct the output trajectory.
263
264
with open (traj_path , 'rb' ) as traj_file :
264
265
traj_xml = traj_file .read ()
@@ -290,4 +291,75 @@ def serialize_dof_values(dof_values):
290
291
return [ str (len (dof_values )),
291
292
' ' .join ([ str (x ) for x in dof_values ]) ]
292
293
293
-
294
+
295
+ def SerializeTransform12Col (tm , format = '%.5f' ):
296
+ return ' ' .join ([(format % (i ,)) for i in tm [0 :3 , :].T .reshape (12 )])
297
+
298
+
299
+ def SerializeArray (a , format = '%.5f' ):
300
+ return ' ' .join ([(format % (i ,)) for i in a .reshape (- 1 )])
301
+
302
+
303
+ def SerializeTSR (self ):
304
+ """
305
+ Function for Serializing TSRs for CBIRRT.
306
+
307
+ SerializeTSR(manipindex,bodyandlink,T0_w,Tw_e,Bw)
308
+
309
+ Input:
310
+ manipindex (int): the 0-indexed index of the robot's manipulator
311
+ bodyandlink (str): body and link which is used as the 0 frame. Format
312
+ 'body_name link_name'. For world frame, specify 'NULL'
313
+ T0_w (double 4x4): transform matrix of the TSR's reference frame relative
314
+ to the 0 frame
315
+ Tw_e (double 4x4): transform matrix of the TSR's offset frame relative to
316
+ the w frame
317
+ Bw (double 1x12): bounds in x y z roll pitch yaw.
318
+ Format: [x_min, x_max, y_min, y_max ...]
319
+
320
+ Output:
321
+ outstring (str): string to use for SerializeTSRChain function
322
+ """
323
+ return '%d %s %s %s %s' % (self .manipindex , self .bodyandlink ,
324
+ SerializeTransform12Col (self .T0_w ),
325
+ SerializeTransform12Col (self .Tw_e ),
326
+ SerializeArray (self .Bw ))
327
+
328
+
329
+ def SerializeTSRChain (self ):
330
+ """
331
+ Function for Serializing TSR Chains for CBIRRT.
332
+
333
+ _SerializeTSRChain(bSampleFromChain, bConstrainToChain,
334
+ numTSRs, allTSRstring,
335
+ mimicbodyname, mimicbodyjoints)
336
+
337
+ Input:
338
+ bSampleStartFromChain (0/1): 1: Use this chain for sampling start configs
339
+ 0: Ignore for sampling starts
340
+ bSampleGoalFromChain (0/1): 1: Use this chain for sampling goal configs
341
+ 0: Ignore for sampling goals
342
+ bConstrainToChain (0/1): 1: Use this chain for constraining configs
343
+ 0: Ignore for constraining
344
+ numTSRs (int): Number of TSRs in this chain (must be > 0)
345
+ allTSRstring (str): string of concatenated TSRs from SerializeTSR.
346
+ Should be like [TSRstring 1 ' ' TSRstring2 ...]
347
+ mimicbodyname (str): name of associated mimicbody for this chain
348
+ (NULL if none associated)
349
+ mimicbodyjoints (int [1xn]): 0-indexed indices of mimicbody's joints that
350
+ are mimiced (INCREASING AND CONSECUTIVE)
351
+
352
+ Output:
353
+ outstring (str): string to include in call to cbirrt planner
354
+ """
355
+ allTSRstring = ' ' .join ([SerializeTSR (tsr ) for tsr in self .TSRs ])
356
+ numTSRs = len (self .TSRs )
357
+ outstring = '%d %d %d' % (int (self .sample_start ),
358
+ int (self .sample_goal ),
359
+ int (self .constrain ))
360
+ outstring += ' %d %s' % (numTSRs , allTSRstring )
361
+ outstring += ' ' + self .mimicbodyname
362
+ if len (self .mimicbodyjoints ) > 0 :
363
+ outstring += ' %d %s' % (len (self .mimicbodyjoints ),
364
+ SerializeArray (self .mimicbodyjoints ))
365
+ return outstring
0 commit comments