state_space.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 VIGIR_FOOTSTEP_PLANNING_STATE_SPACE_H__
31 #define VIGIR_FOOTSTEP_PLANNING_STATE_SPACE_H__
32 
33 #include <ros/ros.h>
34 
35 #include <boost/thread/mutex.hpp>
36 
37 #include <tr1/unordered_set>
38 #include <tr1/hashtable.h>
39 
40 #include <sbpl/headers.h>
41 
42 #include <vigir_footstep_planning_lib/modeling/footstep.h>
43 #include <vigir_footstep_planning_lib/modeling/planning_state.h>
44 
46 
47 
48 
50 {
51 // specialization of hash<int,int>, similar to standard boost::hash on pairs?
52 struct IntPairHash{
53 public:
54  size_t operator()(std::pair<int, int> x) const throw() {
55  size_t seed = std::tr1::hash<int>()(x.first);
56  return std::tr1::hash<int>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
57  }
58 };
59 
60 struct StepCostPair {
61  StepCostPair(const PlanningState* state, const int cost)
62  : state(state)
63  , cost(cost)
64  {}
65 
66  bool operator < (const StepCostPair& other)
67  {
68  return cost < other.cost;
69  }
70 
71  const PlanningState* state;
72  const int cost;
73 };
74 
75 typedef std::vector<int> exp_states_t;
76 typedef exp_states_t::const_iterator exp_states_iter_t;
77 typedef std::tr1::unordered_set<std::pair<int,int>, IntPairHash > exp_states_2d_t;
78 typedef exp_states_2d_t::const_iterator exp_states_2d_iter_t;
79 
80 
81 
83 {
84 public:
85  StateSpace(const EnvironmentParameters& params, std::vector<int*>& state_ID2_index_mapping);
86 
87  virtual ~StateSpace();
88 
89  void reset();
90 
91  // typedefs
94 
95  void setFrameId(const std::string& frame_id);
96 
97  std::pair<int, int> updateGoal(const State& foot_left, const State& foot_right);
98  std::pair<int, int> updateStart(const State& foot_left, const State& right_right);
99  void setPlannerStartAndGoal(unsigned int start_foot_selection);
100 
106  bool getState(unsigned int id, State &s) const;
107 
108  bool getStartState(State &left, State &right) const;
109  bool getStartState(State &robot) const;
110  bool getGoalState(State &left, State &right) const;
111  bool getGoalState(State &robot) const;
112 
113  exp_states_iter_t getRandomStatesStart()
114  {
115  return ivRandomStates.begin();
116  }
117 
118  exp_states_iter_t getRandomStatesEnd()
119  {
120  return ivRandomStates.end();
121  }
122 
123 
125  PlanningState* createNewHashEntry(const State& s);
126 
134  PlanningState *createNewHashEntry(const PlanningState& s);
135 
137  PlanningState* getHashEntry(const State& s);
138 
143  PlanningState* getHashEntry(const PlanningState& s);
144 
145  PlanningState *createHashEntryIfNotExists(const PlanningState& s);
146 
151  bool closeToGoal(const PlanningState& from) const;
152 
157  bool closeToStart(const PlanningState& from) const;
158 
159 
161  bool getStepCost(const State& stand_foot, const State& swing_foot_before, const State& swing_foot_after, double& cost, double& risk) const;
162  bool getStepCost(const State& stand_foot, const State& swing_foot_before, const State& swing_foot_after, int& cost, int& risk) const;
163  bool getStepCost(const State& stand_foot, const State& swing_foot_before, const State& swing_foot_after, int& cost) const;
164 
166  std::string frame_id;
167 
171 
172  PlanningState* start_foot_left;
173  PlanningState* start_foot_right;
174 
177 
178  PlanningState* goal_foot_left;
179  PlanningState* goal_foot_right;
180 
183 
184  std::vector<int> ivStateArea;
185 
186  std::vector<int*>& state_ID2_index_mapping;
187 
192  std::vector<const PlanningState*> ivStateId2State;
193 
199  std::vector<PlanningState*>* ivpStateHash2State;
200 
203 
205  const int ivRandomNodeDist;
206 
207  exp_states_t ivRandomStates;
208 
209  mutable boost::shared_mutex hash_table_shared_mutex;
210 };
211 }
212 
213 #endif
boost::shared_mutex hash_table_shared_mutex
Definition: state_space.h:209
std::vector< const PlanningState * > ivStateId2State
Maps from an ID to the corresponding PlanningState. (Used in the SBPL to access a certain PlanningSta...
Definition: state_space.h:192
size_t operator()(std::pair< int, int > x) const
Definition: state_space.h:54
int ivIdPlanningStart
ID of Start and Goal foot chosen by planner.
Definition: state_space.h:169
XmlRpcServer s
exp_states_t ivRandomStates
random intermediate states for R*
Definition: state_space.h:207
boost::shared_ptr< StateSpace > Ptr
Definition: state_space.h:92
StepCostPair(const PlanningState *state, const int cost)
Definition: state_space.h:61
std::vector< int * > & state_ID2_index_mapping
Definition: state_space.h:186
boost::shared_ptr< StateSpace > ConstPtr
Definition: state_space.h:93
exp_states_t::const_iterator exp_states_iter_t
Definition: state_space.h:76
const int ivRandomNodeDist
distance of random neighbors for R* (discretized in cells)
Definition: state_space.h:205
const EnvironmentParameters & params
Definition: state_space.h:165
std::vector< int > exp_states_t
Definition: state_space.h:75
std::vector< PlanningState * > * ivpStateHash2State
Maps from a hash tag to a list of corresponding planning states. (Used in footstep_planner_environmen...
Definition: state_space.h:199
exp_states_2d_t::const_iterator exp_states_2d_iter_t
Definition: state_space.h:78
exp_states_iter_t getRandomStatesStart()
Definition: state_space.h:113
exp_states_iter_t getRandomStatesEnd()
Definition: state_space.h:118
bool ivHeuristicExpired
The heuristic function used by the planner.
Definition: state_space.h:202
std::tr1::unordered_set< std::pair< int, int >, IntPairHash > exp_states_2d_t
Definition: state_space.h:77


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