Robowflex  v0.1
Making MoveIt Easy
ompl_trajectory.cpp
Go to the documentation of this file.
1 /* Author: Constantinos Chamzas */
2 
7 
8 #include <moveit/ompl_interface/parameterization/model_based_state_space.h>
10 
11 using namespace robowflex;
12 
14  : Trajectory(robot, group)
15 {
16 }
17 
19 {
20 }
21 
22 ompl::geometric::PathGeometric OMPL::OMPLTrajectory::toOMPLPath(const ompl::geometric::SimpleSetupPtr &ss)
23 {
24  auto path = ompl::geometric::PathGeometric(ss->getSpaceInformation());
25  auto *tstate = ss->getSpaceInformation()->allocState();
26  auto traj_msg = getMessage();
27 
28  // transform to Path geometric
29  for (const auto &state_vec : traj_msg.joint_trajectory.points)
30  for (unsigned int j = 0; j < state_vec.positions.size(); j++)
31  tstate->as<ompl_interface::ModelBasedStateSpace::StateType>()->values[j] = state_vec.positions[j];
32 
33  path.append(tstate);
34 
35  return path;
36 }
37 
38 void OMPL::OMPLTrajectory::fromOMPLPath(const robot_state::RobotState &reference_state,
39  const ompl::geometric::PathGeometric &path)
40 {
41  const auto &mbss = std::dynamic_pointer_cast<ompl_interface::ModelBasedStateSpace>(
42  path.getSpaceInformation()->getStateSpace());
43 
44  if (not mbss)
45  throw Exception(1, "Failed to extract StateSpace from provided OMPL path!");
46 
47  moveit::core::RobotState ks = reference_state;
48  for (std::size_t i = 0; i < path.getStateCount(); ++i)
49  {
50  mbss->copyToRobotState(ks, path.getState(i));
51  trajectory_->addSuffixWayPoint(ks, 0.0);
52  }
53 }
Exception that contains a message and an error code.
Definition: util.h:15
void fromOMPLPath(const robot_state::RobotState &reference_state, const ompl::geometric::PathGeometric &path)
Sets the trajectory from an OMPL Path and a reference state.
ompl::geometric::PathGeometric toOMPLPath(const ompl::geometric::SimpleSetupPtr &ss)
Converts to an OMPL Path given an OMPL simple_setup.
OMPLTrajectory(const RobotConstPtr &robot, const std::string &group)
Constructor.
A const shared pointer wrapper for robowflex::Robot.
The Trajectory class is a wrapper around MoveIt!'s robot_trajectory::RobotTrajectory,...
Definition: trajectory.h:43
Functions for loading and animating robots in Blender.
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")