helper.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2017, Alexander Stumpf, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Simulation, Systems Optimization and Robotics
13 // group, TU Darmstadt nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef VIGIR_FOOTSTEP_PLANNING_LIB_HELPER_H__
30 #define VIGIR_FOOTSTEP_PLANNING_LIB_HELPER_H__
31 
32 #include <ros/ros.h>
33 #include <tf/tf.h>
34 
35 #include <boost/function.hpp>
36 #include <boost/bind.hpp>
37 
40 
41 #include <nav_msgs/OccupancyGrid.h>
42 
43 #include <vigir_generic_params/generic_params_msgs.h>
44 
45 #include <vigir_footstep_planning_msgs/footstep_planning_msgs.h>
46 
47 
48 
50 {
51 template <typename ActionSpec>
53  : public actionlib::SimpleActionClient<ActionSpec>
54 {
55 public:
56  // typedefs
59 
60  SimpleActionClient(ros::NodeHandle nh, std::string name, bool spin_thread = true)
61  : actionlib::SimpleActionClient<ActionSpec>(nh, name, spin_thread)
62  {
63  }
64 
65  static Ptr create(ros::NodeHandle nh, std::string name, bool spin_thread = true)
66  {
67  return Ptr(new SimpleActionClient<ActionSpec>(nh, name, spin_thread));
68  }
69 };
70 
71 template <typename ActionSpec>
73  : public actionlib::SimpleActionServer<ActionSpec>
74 {
75 public:
76  // typedefs
79  typedef boost::function<void ()> ExecuteCallback;
80  typedef boost::function<void ()> PreemptCallback;
81 
82  SimpleActionServer(ros::NodeHandle nh, std::string name, bool auto_start)
83  : actionlib::SimpleActionServer<ActionSpec>(nh, name, auto_start)
84  {
85  }
86 
87  template <typename S> void finish(const S& result)
88  {
89  if (hasError(result.status))
90  this->setAborted(result, toString(result.status));
91  else
92  this->setSucceeded(result, toString(result.status));
93  }
94 
95  void preempt()
96  {
98  }
99 
100  static Ptr create(ros::NodeHandle nh, std::string name, bool auto_start, ExecuteCallback execute_cb, PreemptCallback preempt_cb = PreemptCallback())
101  {
102  Ptr as(new SimpleActionServer<ActionSpec>(nh, name, false));
103 
104  as->registerGoalCallback(execute_cb);
105 
106  if (!preempt_cb.empty())
107  preempt_cb = boost::bind(&SimpleActionServer::preempt, as.get());
108  as->registerPreemptCallback(preempt_cb);
109 
110  if (auto_start)
111  as->start();
112 
113  return as;
114  }
115 };
116 
117 msgs::ErrorStatus determineStartFeetPose(msgs::Feet& start_feet, ros::ServiceClient& generate_feet_pose_client, const std_msgs::Header& header);
118 msgs::ErrorStatus determineGoalFeetPose(msgs::Feet& goal_feet, ros::ServiceClient& generate_feet_pose_client, const geometry_msgs::PoseStamped& goal_pose);
119 
120 msgs::ErrorStatus transform(msgs::Foot& foot, ros::ServiceClient& transform_foot_pose_client, const std::string& target_frame);
121 msgs::ErrorStatus transform(msgs::Feet& feet, ros::ServiceClient& transform_feet_poses_client, const std::string& target_frame);
122 msgs::ErrorStatus transform(msgs::StepPlan& step_plan, ros::ServiceClient& transform_step_plan_client, const std::string& target_frame);
123 
124 template <typename T>
125 msgs::ErrorStatus transformToPlannerFrame(T& p, ros::ServiceClient& foot_pose_transformer_client)
126 {
127  return transform(p, foot_pose_transformer_client, "planner");
128 }
129 
130 template <typename T>
131 msgs::ErrorStatus transformToRobotFrame(T& p, ros::ServiceClient& foot_pose_transformer_client)
132 {
133  return transform(p, foot_pose_transformer_client, "robot");
134 }
135 
136 
137 
138 // loading of common parameters
139 bool getXYZ(ros::NodeHandle& nh, const std::string name, geometry_msgs::Vector3& val);
140 bool getRPY(ros::NodeHandle& nh, const std::string name, geometry_msgs::Vector3& val);
141 
142 bool getFootSize(ros::NodeHandle& nh, geometry_msgs::Vector3& foot_size);
143 bool getUpperBodySize(ros::NodeHandle& nh, geometry_msgs::Vector3& upper_body_size);
144 bool getUpperBodyOriginShift(ros::NodeHandle& nh, geometry_msgs::Vector3& upper_body_origin_shift);
145 
146 
147 
148 bool getGridMapCoords(const nav_msgs::OccupancyGrid& map, double x, double y, int& map_x, int& map_y);
149 bool getGridMapIndex(const nav_msgs::OccupancyGrid& map, double x, double y, int& idx);
150 
151 
152 
153 inline std::string& strip(std::string& s, const char c) { return vigir_generic_params::strip(s, c); }
154 inline std::string strip_const(const std::string& s, const char c) { return vigir_generic_params::strip_const(s, c); }
155 }
156 
157 #endif
bool getFootSize(ros::NodeHandle &nh, geometry_msgs::Vector3 &foot_size)
Definition: helper.cpp:130
bool getRPY(ros::NodeHandle &nh, const std::string name, geometry_msgs::Vector3 &val)
Definition: helper.cpp:116
boost::function< void()> PreemptCallback
Definition: helper.h:80
bool getUpperBodyOriginShift(ros::NodeHandle &nh, geometry_msgs::Vector3 &upper_body_origin_shift)
Definition: helper.cpp:140
static Ptr create(ros::NodeHandle nh, std::string name, bool auto_start, ExecuteCallback execute_cb, PreemptCallback preempt_cb=PreemptCallback())
Definition: helper.h:100
boost::shared_ptr< SimpleActionServer< ActionSpec > > Ptr
Definition: helper.h:77
std::string strip_const(const std::string &s, const char c)
Definition: helper.h:154
msgs::ErrorStatus determineStartFeetPose(msgs::Feet &start_feet, ros::ServiceClient &generate_feet_pose_client, const std_msgs::Header &header)
Definition: helper.cpp:5
boost::shared_ptr< SimpleActionClient > Ptr
Definition: helper.h:57
msgs::ErrorStatus transformToPlannerFrame(T &p, ros::ServiceClient &foot_pose_transformer_client)
Definition: helper.h:125
boost::shared_ptr< const SimpleActionClient > ConstPtr
Definition: helper.h:58
bool getGridMapCoords(const nav_msgs::OccupancyGrid &map, double x, double y, int &map_x, int &map_y)
Definition: helper.cpp:147
TFSIMD_FORCE_INLINE const tfScalar & y() const
bool getGridMapIndex(const nav_msgs::OccupancyGrid &map, double x, double y, int &idx)
Definition: helper.cpp:159
static Ptr create(ros::NodeHandle nh, std::string name, bool spin_thread=true)
Definition: helper.h:65
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
bool getUpperBodySize(ros::NodeHandle &nh, geometry_msgs::Vector3 &upper_body_size)
Definition: helper.cpp:135
TFSIMD_FORCE_INLINE const tfScalar & x() const
SimpleActionServer(ros::NodeHandle nh, std::string name, bool auto_start)
Definition: helper.h:82
boost::shared_ptr< const SimpleActionServer< ActionSpec > > ConstPtr
Definition: helper.h:78
msgs::ErrorStatus determineGoalFeetPose(msgs::Feet &goal_feet, ros::ServiceClient &generate_feet_pose_client, const geometry_msgs::PoseStamped &goal_pose)
Definition: helper.cpp:43
boost::function< void()> ExecuteCallback
Definition: helper.h:79
std::string & strip(std::string &s, const char c)
Definition: helper.h:153
msgs::ErrorStatus transformToRobotFrame(T &p, ros::ServiceClient &foot_pose_transformer_client)
Definition: helper.h:131
SimpleActionClient(ros::NodeHandle nh, std::string name, bool spin_thread=true)
Definition: helper.h:60
bool getXYZ(ros::NodeHandle &nh, const std::string name, geometry_msgs::Vector3 &val)
Definition: helper.cpp:102
msgs::ErrorStatus transform(msgs::Foot &foot, ros::ServiceClient &transform_foot_pose_client, const std::string &target_frame)
Definition: helper.cpp:58


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33