moveit2
The MoveIt Motion Planning Framework for ROS 2.
trajopt_planning_context.cpp
Go to the documentation of this file.
3 #include <moveit_msgs/MotionPlanRequest.h>
5 
6 #include <ros/console.h>
7 
8 #include <Eigen/Geometry>
9 
12 
13 namespace trajopt_interface
14 {
15 TrajOptPlanningContext::TrajOptPlanningContext(const std::string& context_name, const std::string& group_name,
16  const moveit::core::RobotModelConstPtr& model)
17  : planning_interface::PlanningContext(context_name, group_name), robot_model_(model)
18 {
19  ROS_INFO(" ======================================= TrajOptPlanningContext is constructed");
20  trajopt_interface_ = std::make_shared<TrajOptInterface>();
21 }
22 
24 {
25  moveit_msgs::MotionPlanDetailedResponse res_msg;
26  bool trajopt_solved = trajopt_interface_->solve(planning_scene_, request_, res_msg);
27 
28  if (trajopt_solved)
29  {
30  res.trajectory_.resize(1);
31  res.trajectory_[0] = std::make_shared<robot_trajectory::RobotTrajectory>(robot_model_, getGroupName());
32 
33  moveit::core::RobotState start_state(robot_model_);
34  moveit::core::robotStateMsgToRobotState(res_msg.trajectory_start, start_state);
35  res.trajectory_[0]->setRobotTrajectoryMsg(start_state, res_msg.trajectory[0]);
36 
37  res.description_.push_back("plan");
38  // TODO: Add the initial trajectory to res (MotionPlanDetailedResponse)
39  res.processing_time_ = res_msg.processing_time;
40  res.error_code_ = res_msg.error_code;
41  return true;
42  }
43  else
44  {
45  res.error_code_ = res_msg.error_code;
46  return false;
47  }
48 }
49 
51 {
53  bool planning_success = solve(res_detailed);
54 
55  res.error_code_ = res_detailed.error_code_;
56 
57  if (planning_success)
58  {
59  res.trajectory_ = res_detailed.trajectory_[0];
60  res.planning_time_ = res_detailed.processing_time_[0];
61  }
62 
63  return planning_success;
64 }
65 
67 {
68  ROS_ERROR_STREAM_NAMED("trajopt_planning_context", "TrajOpt is not interruptible yet");
69  return false;
70 }
72 {
73 }
74 
75 } // namespace trajopt_interface
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:90
planning_scene::PlanningSceneConstPtr planning_scene_
The planning scene for this context.
MotionPlanRequest request_
The planning request for this context.
const std::string & getGroupName() const
Get the name of the group this planning context is for.
void clear() override
Clear the data structures used by the planner.
bool terminate() override
If solve() is running, terminate the computation. Return false if termination not possible....
bool solve(planning_interface::MotionPlanResponse &res) override
Solve the motion planning problem and store the result in res. This function should not clear data st...
TrajOptPlanningContext(const std::string &name, const std::string &group, const moveit::core::RobotModelConstPtr &model)
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::msg::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
Convert a robot state msg (with accompanying extra transforms) to a MoveIt robot state.
This namespace includes the base class for MoveIt planners.
moveit_msgs::msg::MoveItErrorCodes error_code_
std::vector< robot_trajectory::RobotTrajectoryPtr > trajectory_
robot_trajectory::RobotTrajectoryPtr trajectory_
moveit_msgs::msg::MoveItErrorCodes error_code_