footstep_planner.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2018, Alexander Stumpf, TU Darmstadt
3 // Based on http://wiki.ros.org/footstep_planner by Johannes Garimort and Armin Hornung
4 // All rights reserved.
5 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of the Simulation, Systems Optimization and Robotics
14 // group, TU Darmstadt nor the names of its contributors may be used to
15 // endorse or promote products derived from this software without
16 // specific prior written permission.
17 
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
22 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //=================================================================================================
29 
30 #ifndef FOOTSTEP_PLANNER_H__
31 #define FOOTSTEP_PLANNER_H__
32 
33 #include <ros/ros.h>
34 #include <tf/tf.h>
35 
36 #include <assert.h>
37 #include <time.h>
38 
39 #include <boost/thread.hpp>
40 #include <boost/thread/mutex.hpp>
41 #include <boost/function.hpp>
42 
43 #include <XmlRpcValue.h>
44 #include <XmlRpcException.h>
45 
47 
48 #include <geometry_msgs/Pose.h>
49 #include <geometry_msgs/PoseStamped.h>
50 #include <geometry_msgs/PoseWithCovarianceStamped.h>
51 #include <nav_msgs/Path.h>
52 #include <nav_msgs/OccupancyGrid.h>
53 #include <sensor_msgs/PointCloud.h>
54 #include <sensor_msgs/PointCloud2.h>
55 #include <visualization_msgs/Marker.h>
56 #include <visualization_msgs/MarkerArray.h>
57 
58 #include <vigir_generic_params/generic_params_msgs.h>
59 #include <vigir_generic_params/parameter_manager.h>
60 
61 #include <vigir_pluginlib/plugin_manager.h>
62 
63 #include <vigir_footstep_planning_msgs/footstep_planning_msgs.h>
64 
65 #include <vigir_footstep_planning_lib/math.h>
66 #include <vigir_footstep_planning_lib/modeling/footstep.h>
67 #include <vigir_footstep_planning_lib/modeling/state.h>
68 
69 #include <vigir_footstep_planning_plugins/plugin_aggregators/step_cost_estimator.h>
70 #include <vigir_footstep_planning_plugins/plugin_aggregators/heuristic.h>
71 #include <vigir_footstep_planning_plugins/plugin_aggregators/post_processor.h>
72 #include <vigir_footstep_planning_plugins/plugin_aggregators/robot_model.h>
73 #include <vigir_footstep_planning_plugins/plugin_aggregators/state_generator.h>
74 #include <vigir_footstep_planning_plugins/plugin_aggregators/world_model.h>
75 #include <vigir_footstep_planning_plugins/plugins/step_plan_msg_plugin.h>
76 
78 
81 
82 
83 
85 {
86 typedef std::vector<State>::const_iterator state_iter_t;
87 
93 {
94 public:
95  typedef boost::function<void (msgs::StepPlanRequestService::Response)> ResultCB;
96  typedef boost::function<void (msgs::PlanningFeedback)> FeedbackCB;
97  typedef boost::function<void ()> PreemptCB;
98 
100  virtual ~FootstepPlanner();
101 
102  bool isPlanning() const;
103 
104  bool setParams(const vigir_generic_params::ParameterSet& params);
105 
106  msgs::ErrorStatus updateFoot(msgs::Foot& foot, uint8_t mode, bool transform = true) const;
107  msgs::ErrorStatus updateFeet(msgs::Feet& feet, uint8_t mode, bool transform = true) const;
108  msgs::ErrorStatus updateStepPlan(msgs::StepPlan& result, uint8_t mode, const std::string& param_set_name = std::string(), bool transform = true) const;
109 
110  msgs::ErrorStatus stepPlanRequest(msgs::StepPlanRequestService::Request& req, ResultCB result_cb = ResultCB(), FeedbackCB feedback_cb = FeedbackCB(), PreemptCB preempt_cb = PreemptCB());
112  bool stepPlanRequestService(msgs::StepPlanRequestService::Request& req, msgs::StepPlanRequestService::Response& resp);
113 
115  void preemptPlanning();
116 
117  // typedefs
120 
121 protected:
129  msgs::ErrorStatus planSteps(msgs::StepPlanRequestService::Request& req);
130 
132  msgs::ErrorStatus planPattern(msgs::StepPlanRequestService::Request& req);
133  msgs::ErrorStatus finalizeAndAddStepToPlan(State& s, const msgs::PatternParameters& env_params, bool change_z = true);
134 
136  bool finalizeStepPlan(msgs::StepPlanRequestService::Request& req, msgs::StepPlanRequestService::Response& resp, bool post_process);
137 
139  void startPlanning(msgs::StepPlanRequestService::Request& req);
141  void doPlanning(msgs::StepPlanRequestService::Request& req);
142 
143  bool findNearestValidState(State& s) const;
144 
145  bool checkRobotCollision(const State& left_foot, const State& right_foot, bool& left, bool& right) const;
146 
152  bool setStart(const State& left_foot, const State& right_foot, bool ignore_collision = false);
153 
159  bool setStart(const msgs::StepPlanRequest& req, bool ignore_collision = false);
160 
166  bool setGoal(const State& left_foot, const State& right_foot, bool ignore_collision = false);
167 
173  bool setGoal(const msgs::StepPlanRequest& req, bool ignore_collision = false);
174 
176  double getPathCosts() const { return ivPathCost; }
177 
179  size_t getNumExpandedStates() const
180  {
181  return ivPlannerPtr->get_n_expands();
182  }
183 
185  size_t getNumFootPoses() const { return ivPath.size(); }
186 
187  state_iter_t getPathBegin() const { return ivPath.begin(); }
188  state_iter_t getPathEnd() const { return ivPath.end(); }
189 
191  int getPathSize() { return ivPath.size(); }
192 
193  State getStartFootLeft() { return ivStartFootLeft; }
195 
197  void reset();
198 
200  void resetTotally();
201 
203  bool pathExists() { return (bool)ivPath.size(); }
204 
209  bool pathIsNew(const std::vector<int>& new_path);
210 
215  bool extractPath(const std::vector<int>& state_ids);
216 
223  bool plan(ReplanParams& params);
224 
226  State getFootPose(const State& robot, Leg leg, double dx, double dy, double dyaw);
227  State getFootPose(const State& robot, Leg leg);
228 
230  void setPlanner();
231 
232  // publisher
234 
235  mutable boost::recursive_mutex planner_mutex;
236  boost::thread planning_thread;
237 
238  ResultCB result_cb;
239  FeedbackCB feedback_cb;
240  PreemptCB preempt_cb;
241 
244 
245  std::vector<State> ivPath;
246 
251 
252  // local instance of foot pose transformer
254 
255  // Parameters
256  std::string frame_id;
258  unsigned int start_foot_selection;
260 
262 
263  // robot parameters
265 
266  double ivPathCost;
267 
268  std::vector<int> ivPlanningStatesIds;
269 
270  pcl::PointCloud<pcl::PointXYZI>::Ptr ivCheckedFootContactSupport;
271 
272  // counter to be used as sequence number
273  unsigned int step_plan_uid;
274 };
275 }
276 
277 #endif
bool pathIsNew(const std::vector< int > &new_path)
std::vector< State >::const_iterator state_iter_t
A class to control the interaction between ROS and the footstep planner.
void preemptPlanning()
stops thread running planning
msgs::ErrorStatus planPattern(msgs::StepPlanRequestService::Request &req)
plans stepping
bool checkRobotCollision(const State &left_foot, const State &right_foot, bool &left, bool &right) const
boost::function< void(msgs::PlanningFeedback)> FeedbackCB
boost::shared_ptr< SBPLPlanner > ivPlannerPtr
State getFootPose(const State &robot, Leg leg, double dx, double dy, double dyaw)
Returns the foot pose of a leg for a given robot pose.
boost::shared_ptr< const FootstepPlanner > ConstPtr
bool extractPath(const std::vector< int > &state_ids)
Extracts the path (list of foot poses) from a list of state IDs calculated by the SBPL...
msgs::ErrorStatus updateFeet(msgs::Feet &feet, uint8_t mode, bool transform=true) const
msgs::ErrorStatus updateFoot(msgs::Foot &foot, uint8_t mode, bool transform=true) const
boost::function< void(msgs::StepPlanRequestService::Response)> ResultCB
void reset()
Reset the previous planning information.
msgs::ErrorStatus updateStepPlan(msgs::StepPlan &result, uint8_t mode, const std::string &param_set_name=std::string(), bool transform=true) const
bool setStart(const State &left_foot, const State &right_foot, bool ignore_collision=false)
Sets the start pose as position of left and right footsteps.
bool setParams(const vigir_generic_params::ParameterSet &params)
bool finalizeStepPlan(msgs::StepPlanRequestService::Request &req, msgs::StepPlanRequestService::Response &resp, bool post_process)
extracts step plan response from planning result
bool setGoal(const State &left_foot, const State &right_foot, bool ignore_collision=false)
Sets the goal pose as position of left and right footsteps.
msgs::ErrorStatus planSteps(msgs::StepPlanRequestService::Request &req)
Start a planning task from scratch (will delete information of previous planning tasks). Map and start, goal poses need to be set beforehand.
void resetTotally()
Reset and reinitialize the environment.
msgs::ErrorStatus stepPlanRequest(msgs::StepPlanRequestService::Request &req, ResultCB result_cb=ResultCB(), FeedbackCB feedback_cb=FeedbackCB(), PreemptCB preempt_cb=PreemptCB())
void setPlanner()
Sets the planning algorithm used by SBPL.
boost::shared_ptr< FootstepPlannerEnvironment > ivPlannerEnvironmentPtr
boost::shared_ptr< FootstepPlanner > Ptr
void startPlanning(msgs::StepPlanRequestService::Request &req)
: starts planning in a new thread
msgs::ErrorStatus finalizeAndAddStepToPlan(State &s, const msgs::PatternParameters &env_params, bool change_z=true)
bool stepPlanRequestService(msgs::StepPlanRequestService::Request &req, msgs::StepPlanRequestService::Response &resp)
Service handle to plan footsteps.
bool plan(ReplanParams &params)
Starts the planning task in the underlying SBPL.
pcl::PointCloud< pcl::PointXYZI >::Ptr ivCheckedFootContactSupport
void doPlanning(msgs::StepPlanRequestService::Request &req)
: method used in seperate thread


vigir_footstep_planner
Author(s): Alexander Stumpf
autogenerated on Sun Nov 17 2019 03:29:59