chomp_optimizer_adapter.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Raghavender Sahdev.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Raghavender Sahdev nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Raghavender Sahdev */
36 
40 #include <moveit_msgs/RobotTrajectory.h>
42 #include <ros/ros.h>
43 
48 
50 
52 
53 #include <vector>
54 #include <eigen3/Eigen/Core>
55 
56 namespace chomp
57 {
58 class OptimizerAdapter : public planning_request_adapter::PlanningRequestAdapter
59 {
60 public:
62  {
63  }
64 
65  void initialize(const ros::NodeHandle& nh) override
66  {
67  if (!nh.getParam("planning_time_limit", params_.planning_time_limit_))
68  {
70  ROS_INFO_STREAM("Param planning_time_limit was not set. Using default value: " << params_.planning_time_limit_);
71  }
72  if (!nh.getParam("max_iterations", params_.max_iterations_))
73  {
75  ROS_INFO_STREAM("Param max_iterations was not set. Using default value: " << params_.max_iterations_);
76  }
77  if (!nh.getParam("max_iterations_after_collision_free", params_.max_iterations_after_collision_free_))
78  {
80  ROS_INFO_STREAM("Param max_iterations_after_collision_free was not set. Using default value: "
82  }
83  if (!nh.getParam("smoothness_cost_weight", params_.smoothness_cost_weight_))
84  {
87  "Param smoothness_cost_weight was not set. Using default value: " << params_.smoothness_cost_weight_);
88  }
89  if (!nh.getParam("obstacle_cost_weight", params_.obstacle_cost_weight_))
90  {
92  ROS_INFO_STREAM("Param obstacle_cost_weight was not set. Using default value: " << params_.obstacle_cost_weight_);
93  }
94  if (!nh.getParam("learning_rate", params_.learning_rate_))
95  {
96  params_.learning_rate_ = 0.01;
97  ROS_INFO_STREAM("Param learning_rate was not set. Using default value: " << params_.learning_rate_);
98  }
99  if (!nh.getParam("smoothness_cost_velocity", params_.smoothness_cost_velocity_))
100  {
103  "Param smoothness_cost_velocity was not set. Using default value: " << params_.smoothness_cost_velocity_);
104  }
105  if (!nh.getParam("smoothness_cost_acceleration", params_.smoothness_cost_acceleration_))
106  {
108  ROS_INFO_STREAM("Param smoothness_cost_acceleration was not set. Using default value: "
110  }
111  if (!nh.getParam("smoothness_cost_jerk", params_.smoothness_cost_jerk_))
112  {
114  ROS_INFO_STREAM("Param smoothness_cost_jerk_ was not set. Using default value: " << params_.smoothness_cost_jerk_);
115  }
116  if (!nh.getParam("ridge_factor", params_.ridge_factor_))
117  {
118  params_.ridge_factor_ = 0.0;
119  ROS_INFO_STREAM("Param ridge_factor_ was not set. Using default value: " << params_.ridge_factor_);
120  }
121  if (!nh.getParam("use_pseudo_inverse", params_.use_pseudo_inverse_))
122  {
124  ROS_INFO_STREAM("Param use_pseudo_inverse_ was not set. Using default value: " << params_.use_pseudo_inverse_);
125  }
126  if (!nh.getParam("pseudo_inverse_ridge_factor", params_.pseudo_inverse_ridge_factor_))
127  {
129  ROS_INFO_STREAM("Param pseudo_inverse_ridge_factor was not set. Using default value: "
131  }
132  if (!nh.getParam("joint_update_limit", params_.joint_update_limit_))
133  {
135  ROS_INFO_STREAM("Param joint_update_limit was not set. Using default value: " << params_.joint_update_limit_);
136  }
137  // TODO: remove this warning after 06/2022
138  if (!nh.hasParam("min_clearance") && nh.hasParam("min_clearence"))
139  ROS_WARN("The param 'min_clearence' has been renamed to 'min_clearance', please update your config!");
140  if (!nh.getParam("min_clearance", params_.min_clearance_))
141  {
142  params_.min_clearance_ = 0.2;
143  ROS_INFO_STREAM("Param min_clearance was not set. Using default value: " << params_.min_clearance_);
144  }
145  if (!nh.getParam("collision_threshold", params_.collision_threshold_))
146  {
148  ROS_INFO_STREAM("Param collision_threshold_ was not set. Using default value: " << params_.collision_threshold_);
149  }
150  if (!nh.getParam("use_stochastic_descent", params_.use_stochastic_descent_))
151  {
154  "Param use_stochastic_descent was not set. Using default value: " << params_.use_stochastic_descent_);
155  }
156  // default
157  params_.trajectory_initialization_method_ = std::string("fillTrajectory");
158  std::string trajectory_initialization_method;
159  if (!nh.getParam("trajectory_initialization_method", trajectory_initialization_method))
160  {
161  ROS_INFO_STREAM("Param trajectory_initialization_method was not set. Using value: "
163  }
164  else if (!params_.setTrajectoryInitializationMethod(trajectory_initialization_method))
165  {
166  ROS_ERROR_STREAM("Param trajectory_initialization_method set to invalid value '"
167  << trajectory_initialization_method << "'. Using '" << params_.trajectory_initialization_method_
168  << "' instead.");
169  }
170  }
171 
172  std::string getDescription() const override
173  {
174  return "CHOMP Optimizer";
175  }
176 
177  bool adaptAndPlan(const PlannerFn& planner, const planning_scene::PlanningSceneConstPtr& ps,
179  std::vector<std::size_t>& /*added_path_index*/) const override
180  {
181  // following call to planner() calls the OMPL planner and stores the trajectory inside the MotionPlanResponse res
182  // variable which is then used by CHOMP for optimization of the computed trajectory
183  if (!planner(ps, req, res))
184  return false;
185 
186  // create a hybrid collision detector to set the collision checker as hybrid
187  collision_detection::CollisionDetectorAllocatorPtr hybrid_cd(
189 
190  // create a writable planning scene
191  planning_scene::PlanningScenePtr planning_scene = ps->diff();
192  ROS_DEBUG_STREAM("Configuring Planning Scene for CHOMP ...");
193  planning_scene->setActiveCollisionDetector(hybrid_cd, true);
194 
195  chomp::ChompPlanner chomp_planner;
197  res_detailed.trajectory_.push_back(res.trajectory_);
198 
199  bool planning_success = chomp_planner.solve(planning_scene, req, params_, res_detailed);
200 
201  if (planning_success)
202  {
203  res.trajectory_ = res_detailed.trajectory_[0];
204  res.planning_time_ += res_detailed.processing_time_[0];
205  }
206  res.error_code_ = res_detailed.error_code_;
207 
208  return planning_success;
209  }
210 
211 private:
213 };
214 } // namespace chomp
215 
chomp::ChompParameters::max_iterations_after_collision_free_
int max_iterations_after_collision_free_
chomp::ChompParameters::planning_time_limit_
double planning_time_limit_
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
chomp::ChompParameters::smoothness_cost_velocity_
double smoothness_cost_velocity_
chomp::ChompParameters::collision_threshold_
double collision_threshold_
planning_interface::MotionPlanResponse
chomp::ChompPlanner::solve
bool solve(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, const ChompParameters &params, planning_interface::MotionPlanDetailedResponse &res) const
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
planning_request_adapter.h
ros.h
chomp::ChompParameters::pseudo_inverse_ridge_factor_
double pseudo_inverse_ridge_factor_
planning_interface::MotionPlanResponse::error_code_
moveit::core::MoveItErrorCode error_code_
planning_interface.h
chomp
chomp::OptimizerAdapter::OptimizerAdapter
OptimizerAdapter()
Definition: chomp_optimizer_adapter.cpp:125
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
chomp::ChompPlanner
chomp_planner.h
planning_request_adapter::PlanningRequestAdapter
chomp::OptimizerAdapter
Definition: chomp_optimizer_adapter.cpp:90
chomp::OptimizerAdapter::adaptAndPlan
bool adaptAndPlan(const PlannerFn &planner, const planning_scene::PlanningSceneConstPtr &ps, const planning_interface::MotionPlanRequest &req, planning_interface::MotionPlanResponse &res, std::vector< std::size_t > &) const override
Definition: chomp_optimizer_adapter.cpp:241
chomp::ChompParameters::obstacle_cost_weight_
double obstacle_cost_weight_
chomp::ChompParameters::smoothness_cost_jerk_
double smoothness_cost_jerk_
chomp::ChompParameters::joint_update_limit_
double joint_update_limit_
planning_interface::MotionPlanResponse::trajectory_
robot_trajectory::RobotTrajectoryPtr trajectory_
planning_interface::MotionPlanDetailedResponse::trajectory_
std::vector< robot_trajectory::RobotTrajectoryPtr > trajectory_
ros::NodeHandle::hasParam
bool hasParam(const std::string &key) const
ROS_WARN
#define ROS_WARN(...)
chomp::ChompParameters::use_pseudo_inverse_
bool use_pseudo_inverse_
chomp::ChompParameters::smoothness_cost_weight_
double smoothness_cost_weight_
chomp::OptimizerAdapter::initialize
void initialize(const ros::NodeHandle &nh) override
Definition: chomp_optimizer_adapter.cpp:129
class_loader.hpp
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
planning_interface::MotionPlanRequest
moveit_msgs::MotionPlanRequest MotionPlanRequest
CollisionDetectorAllocatorTemplate< CollisionEnvHybrid, CollisionDetectorAllocatorHybrid >::create
static CollisionDetectorAllocatorPtr create()
chomp::ChompParameters::ridge_factor_
double ridge_factor_
collision_detector_allocator_hybrid.h
chomp::ChompParameters::max_iterations_
int max_iterations_
iterative_time_parameterization.h
chomp::ChompParameters::use_stochastic_descent_
bool use_stochastic_descent_
chomp::ChompParameters
planning_request_adapter::PlanningRequestAdapter::PlanningRequestAdapter
PlanningRequestAdapter()
planning_request_adapter::PlanningRequestAdapter::PlannerFn
boost::function< bool(const planning_scene::PlanningSceneConstPtr &, const planning_interface::MotionPlanRequest &, planning_interface::MotionPlanResponse &)> PlannerFn
planning_request_adapter
chomp::ChompParameters::setTrajectoryInitializationMethod
bool setTrajectoryInitializationMethod(std::string method)
planning_interface::MotionPlanDetailedResponse::error_code_
moveit::core::MoveItErrorCode error_code_
CLASS_LOADER_REGISTER_CLASS
CLASS_LOADER_REGISTER_CLASS(chomp::OptimizerAdapter, planning_request_adapter::PlanningRequestAdapter)
chomp::ChompParameters::min_clearance_
double min_clearance_
conversions.h
chomp::ChompParameters::learning_rate_
double learning_rate_
trajectory_tools.h
chomp::OptimizerAdapter::params_
chomp::ChompParameters params_
Definition: chomp_optimizer_adapter.cpp:276
planning_interface::MotionPlanResponse::planning_time_
double planning_time_
planning_scene
chomp::ChompParameters::smoothness_cost_acceleration_
double smoothness_cost_acceleration_
chomp::OptimizerAdapter::getDescription
std::string getDescription() const override
Definition: chomp_optimizer_adapter.cpp:236
ros::NodeHandle
chomp::ChompParameters::trajectory_initialization_method_
std::string trajectory_initialization_method_
planning_interface::MotionPlanDetailedResponse
planning_interface::MotionPlanDetailedResponse::processing_time_
std::vector< double > processing_time_
chomp_parameters.h


chomp_optimizer_adapter
Author(s): Raghavender Sahdev
autogenerated on Sat Mar 15 2025 02:26:09