Skip to content

Commit 22ecace

Browse files
committed
Merge branch 'master' of https://github.com/personalrobotics/prpy into bugfix/cloning_race
2 parents f35a31c + 47b8d59 commit 22ecace

File tree

4 files changed

+167
-103
lines changed

4 files changed

+167
-103
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<run_depend>manipulation2</run_depend>
1818
<run_depend>openrave</run_depend>
1919
<run_depend>python-scipy</run_depend>
20+
<run_depend>python-termcolor</run_depend>
2021
<test_depend>python-nose</test_depend>
2122
<test_depend>unittest</test_depend>
2223
</package>

src/prpy/planning/cbirrt.py

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
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 copy, logging, numpy, openravepy, os, tempfile
31+
import numpy, openravepy
3232
from ..util import SetTrajectoryTags
3333
from base import (BasePlanner, PlanningError, UnsupportedPlanningError,
3434
PlanningMethod, Tags)
3535
import prpy.kin, prpy.tsr
3636

37+
3738
class CBiRRTPlanner(BasePlanner):
3839
def __init__(self):
3940
super(CBiRRTPlanner, self).__init__()
@@ -109,7 +110,7 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
109110
# 'object frame w' is at ee, z pointed along direction to move
110111
H_world_w = prpy.kin.H_from_op_diff(H_world_ee[0:3,3], direction)
111112
H_w_ee = numpy.dot(prpy.kin.invert_H(H_world_w), H_world_ee)
112-
113+
113114
# Serialize TSR string (goal)
114115
Hw_end = numpy.eye(4)
115116
Hw_end[2,3] = distance
@@ -135,7 +136,7 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
135136
Bw = Bw,
136137
manip = robot.GetActiveManipulatorIndex())
137138
traj_tsr_chain = prpy.tsr.tsr.TSRChain(constrain=True, TSRs=[trajtsr])
138-
139+
139140
return self.Plan(robot,
140141
psample=0.1,
141142
tsr_chains=[goal_tsr_chain, traj_tsr_chain],
@@ -227,7 +228,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
227228
robot.GetActiveDOF(), len(start_config)
228229
)
229230
)
230-
231+
231232
args += ['jointstarts'] + self.serialize_dof_values(start_config)
232233

233234
if jointgoals is not None:
@@ -239,12 +240,12 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
239240
robot.GetActiveDOF(), len(goal_config)
240241
)
241242
)
242-
243+
243244
args += ['jointgoals'] + self.serialize_dof_values(goal_config)
244245

245246
if tsr_chains is not None:
246247
for tsr_chain in tsr_chains:
247-
args += [ 'TSRChain', tsr_chain.serialize() ]
248+
args += ['TSRChain', SerializeTSRChain(tsr_chain)]
248249

249250
# FIXME: Why can't we write to anything other than cmovetraj.txt or
250251
# /tmp/cmovetraj.txt with CBiRRT?
@@ -258,7 +259,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
258259

259260
if not response.strip().startswith('1'):
260261
raise PlanningError('Unknown error: ' + response)
261-
262+
262263
# Construct the output trajectory.
263264
with open(traj_path, 'rb') as traj_file:
264265
traj_xml = traj_file.read()
@@ -290,4 +291,75 @@ def serialize_dof_values(dof_values):
290291
return [ str(len(dof_values)),
291292
' '.join([ str(x) for x in dof_values]) ]
292293

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

src/prpy/serialization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def serialize(obj):
7070
elif isinstance(obj, TSR):
7171
return {
7272
TYPE_KEY: TSR.__name__,
73-
'data': obj.serialize_dict()
73+
'data': obj.to_dict()
7474
}
7575
elif isinstance(obj, TSRChain):
7676
return {
7777
TYPE_KEY: TSRChain.__name__,
78-
'data': obj.serialize_dict()
78+
'data': obj.to_dict()
7979
}
8080
else:
8181
raise UnsupportedTypeSerializationException(obj)
@@ -261,9 +261,9 @@ def _deserialize_internal(env, data, data_type):
261261
traj.deserialize(data['data'])
262262
return traj
263263
elif data_type == TSR.__name__:
264-
return TSR.deserialize_dict(data['data'])
264+
return TSR.from_dict(data['data'])
265265
elif data_type == TSRChain.__name__:
266-
return TSRChain.deserialize_dict(data['data'])
266+
return TSRChain.from_dict(data['data'])
267267
else:
268268
raise UnsupportedTypeDeserializationException(data_type)
269269

0 commit comments

Comments
 (0)