Skip to content

Commit 804d2b7

Browse files
committed
Merge pull request #234 from personalrobotics/fix/unittiming_vel
fix ComputeUnitTiming velocity bug, add unit test
2 parents 15621cc + ef05bca commit 804d2b7

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/prpy/util.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -890,16 +890,20 @@ def ComputeUnitTiming(robot, traj, env=None):
890890
if env is None:
891891
env = traj.GetEnv()
892892

893-
cspec = traj.GetConfigurationSpecification()
894-
cspec.AddDeltaTimeGroup()
895-
dof_indices, _ = cspec.ExtractUsedIndices(robot)
893+
old_cspec = traj.GetConfigurationSpecification()
894+
dof_indices, _ = old_cspec.ExtractUsedIndices(robot)
895+
896+
with robot.CreateRobotStateSaver(robot):
897+
robot.SetActiveDOFs(dof_indices)
898+
new_cspec = robot.GetActiveConfigurationSpecification('linear')
899+
new_cspec.AddDeltaTimeGroup()
896900

897901
new_traj = RaveCreateTrajectory(env, '')
898-
new_traj.Init(cspec)
902+
new_traj.Init(new_cspec)
899903

900904
for i in range(traj.GetNumWaypoints()):
901-
waypoint = traj.GetWaypoint(i, cspec)
902-
dof_values = cspec.ExtractJointValues(waypoint, robot, dof_indices)
905+
old_waypoint = traj.GetWaypoint(i)
906+
dof_values = old_cspec.ExtractJointValues(old_waypoint, robot, dof_indices)
903907

904908
if i == 0:
905909
deltatime = 0.
@@ -908,8 +912,11 @@ def ComputeUnitTiming(robot, traj, env=None):
908912

909913
dof_values_prev = dof_values
910914

911-
cspec.InsertDeltaTime(waypoint, deltatime)
912-
new_traj.Insert(i, waypoint)
915+
new_waypoint = numpy.zeros(new_cspec.GetDOF())
916+
917+
new_cspec.InsertJointValues(new_waypoint, dof_values, robot, dof_indices, 0)
918+
new_cspec.InsertDeltaTime(new_waypoint, deltatime)
919+
new_traj.Insert(i, new_waypoint)
913920

914921
return new_traj
915922

tests/test_util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,18 @@ def test_IsAtTrajectoryEnd_ReturnsFalse(self):
147147
q1 = goal_config
148148
traj = self.CreateTrajectory(q0, q1)
149149
self.assertFalse(prpy.util.IsAtTrajectoryEnd(self.robot, traj))
150+
151+
def test_ComputeUnitTiming(self):
152+
cspec = self.robot.GetActiveConfigurationSpecification()
153+
traj = openravepy.RaveCreateTrajectory(self.env, '')
154+
traj.Init(cspec)
155+
traj.Insert(0, [0,0,0,0,0,0,0])
156+
traj.Insert(1, [1,0,0,0,0,0,0])
157+
openravepy.planningutils.RetimeActiveDOFTrajectory(traj,
158+
self.robot, False, 100.0, 100.0, 'LinearTrajectoryRetimer', '')
159+
traj_arclen = prpy.util.ComputeUnitTiming(self.robot, traj)
160+
dofvals = traj_arclen.Sample(0.99, cspec)
161+
self.assertAlmostEqual(dofvals[0], 0.99)
162+
163+
if __name__ == '__main__':
164+
unittest.main()

0 commit comments

Comments
 (0)