42 #if __has_include(<tf2/LinearMath/Quaternion.hpp>) 
   43 #include <tf2/LinearMath/Quaternion.hpp> 
   45 #include <tf2/LinearMath/Quaternion.h> 
   47 #include <tf2_eigen/tf2_eigen.hpp> 
   48 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp> 
   54 static const rclcpp::Logger LOGGER = rclcpp::get_logger(
"chomp_planner");
 
   60   auto start_time = std::chrono::system_clock::now();
 
   63     RCLCPP_ERROR(LOGGER, 
"No planning scene initialized.");
 
   64     res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::FAILURE;
 
   74     RCLCPP_ERROR(LOGGER, 
"Start state violates joint limits");
 
   75     res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::INVALID_ROBOT_STATE;
 
   82   if (req.goal_constraints.size() != 1)
 
   84     RCLCPP_ERROR(LOGGER, 
"Expecting exactly one goal constraint, got: %zd", req.goal_constraints.size());
 
   85     res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS;
 
   89   if (req.goal_constraints[0].joint_constraints.empty() || !req.goal_constraints[0].position_constraints.empty() ||
 
   90       !req.goal_constraints[0].orientation_constraints.empty())
 
   92     RCLCPP_ERROR(LOGGER, 
"Only joint-space goals are supported");
 
   93     res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS;
 
   99   for (
const moveit_msgs::msg::JointConstraint& joint_constraint : req.goal_constraints[0].joint_constraints)
 
  103     RCLCPP_ERROR(LOGGER, 
"Goal state violates joint limits");
 
  104     res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::INVALID_ROBOT_STATE;
 
  107   robotStateToArray(goal_state, req.group_name, trajectory.
getTrajectoryPoint(goal_index));
 
  110       planning_scene->getRobotModel()->getJointModelGroup(req.group_name);
 
  118     if (revolute_joint != 
nullptr)
 
  122         double start = (trajectory)(0, i);
 
  123         double end = (trajectory)(goal_index, i);
 
  124         RCLCPP_INFO(LOGGER, 
"Start is %f end %f short %f", start, end, shortestAngularDistance(start, end));
 
  125         (trajectory)(goal_index, i) = start + shortestAngularDistance(start, end);
 
  141       RCLCPP_ERROR(LOGGER, 
"Input trajectory has less than 2 points, " 
  142                            "trajectory must contain at least start and goal state");
 
  148     RCLCPP_ERROR(LOGGER, 
"invalid interpolation method specified in the chomp_planner file");
 
  152   RCLCPP_INFO(LOGGER, 
"CHOMP trajectory initialized using method: %s ",
 
  156   auto create_time = std::chrono::system_clock::now();
 
  158   int replan_count = 0;
 
  159   bool replan_flag = 
false;
 
  160   double org_learning_rate = 0.04, org_ridge_factor = 0.0, org_planning_time_limit = 10;
 
  161   int org_max_iterations = 200;
 
  169   std::unique_ptr<ChompOptimizer> optimizer;
 
  188         std::make_unique<ChompOptimizer>(&trajectory, 
planning_scene, req.group_name, ¶ms_nonconst, start_state);
 
  189     if (!optimizer->isInitialized())
 
  191       RCLCPP_ERROR(LOGGER, 
"Could not initialize optimizer");
 
  192       res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED;
 
  196     RCLCPP_DEBUG(LOGGER, 
"Optimization took %ld sec to create",
 
  197                  (std::chrono::system_clock::now() - create_time).count());
 
  199     bool optimization_result = optimizer->optimize();
 
  205                   "Planned with Chomp Parameters (learning_rate, ridge_factor, " 
  206                   "planning_time_limit, max_iterations), attempt: # %d ",
 
  208       RCLCPP_INFO(LOGGER, 
"Learning rate: %f ridge factor: %f planning time limit: %f max_iterations %d ",
 
  227   params_nonconst.
setRecoveryParams(org_learning_rate, org_ridge_factor, org_planning_time_limit, org_max_iterations);
 
  229   RCLCPP_DEBUG(LOGGER, 
"Optimization actually took %ld sec to run",
 
  230                (std::chrono::system_clock::now() - create_time).count());
 
  231   create_time = std::chrono::system_clock::now();
 
  234   RCLCPP_DEBUG(LOGGER, 
"Output trajectory has %zd joints", trajectory.
getNumJoints());
 
  236   auto result = std::make_shared<robot_trajectory::RobotTrajectory>(
planning_scene->getRobotModel(), req.group_name);
 
  241     auto state = std::make_shared<moveit::core::RobotState>(start_state);
 
  242     size_t joint_index = 0;
 
  245       assert(jm->getVariableCount() == 1);
 
  246       state->setVariablePosition(jm->getFirstVariableIndex(), source[joint_index++]);
 
  248     result->addSuffixWayPoint(state, 0.0);
 
  254   RCLCPP_DEBUG(LOGGER, 
"Bottom took %ld sec to create", (std::chrono::system_clock::now() - create_time).count());
 
  255   RCLCPP_DEBUG(LOGGER, 
"Serviced planning request in %ld wall-seconds",
 
  256                (std::chrono::system_clock::now() - start_time).count());
 
  258   res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::SUCCESS;
 
  260   res.
processing_time_[0] = std::chrono::duration<double>(std::chrono::system_clock::now() - start_time).count();
 
  263   if (!optimizer->isCollisionFree())
 
  265     RCLCPP_ERROR(LOGGER, 
"Motion plan is invalid.");
 
  266     res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN;
 
  273   for (
const moveit_msgs::msg::JointConstraint& constraint : req.goal_constraints[0].joint_constraints)
 
  277       RCLCPP_ERROR(LOGGER, 
"Goal constraints are violated: %s", constraint.joint_name.c_str());
 
  278       res.
error_code_.val = moveit_msgs::msg::MoveItErrorCodes::GOAL_CONSTRAINTS_VIOLATED;
 
  284   res.
processing_time_[0] = std::chrono::duration<double>(std::chrono::system_clock::now() - start_time).count();
 
double planning_time_limit_
 
std::string trajectory_initialization_method_
 
void setRecoveryParams(double learning_rate, double ridge_factor, int planning_time_limit, int max_iterations)
 
int max_recovery_attempts_
 
bool enable_failure_recovery_
 
bool solve(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, const ChompParameters ¶ms, planning_interface::MotionPlanDetailedResponse &res) const
 
Represents a discretized joint-space trajectory for CHOMP.
 
size_t getNumPoints() const
Gets the number of points in the trajectory.
 
void fillInCubicInterpolation()
Generates a cubic interpolation of the trajectory from the start index to end index.
 
bool fillInFromTrajectory(const robot_trajectory::RobotTrajectory &trajectory)
Receives the path obtained from a given MotionPlanDetailedResponse res object's trajectory (e....
 
size_t getNumJoints() const
Gets the number of joints in each trajectory point.
 
Eigen::MatrixXd::RowXpr getTrajectoryPoint(int traj_point)
 
void fillInLinearInterpolation()
Generates a linearly interpolated trajectory from the start index to end index.
 
void fillInMinJerk()
Generates a minimum jerk trajectory from the start index to end index.
 
Class for handling single DOF joint constraints.
 
ConstraintEvaluationResult decide(const moveit::core::RobotState &state, bool verbose=false) const override
Decide whether the constraint is satisfied in the indicated state.
 
bool configure(const moveit_msgs::msg::JointConstraint &jc)
Configure the constraint based on a moveit_msgs::msg::JointConstraint.
 
const std::vector< const JointModel * > & getActiveJointModels() const
Get the active joints in this group (that have controllable DOF). This does not include mimic joints.
 
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
 
bool isContinuous() const
Check if this joint wraps around.
 
Representation of a robot's state. This includes position, velocity, acceleration and effort.
 
void setVariablePosition(const std::string &variable, double value)
Set the position of a single variable. An exception is thrown if the variable name is not known.
 
bool satisfiesBounds(double margin=0.0) const
 
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.
 
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
 
This namespace includes the central class for representing planning contexts.
 
bool satisfied
Whether or not the constraint or constraints were satisfied.
 
moveit_msgs::msg::MoveItErrorCodes error_code_
 
std::vector< robot_trajectory::RobotTrajectoryPtr > trajectory_
 
std::vector< double > processing_time_