Hello Spyros,
OMPL will only give you desired_angle(i) but not desired_angle(t), where i is an index of points on the trajectory. However for a single rotational axis there is only one ( or two ) ways to get from angle1 to angle2, so OMPL is not needed here. you can just simply interpolate between two RobotState with a stepsize that depends on how precise you need to check collisions. Then check collisions for each angle inbetween. If there are none you can execute your trajectory by whatever means suite you.
To go from desired_angle(i) to desired_angle(t) you need to do time parametrization. You can check out trajectory_processing::IterativeParabolicTimeParameterization for an example. But probably there are simpler solutions for single axis systems.
You're welcome
Here's a piece of sample code, you will need to adapt it a bit to suite your needs:
robot_state::RobotState intermediateState(state);
bool collisionFree = true;
{ // Scope LockedPlanningSceneRO
planning_scene_monitor::LockedPlanningSceneRO ps(m_rosWorld->getPlanningSceneMonitor());
int steps = 100; //Todo: make this dependent on distance
for (int i = 0; i <= steps; i++) {
state.interpolate(goalState, i*1.0/steps, intermediateState);
intermediateState.update();
intermediateState.updateCollisionBodyTransforms();
if (!ps->isStateValid(intermediateState, "manipulator")) {
ROS_ERROR("Collision in direct moving at %f, will start planner", i*1.0/steps);
collision_detection::CollisionResult::ContactMap contacts;
ps->getCollidingPairs(contacts, intermediateState);
for (collision_detection::CollisionResult::ContactMap::const_iterator it = contacts.begin(); it != contacts.end(); ++it) {
std::cout << "Collision between " << it->first.first << " and " << it->first.second << std::endl;
}
collisionFree = false;
break;
}
}
} // Scope LockedPlanningSceneRO
bool pathFound = collisionFree;
if (collisionFree) {
std::cout << "Path is clear, moving directly" << std::endl;
robot_trajectory::RobotTrajectory traj(state.getRobotModel(), "manipulator");
double nulls [6]= {0, 0, 0, 0, 0, 0};
goalState.setVariableVelocities(nulls);
goalState.setVariableAccelerations(nulls);
robot_state::RobotState wSpeed(state);
wSpeed.setVariableVelocities(nulls);
wSpeed.setVariableAccelerations(nulls);
traj.addSuffixWayPoint(wSpeed, 1e-4);
traj.addSuffixWayPoint(goalState, 0.01); //Todo: calculate time?
trajectory_processing::IterativeParabolicTimeParameterization timeGuess;
bool success = timeGuess.computeTimeStamps(traj);
traj.getLastWayPointPtr()->setVariableAccelerations(nulls);
std::cout << "Time parametrization: " << (success?"yes":"no") << traj.getWayPointDurations().back() << std::endl;
std::cout << "num waypoints: " << traj.getWayPointCount() << std::endl;
moveit::core::robotStateToRobotStateMsg(wSpeed, plan.start_state_);
traj.getRobotTrajectoryMsg(plan.trajectory_);