add_smoothing_filter.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, Southwest Research Institute
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 Southwest Research Institute 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: Chris Lewis */
36 
38 #include <moveit/version.h>
40 
42 #include <ros/ros.h> // required for NodeHandle
43 #include <ros/console.h>
44 
46 {
47 
48 class AddSmoothingFilter : public planning_request_adapter::PlanningRequestAdapter
49 {
50 public:
51 
52  static const std::string FILTER_PARAMETER_NAME_; // base name for filter parameters
53 
59  {
60  //in noetic and newer initialize will be called by external code
61 #if MOVEIT_VERSION_MAJOR < 1 || (MOVEIT_VERSION_MAJOR == 1 && MOVEIT_VERSION_MINOR < 1)
62  initialize(nh_);
63 #endif
64  }
65 
69 #if MOVEIT_VERSION_MAJOR >= 1 && MOVEIT_VERSION_MINOR >= 1
70  virtual void initialize(const ros::NodeHandle& node_handle) override
71 #else
72  virtual void initialize(const ros::NodeHandle& node_handle)
73 #endif
74  {
75  nh_ = node_handle;
76 
77  int num_coef;
78 
79  // set of default filter coefficients in case paramter, or its associated file, or its syntax is wrong
80  filter_coef_.push_back(0.25);
81  filter_coef_.push_back(0.5);
82  filter_coef_.push_back(1.0);
83  filter_coef_.push_back(0.5);
84  filter_coef_.push_back(0.25);
85 
86  // see if a new set of filter parameters is on the parameter server, if so, install them
88  ROS_INFO_STREAM("Param '" << FILTER_PARAMETER_NAME_ << "' was not set. Using default filter values " );
89  }
90  else{ // base filter name exists
91  std::vector<double> temp_coef;
92  nh_.getParam(filter_name_.c_str(),temp_coef); // no need to check for success
93  if(temp_coef.size()%2 == 1 && temp_coef.size()>2){ // need to have odd number of coefficients greater than 2
94  filter_coef_.clear();
95  for(int i=0; i< (int) temp_coef.size(); i++){ // install the filter coefficients
96  filter_coef_.push_back(temp_coef[i]);
97  }
98  }
99  else{
100  ROS_INFO_STREAM("Could not read filter, using default filter coefficients");
101  }
102  }
104  ROS_ERROR("Initialization error on smoothing filter. Requires an odd number of coeficients");
105 
106  };
107 
109  ~AddSmoothingFilter(){ };
110 
112  virtual std::string getDescription() const { return "Add Smoothing Trajectory Filter"; }
113 
121  virtual bool adaptAndPlan(const PlannerFn &planner,
122  const planning_scene::PlanningSceneConstPtr& planning_scene,
125  std::vector<std::size_t> &added_path_index) const
126  {
127  // do anything prior to calling the planner here
128  // ....
129  // IN this case nothing was done
130 
131  // call the nested planner or adapter
132  bool result = planner(planning_scene, req, res);
133 
134  // do anything after calling the nested planner or adapters here
135  if (result && res.trajectory_) // successful plan
136  {
137  ROS_DEBUG("Running '%s'", getDescription().c_str()); // inform the user
138  if (!smoothing_filter_.applyFilter(*res.trajectory_)) {// do the smoothing
139  ROS_ERROR("Smoothing filter of the solution path failed. Filter Not Initialized ");
140  }
141  }// end of if successful plan
142  return result;
143  };
144 
145 
146 private:
149  std::string filter_name_;
150  std::vector<double> filter_coef_;
151 
152 };
153 
154 const std::string AddSmoothingFilter::FILTER_PARAMETER_NAME_ = "/move_group/smoothing_filter_name";
155 
156 }
157 
industrial_trajectory_filters::AddSmoothingFilter
Definition: add_smoothing_filter.cpp:80
planning_interface::MotionPlanResponse
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
planning_request_adapter.h
ros.h
ROS_DEBUG
#define ROS_DEBUG(...)
industrial_trajectory_filters
Definition: filter_base.h:43
industrial_trajectory_filters::AddSmoothingFilter::adaptAndPlan
virtual bool adaptAndPlan(const PlannerFn &planner, const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, planning_interface::MotionPlanResponse &res, std::vector< std::size_t > &added_path_index) const
The work hourse of planning request adapters.
Definition: add_smoothing_filter.cpp:185
planning_request_adapter::PlanningRequestAdapter
industrial_trajectory_filters::AddSmoothingFilter::getDescription
virtual std::string getDescription() const
Returns a short description of this plugin.
Definition: add_smoothing_filter.cpp:176
console.h
planning_interface::MotionPlanResponse::trajectory_
robot_trajectory::RobotTrajectoryPtr trajectory_
industrial_trajectory_filters::AddSmoothingFilter::nh_
ros::NodeHandle nh_
Definition: add_smoothing_filter.cpp:207
ROS_ERROR
#define ROS_ERROR(...)
industrial_trajectory_filters::SmoothingTrajectoryFilter::init
bool init(std::vector< double > &coef)
Constructor.
Definition: smoothing_trajectory_filter.cpp:86
industrial_trajectory_filters::AddSmoothingFilter::initialize
virtual void initialize(const ros::NodeHandle &node_handle)
load parameters from a certain namespace
Definition: add_smoothing_filter.cpp:136
class_loader.hpp
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
planning_interface::MotionPlanRequest
moveit_msgs::MotionPlanRequest MotionPlanRequest
industrial_trajectory_filters::AddSmoothingFilter::filter_name_
std::string filter_name_
Definition: add_smoothing_filter.cpp:213
industrial_trajectory_filters::AddSmoothingFilter::~AddSmoothingFilter
~AddSmoothingFilter()
Destructor.
Definition: add_smoothing_filter.cpp:173
planning_request_adapter::PlanningRequestAdapter::PlanningRequestAdapter
PlanningRequestAdapter()
industrial_trajectory_filters::AddSmoothingFilter::smoothing_filter_
industrial_trajectory_filters::SmoothingTrajectoryFilter smoothing_filter_
Definition: add_smoothing_filter.cpp:212
planning_request_adapter::PlanningRequestAdapter::PlannerFn
boost::function< bool(const planning_scene::PlanningSceneConstPtr &, const planning_interface::MotionPlanRequest &, planning_interface::MotionPlanResponse &)> PlannerFn
smoothing_trajectory_filter.h
planning_request_adapter
CLASS_LOADER_REGISTER_CLASS
CLASS_LOADER_REGISTER_CLASS(industrial_trajectory_filters::AddSmoothingFilter, planning_request_adapter::PlanningRequestAdapter)
industrial_trajectory_filters::AddSmoothingFilter::filter_coef_
std::vector< double > filter_coef_
Definition: add_smoothing_filter.cpp:214
industrial_trajectory_filters::AddSmoothingFilter::FILTER_PARAMETER_NAME_
static const std::string FILTER_PARAMETER_NAME_
Definition: add_smoothing_filter.cpp:116
planning_scene
industrial_trajectory_filters::SmoothingTrajectoryFilter::applyFilter
bool applyFilter(robot_trajectory::RobotTrajectory &rob_trajectory) const
Definition: smoothing_trajectory_filter.cpp:110
industrial_trajectory_filters::AddSmoothingFilter::AddSmoothingFilter
AddSmoothingFilter()
Constructor AddSmoothingFilter is a planning request adapter plugin which post-processes The robot's ...
Definition: add_smoothing_filter.cpp:122
industrial_trajectory_filters::SmoothingTrajectoryFilter
This class filters the trajectory using a Finite Impluse Response filter.
Definition: smoothing_trajectory_filter.h:78
ros::NodeHandle


industrial_trajectory_filters
Author(s): Shaun Edwards, Jorge Nicho
autogenerated on Wed Mar 2 2022 00:24:49