footstep_astar_solver.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
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
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 
37 #ifndef JSK_FOOTSTEP_PLANNER_FOOTSTEP_SOLVER_H_
38 #define JSK_FOOTSTEP_PLANNER_FOOTSTEP_SOLVER_H_
39 
42 
43 namespace jsk_footstep_planner
44 {
45  // Only available for FootstepState and FootstepGraph
46  // because close list behavior is specialized for the purpose
47  template <class GraphT>
48  class FootstepAStarSolver: public AStarSolver<GraphT>
49  {
50  public:
52  typedef typename GraphT::StateT State;
53  typedef typename GraphT::StateT::Ptr StatePtr;
54  typedef typename GraphT::Ptr GraphPtr;
56  typedef typename boost::function<void(FootstepAStarSolver&, GraphPtr)> ProfileFunction;
57  typedef typename std::priority_queue<SolverNodePtr,
58  std::vector<SolverNodePtr>,
59  std::greater<SolverNodePtr> > OpenList;
61  GraphPtr graph, size_t x_num, size_t y_num, size_t theta_num,
62  unsigned int profile_period = 1024,
63  double cost_weight = 1.0,
64  double heuristic_weight = 1.0):
65  footstep_close_list_(x_num, y_num, theta_num),
66  profile_period_(profile_period),
68  cost_weight_(cost_weight),
69  heuristic_weight_(heuristic_weight),
70  is_cancelled_(false),
71  AStarSolver<GraphT>(graph)
72  {
73 
74  }
75 
76  virtual double fn(SolverNodePtr n)
77  {
78  return cost_weight_ * gn(n) + heuristic_weight_ * hn(n);
79  }
80 
81 
82  virtual
83  std::vector<typename SolverNode<State, GraphT>::Ptr>
84  solve(const ros::WallDuration& timeout = ros::WallDuration(1000000000.0))
85  {
88  graph_->getStartState(),
89  0, graph_));
90  TransitionLimit::Ptr limit = graph_->getTransitionLimit();
91  bool lazy_projection = graph_->lazyProjection();
92  addToOpenList(start_state);
93  while (!is_cancelled_ && !isOpenListEmpty() && isOK(start_time, timeout)) {
94  SolverNodePtr target_node = popFromOpenList();
95  if (graph_->usePointCloudModel() && lazy_projection) {
96  unsigned int error_state;
97  StatePtr projected_state = graph_->projectFootstep(target_node->getState(),
98  error_state);
99  if (!projected_state) { // failed to project footstep
100  if (graph_->localMovement() && error_state == projection_state::close_to_success) {
101  // try local movement
102  std::vector<StatePtr> locally_moved_states;
103  {
104  std::vector<StatePtr> states_candidates
105  = graph_->localMoveFootstepState(target_node->getState());
106  for (int i = 0; i < states_candidates.size(); i ++) {
107  StatePtr tmp_state = graph_->projectFootstep(states_candidates[i],
108  error_state);
109  if (!!tmp_state) {
110  locally_moved_states.push_back(tmp_state);
111  }
112  }
113  }
114  if (locally_moved_states.size() > 0) {
115  std::vector<SolverNodePtr> locally_moved_nodes
116  = target_node->wrapWithSolverNodes(target_node->getParent(),
117  locally_moved_states);
118  for (size_t i = 0; i < locally_moved_nodes.size(); i++) {
119 
120  if (graph_->isSuccessable(locally_moved_nodes[i]->getState(),
121  target_node->getParent()->getState())) {
122  addToOpenList(locally_moved_nodes[i]);
123  }
124  }
125  }
126  }
127  continue; // back to the top of while loop
128  }
129  else {
130  if (target_node->getParent()) {
131  if (graph_->isSuccessable(projected_state, target_node->getParent()->getState())) {
132  target_node->setState(projected_state);
133  }
134  else {
135  continue;
136  }
137  }
138  else {
139  target_node->setState(projected_state);
140  }
141  }
142  } //if (graph_->usePointCloudModel() && lazy_projection) {
143  if (graph_->isGoal(target_node->getState())) {
145  profile_function_(*this, graph_);
146  }
147  std::vector<SolverNodePtr> result_path = target_node->getPathWithoutThis();
148  result_path.push_back(target_node);
149  return result_path;
150  }
151  else if (!findInCloseList(target_node->getState())) {
152  addToCloseList(target_node->getState());
153  std::vector<SolverNodePtr> next_nodes = target_node->expand(target_node, verbose_);
154  // Add to open list only if next_nodes is not in close list.
155  // We can do it thanks to FootstepStateDiscreteCloseList
156  for (size_t i = 0; i < next_nodes.size(); i++) {
157  SolverNodePtr next_node = next_nodes[i];
158  if (!findInCloseList(next_node->getState())) {
159  addToOpenList(next_node);
160  }
161  }
162  }
163  }
164  if (is_cancelled_) {
165  ROS_WARN("FootstepAStarSolver is cancelled");
166  }
167  // Failed to search
168  return std::vector<SolverNodePtr>();
169  }
170 
171  virtual void cancelSolve() {
172  is_cancelled_ = true;
173  ROS_FATAL("cancel planning");
174  }
175 
176  // Overtake closelist behavior from solver class
177  virtual bool findInCloseList(StatePtr s)
178  {
179  return footstep_close_list_.find(s);
180  }
181 
182  virtual void addToCloseList(StatePtr s)
183  {
185  }
186 
187  virtual OpenList getOpenList() { return open_list_; }
188 
189  virtual FootstepStateDiscreteCloseList getCloseList() { return footstep_close_list_; }
190  virtual void setProfileFunction(ProfileFunction f)
191  {
194  }
195 
196  virtual bool isOK(const ros::WallTime& start_time, const ros::WallDuration& timeout)
197  {
199  profile_function_(*this, graph_);
200  loop_counter_ = 0;
201  }
202  return (ros::ok() && (ros::WallTime::now() - start_time) < timeout);
203  }
204 
205  template <class PointT>
206  void closeListToPointCloud(pcl::PointCloud<PointT>& output_cloud)
207  {
209  }
210 
211  template <class PointT>
212  void openListToPointCloud(pcl::PointCloud<PointT>& output_cloud)
213  {
214  output_cloud.points.reserve(open_list_.size());
215  OpenList copied_open_list = open_list_;
216 
217  while (copied_open_list.size() > 0)
218  {
219  SolverNodePtr solver_node = copied_open_list.top();
220  StatePtr state = solver_node->getState();
221  PointT p = state->template toPoint<PointT>();
222  output_cloud.points.push_back(p);
223  copied_open_list.pop();
224  }
225  }
226 
227  void addToOpenList(SolverNodePtr node)
228  {
229  if (node->isRoot()) {
231  }
232  else {
233  if (node->getState()->crossCheck(
234  node->getParent()->getState())) {
236  }
237  }
238  }
239 
246 
247  protected:
248  unsigned int loop_counter_;
249  unsigned int profile_period_;
256  const double cost_weight_;
257  const double heuristic_weight_;
258  bool is_cancelled_;
259  };
260 }
261 
262 #endif
jsk_footstep_planner::FootstepAStarSolver::loop_counter_
unsigned int loop_counter_
Definition: footstep_astar_solver.h:312
jsk_footstep_planner::FootstepAStarSolver::cost_weight_
const double cost_weight_
Definition: footstep_astar_solver.h:320
astar_solver.h
jsk_footstep_planner::FootstepAStarSolver::setProfileFunction
virtual void setProfileFunction(ProfileFunction f)
Definition: footstep_astar_solver.h:254
boost::shared_ptr
jsk_footstep_planner::Solver
Definition: solver.h:79
i
int i
jsk_footstep_planner::FootstepStateDiscreteCloseList::find
bool find(FootstepState::Ptr state)
Definition: footstep_state_discrete_close_list.h:208
jsk_footstep_planner::FootstepAStarSolver::addToCloseList
virtual void addToCloseList(StatePtr s)
Definition: footstep_astar_solver.h:246
jsk_footstep_planner::FootstepAStarSolver::getOpenList
virtual OpenList getOpenList()
Definition: footstep_astar_solver.h:251
jsk_footstep_planner::FootstepAStarSolver::closeListToPointCloud
void closeListToPointCloud(pcl::PointCloud< PointT > &output_cloud)
Definition: footstep_astar_solver.h:270
jsk_footstep_planner::FootstepAStarSolver::addToOpenList
void addToOpenList(SolverNodePtr node)
Definition: footstep_astar_solver.h:291
jsk_footstep_planner::SolverNode::Ptr
boost::shared_ptr< SolverNode > Ptr
Definition: solver_node.h:117
jsk_footstep_planner::SolverNode
Definition: solver_node.h:82
jsk_footstep_planner::FootstepAStarSolver::fn
virtual double fn(SolverNodePtr n)
Definition: footstep_astar_solver.h:140
jsk_footstep_planner::AStarSolver::AStarSolver
AStarSolver(GraphPtr graph)
Definition: astar_solver.h:119
ros::ok
ROSCPP_DECL bool ok()
jsk_footstep_planner::BestFirstSearchSolver::popFromOpenList
virtual SolverNodePtr popFromOpenList()
Definition: best_first_search_solver.h:134
jsk_footstep_planner::FootstepAStarSolver::State
GraphT::StateT State
Definition: footstep_astar_solver.h:116
jsk_footstep_planner
Definition: ann_grid.h:50
jsk_footstep_planner::FootstepAStarSolver::SolverNodePtr
SolverNode< State, GraphT >::Ptr SolverNodePtr
Definition: footstep_astar_solver.h:119
jsk_footstep_planner::AStarSolver
Definition: astar_solver.h:77
jsk_footstep_planner::FootstepAStarSolver::OpenList
std::priority_queue< SolverNodePtr, std::vector< SolverNodePtr >, std::greater< SolverNodePtr > > OpenList
Definition: footstep_astar_solver.h:123
jsk_footstep_planner::FootstepAStarSolver::profile_period_
unsigned int profile_period_
Definition: footstep_astar_solver.h:313
jsk_footstep_planner::Solver::verbose_
bool verbose_
Definition: solver.h:202
jsk_footstep_planner::BestFirstSearchSolver::addToOpenList
virtual void addToOpenList(SolverNodePtr node)
Definition: best_first_search_solver.h:124
footstep_state_discrete_close_list.h
jsk_footstep_planner::AStarSolver::StatePtr
GraphT::StateT::Ptr StatePtr
Definition: astar_solver.h:113
ros::WallTime::now
static WallTime now()
PointT
pcl::PointXYZRGB PointT
jsk_footstep_planner::FootstepAStarSolver::cancelSolve
virtual void cancelSolve()
Definition: footstep_astar_solver.h:235
jsk_footstep_planner::FootstepAStarSolver::is_set_profile_function_
bool is_set_profile_function_
Definition: footstep_astar_solver.h:315
pose_array.p
p
Definition: pose_array.py:21
jsk_footstep_planner::AStarSolver::hn
virtual double hn(SolverNodePtr n)
Definition: astar_solver.h:130
graph
FootstepGraph::Ptr graph
Definition: footstep_planning_2d_interactive_demo.cpp:51
jsk_footstep_planner::FootstepStateDiscreteCloseList
FootstepStateDiscreteCloseList is a special clas to use for close list of FootstepState.
Definition: footstep_state_discrete_close_list.h:140
Solver
ROS_WARN
#define ROS_WARN(...)
start_time
start_time
ros::WallTime
jsk_footstep_planner::BestFirstSearchSolver::open_list_
OpenList open_list_
Definition: best_first_search_solver.h:146
jsk_footstep_planner::FootstepAStarSolver::solve
virtual std::vector< typename SolverNode< State, GraphT >::Ptr > solve(const ros::WallDuration &timeout=ros::WallDuration(1000000000.0))
Definition: footstep_astar_solver.h:148
ROS_FATAL
#define ROS_FATAL(...)
state
state
jsk_footstep_planner::FootstepAStarSolver::GraphPtr
GraphT::Ptr GraphPtr
Definition: footstep_astar_solver.h:118
jsk_footstep_planner::FootstepStateDiscreteCloseList::push_back
void push_back(FootstepState::Ptr state)
Definition: footstep_state_discrete_close_list.h:182
jsk_footstep_planner::FootstepAStarSolver::ProfileFunction
boost::function< void(FootstepAStarSolver &, GraphPtr)> ProfileFunction
Definition: footstep_astar_solver.h:120
jsk_footstep_planner::FootstepAStarSolver::Ptr
boost::shared_ptr< FootstepAStarSolver > Ptr
Definition: footstep_astar_solver.h:115
jsk_footstep_planner::BestFirstSearchSolver
Definition: best_first_search_solver.h:78
jsk_footstep_planner::FootstepAStarSolver::getCloseList
virtual FootstepStateDiscreteCloseList getCloseList()
Definition: footstep_astar_solver.h:253
jsk_footstep_planner::AStarSolver::gn
virtual double gn(SolverNodePtr n)
Definition: astar_solver.h:125
jsk_footstep_planner::FootstepAStarSolver::FootstepAStarSolver
FootstepAStarSolver(GraphPtr graph, size_t x_num, size_t y_num, size_t theta_num, unsigned int profile_period=1024, double cost_weight=1.0, double heuristic_weight=1.0)
Definition: footstep_astar_solver.h:124
jsk_footstep_planner::FootstepAStarSolver::footstep_close_list_
FootstepStateDiscreteCloseList footstep_close_list_
Definition: footstep_astar_solver.h:316
jsk_footstep_planner::BestFirstSearchSolver::isOpenListEmpty
virtual bool isOpenListEmpty()
Definition: best_first_search_solver.h:129
pose_array.s
s
Definition: pose_array.py:22
f
f
jsk_footstep_planner::FootstepAStarSolver::is_cancelled_
bool is_cancelled_
Definition: footstep_astar_solver.h:322
jsk_footstep_planner::FootstepAStarSolver::isOK
virtual bool isOK(const ros::WallTime &start_time, const ros::WallDuration &timeout)
Definition: footstep_astar_solver.h:260
jsk_footstep_planner::FootstepAStarSolver::StatePtr
GraphT::StateT::Ptr StatePtr
Definition: footstep_astar_solver.h:117
jsk_footstep_planner::FootstepStateDiscreteCloseList::toPointCloud
void toPointCloud(pcl::PointCloud< PointT > &output)
Definition: footstep_state_discrete_close_list.h:226
jsk_footstep_planner::FootstepAStarSolver::heuristic_weight_
const double heuristic_weight_
Definition: footstep_astar_solver.h:321
jsk_footstep_planner::FootstepAStarSolver::openListToPointCloud
void openListToPointCloud(pcl::PointCloud< PointT > &output_cloud)
Definition: footstep_astar_solver.h:276
ros::WallDuration
jsk_footstep_planner::Solver::graph_
GraphPtr graph_
Definition: solver.h:201
jsk_footstep_planner::projection_state::close_to_success
const unsigned int close_to_success
Definition: footstep_state.h:129
jsk_footstep_planner::FootstepAStarSolver::profile_function_
ProfileFunction profile_function_
Definition: footstep_astar_solver.h:314
jsk_footstep_planner::FootstepAStarSolver::findInCloseList
virtual bool findInCloseList(StatePtr s)
Definition: footstep_astar_solver.h:241


jsk_footstep_planner
Author(s): Ryohei Ueda
autogenerated on Wed Jan 24 2024 04:05:29