MIRA
PathObjective.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_TOPOMAPPATHOBJECTIVE_H_
48 #define _MIRA_TOPOMAPPATHOBJECTIVE_H_
49 
50 
51 #include <navigation/tasks/PositionTask.h>
52 
53 #include <pilot/Pilot.h>
54 #include <pilot/Objective.h>
55 #include <pilot/PathObjectiveBase.h>
56 
57 #include <model/Marker.h>
58 
59 #include <maps/OccupancyGrid.h>
60 
61 #include <topomap/TopoMap.h>
62 #include <topomap/TopoMapPlanner.h>
65 
66 namespace viros { namespace topomap {
67 
69 
70 class PathObjective : public mira::pilot::PathObjectiveBase, private MetricCostmapTopoMapPlanner::IEventListener
71 {
72 MIRA_OBJECT(PathObjective);
73 
74 public:
75  template<typename Reflector>
76  void reflect(Reflector& r)
77  {
78  MIRA_REFLECT_BASE(r, mira::pilot::PathObjectiveBase);
79  mPlanner.reflect(r);
80 
81  r.method("waitForInitCostMapUpdate", &PathObjective::waitForInitCostMapUpdate, this,
82  "If called, the objective will wait for the next InitCostMap update before updating the path");
83 
84  r.method("setAdditionalLinkCosts", &PathObjective::setAdditionalLinkCosts,
85  this, "Define additional costs for a specific link.",
86  "fromGWName", "from this gateway", "Gateway1",
87  "toGWName", "to this gateway", "Gateway2",
88  "cost", "additional cost from gateway1 to gateway2", 5);
89  r.method("resetAllAdditionalLinkCosts", &PathObjective::resetAllAdditionalLinkCosts,
90  this, "Reset all additional gateways costs to zero.");
91  }
92 
93 
94  virtual void initialize();
95  virtual void setTask(boost::shared_ptr<navigation::Task> task);
96  virtual bool inGoalRegion(const Pose2& iRobotInMap, const Point2f& iGoalInMap, const boost::shared_ptr<navigation::PositionTask>& task);
97  virtual bool reachedTask();
98  virtual void update();
99  virtual void plan(Duration plantime);
100  virtual void prepareVote(float lookAheadTime);
101  virtual Vote vote(const mira::robot::PoseVelocityTrajectory& trajectory, float lookAheadTime);
102 
108  virtual bool haveValidPath();
109 
115  virtual void updateMetricPlannerGoal(mira::pilot::AbstractMetricPlannerPtr planner, bool initial);
116 
120  void setAdditionalLinkCosts(const std::string& fromGWName, const std::string& toGWName, double costs) {
121  mPlanner.setAdditionalLinkCosts(fromGWName, toGWName, costs);
122  }
123 
129  }
130 
136  }
137 
138 protected:
139 
140  void onInitCostMapChanged(ChannelRead<maps::GridMap<double>> data);
141 
142  virtual bool inGoalHysteresis() const;
143 
144  virtual bool causesWork(navigation::TaskPtr task);
145 
146 protected:
147 
149 
150  double mOffset;
151 
154 
160 
161  boost::shared_ptr<navigation::PositionTask> mTask;
162 
163  // stores whether the path can be used for voting
165 
166 
167 protected:
168 
169  void clearGoal();
170  void setGoal(const Point2f& goal, const std::string& frame);
171 
172  void computeLeafCosts(NodePtr node);
173  void localizeGoal(NodePtr node, const std::string& frame, const Point2i& cell, const Point2f& posinmap, MetricCostmapTopoMapPlanner::NodePositionList& nodes);
174  void localizeGoalWorld(NodePtr node, const Point2f& pos, const std::string& goalFrame, MetricCostmapTopoMapPlanner::NodePositionList& nodes, bool stayWithinMapTf);
175 
176 private:
177 
178  //void getBaseNodesWithMap(NodePtr node, std::vector<std::string>& nodes);
179 
180 private: // implementation if IEventListener
181  void onNodeChanged(NodePtr currentNode, GatewayNodePtr usedGateway, GatewayNodePtr nextGateway);
182 
183 protected:
184 
186 
189  boost::optional<uint32> mLastSequence;
190 
191 };
192 
194 
195 } } // namespace
196 
197 #endif
Definition: PathObjective.h:70
virtual bool inGoalRegion(const Pose2 &iRobotInMap, const Point2f &iGoalInMap, const boost::shared_ptr< navigation::PositionTask > &task)
std::list< NodePosition > NodePositionList
Definition: MetricCostmapTopoMapPlanner.h:143
virtual bool haveValidPath()
Is called in prepareVote() to check if the current path is valid and ready to be used.
void reflect(Reflector &r)
Definition: PathObjective.h:76
Channel< maps::GridMap< double > > mCurrentMapChannel
Definition: PathObjective.h:188
virtual void plan(Duration plantime)
Hybrid metric-topological planner for 2D costmaps.
Definition: MetricCostmapTopoMapPlanner.h:52
virtual Vote vote(const mira::robot::PoseVelocityTrajectory &trajectory, float lookAheadTime)
#define MIRA_REFLECT_BASE(reflector, BaseClass)
boost::shared_ptr< GatewayNode > GatewayNodePtr
Definition: TopoMapFwd.h:87
bool mHaveValidPath
Definition: PathObjective.h:164
void setGoal(const Point2f &goal, const std::string &frame)
virtual bool causesWork(navigation::TaskPtr task)
Channel< maps::GridMap< double > > mInitMapChannel
Definition: PathObjective.h:187
bool mWaitForInitCostMapUpdate
Definition: PathObjective.h:153
virtual void setTask(boost::shared_ptr< navigation::Task > task)
Channel< MetricCostmapTopoMapPlanner::NextSubGoal > mDbgNextSubGoalChannel
Definition: PathObjective.h:158
TopoMapPtr mTopoMap
Definition: PathObjective.h:148
void reflect(Reflector &r)
Definition: MetricCostmapTopoMapPlanner.h:61
virtual bool inGoalHysteresis() const
Channel< std::vector< Point2f > > mPathChannel
Definition: PathObjective.h:159
MetricCostmapTopoMapPlanner mPlanner
Definition: PathObjective.h:185
virtual void prepareVote(float lookAheadTime)
Definition: MetricCostmapTopoMapPlanner.h:145
double mOffset
Definition: PathObjective.h:150
Channel< maps::GridMap< uint8, 3 > > mDbgNavStatusChannel
Definition: PathObjective.h:156
boost::shared_ptr< navigation::PositionTask > mTask
Definition: PathObjective.h:161
boost::optional< uint32 > mLastSequence
Definition: PathObjective.h:189
void computeLeafCosts(NodePtr node)
void waitForInitCostMapUpdate()
If called the objective will wait for the next InitCostMap update before updating the path...
Definition: PathObjective.h:134
void setAdditionalLinkCosts(const std::string &fromGWName, const std::string &toGWName, double costs)
Definition: MetricCostmapTopoMapPlanner.h:266
void localizeGoalWorld(NodePtr node, const Point2f &pos, const std::string &goalFrame, MetricCostmapTopoMapPlanner::NodePositionList &nodes, bool stayWithinMapTf)
void resetAllAdditionalLinkCosts()
Reset all additional gateways costs to zero.
Definition: PathObjective.h:127
void localizeGoal(NodePtr node, const std::string &frame, const Point2i &cell, const Point2f &posinmap, MetricCostmapTopoMapPlanner::NodePositionList &nodes)
void setAdditionalLinkCosts(const std::string &fromGWName, const std::string &toGWName, double costs)
Define additional costs for a specific link.
Definition: PathObjective.h:120
bool mInGoalHysteresis
Definition: PathObjective.h:152
boost::shared_ptr< TopoMap > TopoMapPtr
Definition: TopoMapFwd.h:91
boost::shared_ptr< Node > NodePtr
Definition: TopoMapFwd.h:84
Definition: MetricCostmapTopoMapPlanner.h:45
void resetAllAdditionalLinkCosts()
Definition: MetricCostmapTopoMapPlanner.h:269
void onInitCostMapChanged(ChannelRead< maps::GridMap< double >> data)
Channel< std::vector< std::string > > mLocalizedNodesChannel
Definition: PathObjective.h:155
Channel< mira::model::Marker > mDbgMarkerChannel
Definition: PathObjective.h:157
virtual void updateMetricPlannerGoal(mira::pilot::AbstractMetricPlannerPtr planner, bool initial)
Is called in plan to set or update the goal position, if the goal is moving, e.g. ...