filter_base.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Southwest Research Institute
5  * Copyright (C) 2019, FUJISOFT
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions 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 copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the Southwest Research Institute, nor the names
17  * of its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef FILTER_BASE_H_
34 #define FILTER_BASE_H_
35 
36 #include <typeinfo>
37 #include "ros/assert.h"
38 #include "ros/console.h"
39 #include "ros/ros.h"
42 
44 {
45 
52 {
53 
58  struct Request
59  {
60  trajectory_msgs::JointTrajectory trajectory;
61  } request;
62 };
63 
123 template<typename T>
125  {
126  public:
127 
132  planning_request_adapter::PlanningRequestAdapter(), nh_("~"), configured_(false), filter_type_("FilterBase"), filter_name_(
133  "Unimplemented")
134  {
135 
136  }
137 
141  virtual ~FilterBase()
142  {
143  }
144  ;
145 
154  virtual bool update(const T& data_in, T& data_out)=0;
155 
160  std::string getType()
161  {
162  return filter_type_;
163  }
164  ;
165 
170  inline const std::string& getName()
171  {
172  return filter_name_;
173  }
174  ; // original FilterBase method
175 
176  protected:
177 
183  virtual bool configure()=0;
184 
188  std::string filter_name_;
189 
193  std::string filter_type_;
194 
199 
204 
205  protected:
206 
215  virtual bool adaptAndPlan(const PlannerFn &planner, const planning_scene::PlanningSceneConstPtr &planning_scene,
218  std::vector<std::size_t> &added_path_index) const
219  {
220 
221  // non const pointer to this
223 
224  // calling the configure method
225  if (!configured_ && p->configure())
226  {
227  p->configured_ = true;
228  }
229 
230  // moveit messages for saving trajectory data
231  moveit_msgs::RobotTrajectory robot_trajectory_in, robot_trajectory_out;
232  MessageAdapter trajectory_in, trajectory_out; // mapping structures
233 
234  // calling planner first
235  bool result = planner(planning_scene, req, res);
236 
237  // applying filter to planned trajectory
238  if (result && res.trajectory_)
239  {
240  // mapping arguments into message adapter struct
241  res.trajectory_->getRobotTrajectoryMsg(robot_trajectory_in);
242  trajectory_in.request.trajectory = robot_trajectory_in.joint_trajectory;
243 
244  // applying arm navigation filter to planned trajectory
245  p->update(trajectory_in, trajectory_out);
246 
247  // saving filtered trajectory into moveit message.
248  robot_trajectory_out.joint_trajectory = trajectory_out.request.trajectory;
249  res.trajectory_->setRobotTrajectoryMsg(planning_scene->getCurrentState(), robot_trajectory_out);
250 
251  }
252 
253  return result;
254  }
255 
260  virtual std::string getDescription() const
261  {
262  // non const pointer to this
264 
265  std::stringstream ss;
266  ss << "Trajectory filter '" << p->getName() << "' of type '" << p->getType() << "'";
267  return ss.str();
268  }
269  };
270 
271 }
272 
273 #endif /* FILTER_BASE_H_ */
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
Moveit Planning Request Adapter method. This basic implementation of the adaptAndPlan method calls th...
Definition: filter_base.h:215
std::string getType()
Original FilterBase method, return filter type.
Definition: filter_base.h:160
robot_trajectory::RobotTrajectoryPtr trajectory_
Arm navigation message type for trajectory filter.
Definition: filter_base.h:58
ros::NodeHandle nh_
Internal node handle (used for parameter lookup)
Definition: filter_base.h:203
std::string filter_name_
filter name
Definition: filter_base.h:188
Message Adapter structure serves as a stand-in for the arm navigation message type with which the fil...
Definition: filter_base.h:51
trajectory_msgs::JointTrajectory trajectory
Definition: filter_base.h:60
virtual bool configure()=0
FilterBase method for the sub class to configure the filter This function must be implemented in the ...
virtual std::string getDescription() const
Return description string.
Definition: filter_base.h:260
bool configured_
Holds filter configuration state.
Definition: filter_base.h:198
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
This version of the FilterBase<T> can be used to encapsulate the functionality from an arm navigation...
Definition: filter_base.h:124
moveit_msgs::MotionPlanRequest MotionPlanRequest
boost::function< bool(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, planning_interface::MotionPlanResponse &res)> PlannerFn
struct fsrobo_r_trajectory_filters::MessageAdapter::Request request
virtual bool update(const T &data_in, T &data_out)=0
Update the filter and return the data separately. This function must be implemented in the derived cl...
const std::string & getName()
Original FitlerBase Method.
Definition: filter_base.h:170


fsrobo_r_trajectory_filters
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:38