-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions: TrajToArray() & ArrayToTraj() #252
Comments
Would the array only contain positions? Otherwise, I think it needs to have dimensions of I'm not sure exactly what |
Yes currently TrajToArray() gets the waypoints from an OpenRAVE trajectory and puts the joint angles into an N x 7 array. |
Umm.. Won't this only be anything reasonable on a single WAM arm If so, this seems much more herbpy than prpy. Even then timed trajectories
|
ArrayToTraj() is used in a new, proposed planner. If people don't think it's general enough, I'll just leave it in with the planner's code. def ArrayToTraj(robot, cspec, dof, traj_array):
"""
Convert an array of joint positions into a timed trajectory.
@param robot: The robot object.
@param cspec: OpenRAVE Configuration Specification.
@param dof: (int) Num of joints in the array.
@param traj_array: (numpy.array) Rows for each configuration,
columns for each joint.
@returns openravepy.Trajectory: A timed trajectory.
"""
env = robot.GetEnv()
traj = openravepy.RaveCreateTrajectory(env,'')
traj.Init(cs)
num_rows,num_cols = traj_array.shape
if num_cols != dof:
raise ValueError('num_cols != dof')
for i in range(num_rows):
traj.Insert(i, traj_array[i,:])
openravepy.planningutils.RetimeActiveDOFTrajectory(
traj, robot, False, 0.2, 0.2, "LinearTrajectoryRetimer", "")
return traj
# Convert array of joint configurations into OpenRAVE trajectory
cspec = robot.GetActiveConfigurationSpecification('linear')
jointspace_traj = ArrayToTraj(robot, cspec, 7, q) |
Ok yes TrajToArray() may be more accurately called PathToArray() or something. def PathToArray(path, num_dof):
"""
Get the joint angles at each waypoint in a path
and return them in an array.
@param path: A path, being an un-timed OpenRAVE trajectory.
@param num_dof: (int) The number of joints.
@returns positions_array (numpy.array) Rows for each configuration,
columns for each joint.
"""
num_waypoints = path.GetNumWaypoints()
# ToDo: if path is timed, strip the timing or throw exception??
positions_array = numpy.zeros((num_waypoints, num_dof))
for i in range(num_waypoints):
# Get first num_dof values, the values that
# come afterwards are velocities
q = path.GetWaypoint(i)[range(num_dof)]
positions_array[i,:] = q
return positions_array |
I'm not opposed to adding a function that converts a piecewise linear joint trajectory to a NumPy array. All of our planners return a trajectory of this type, so it is a useful utility function to have. However, you would need to add significantly better error checking to the |
I also just noticed that there is a function |
prpy.util.JointStatesFromTraj() is for a timed trajectory, and you need to specify the sample times as a parameter. I am proposing to add a function PathToArray() that operates on un-timed trajectories, so I think we should add it. |
I don't understand where to add 'robot' and 'list of DOFs' to the PathToArray() function? Here's some improved input checking: def PathToArray(path, num_dof):
"""
Get the joint angles at each waypoint in a path
and return them in an array.
@param path: A path, being an un-timed OpenRAVE trajectory.
@param num_dof: (int) The number of joints.
@returns positions_array (numpy.array) Rows for each configuration,
columns for each joint.
"""
# Make sure path does not have timing
if IsTimedTrajectory(path):
ValueError('PathToArray() requires an un-timed path')
path_cspec = path.GetConfigurationSpecification()
# Make sure path is linear in joint space
try:
# OpenRAVE trajectory type can be 'linear', 'quadratic', or
# other values including 'cubic', 'quadric' or 'quintic'
interp_type = path_cspec.GetGroupFromName('joint_values').interpolation
except openravepy.openrave_exception:
raise ValueError('Path does not have a joint_values group')
if interp_type != 'linear':
raise ValueError('Path must be linear in joint space')
num_waypoints = path.GetNumWaypoints()
positions_array = numpy.zeros((num_waypoints, num_dof))
for i in range(num_waypoints):
# Get first num_dof values, the values that
# come afterwards are velocities
q = path.GetWaypoint(i)[range(num_dof)]
positions_array[i,:] = q
return positions_array |
These are similar to existing prpy.util functions MatrixToTraj() and TrajToMatrix().
Does anyone remember what the purpose of these is?
They seem to use a single dimension matrix, which seems strange to me.
The text was updated successfully, but these errors were encountered: