32 #include <model/Marker.h> 35 #include <maps/CostMap.h> 36 #include <pilot/AbstractMetricPlanner.h> 45 namespace viros {
namespace topomap {
54 typedef std::vector<std::tuple<GatewayNodePtr, GatewayNodePtr, double>> GatewayHops;
60 template<
typename Reflector>
63 mira::serialization::Array<PlannerContext> plannerCtx(mPlannerCtx,3);
64 r.property(
"PlannerCtx", plannerCtx,
"");
65 r.property(
"GatewayWidth", mGatewayWidth,
"goal width of gateways in cells", 2);
66 r.property(
"EnableReplanning", mEnableReplanning,
"Specifies whether global replanning within the topological structure is enabled.",
true);
67 r.property(
"TolerableDetourBeforeReplan", mTolerableDetourBeforeReplan,
68 "The allowed detour in meter caused by significant changes in the environment." 69 "If the detour becomes larger than this threshold, a global replanning" 70 "within the topological structure is triggered after the time span specified" 71 "below. (default 10.0 m)", 10.0f);
72 r.property(
"TimeUntilReplan", mTimeUntilReplan,
73 "Time duration, until replanning is triggered when the current path " 74 "became sub-optimal after significant changes in the environment.",
76 r.property(
"MaxPlanningTime", mMaxPlanningTime,
77 "How long should we plan until we decide that we can not plan a path",
79 r.property(
"AllowGoalsWithInfiniteCosts", mAllowGoalsWithInfiniteCosts,
80 "If true planning to goals with infinite costs is allowed. " 81 "This is necessary for moving goals (e.g. follow objective).",
83 r.member(
"CachePath", mCachePath,
84 "The path for caching preplanned maps to enable faster bootup. " 85 "The directory will be created if it does not exist.",
"cache");
91 mira::pilot::AbstractMetricPlannerPtr
planner;
92 mira::maps::CostMap
map;
110 template<
typename Reflector>
113 r.property(
"Planner",
planner,
"");
114 r.roproperty(
"Active",
active,
"");
167 template<
typename Reflector>
172 r.member(
"Costs",
costs,
"");
174 r.member(
"Hops",
hops,
"");
178 costs(
std::numeric_limits<double>::max()),
180 hops(
std::numeric_limits<int>::max()) {}
186 costs = std::numeric_limits<double>::max();
188 hops = std::numeric_limits<int>::max();
192 return n ?
n->getFullName() :
"<null>";
195 return gn ?
gn->getFullName() :
"<null>";
201 const std::string& name);
216 mira::pilot::AbstractMetricPlanner::Carrot
getCarrot(
const Point2f& pos,
int count,
float length = 1e10f)
const;
223 mEventListener = listener;
229 return mCurrentPlanner;
238 mira::maps::GridMap<double>
getNavFunction(
bool ignoreDoubleBuffer =
false);
239 mira::maps::GridMap<uint8,3>
dumpNavStatus(
bool actualMap =
false,
240 bool costsInGoalRegion =
true);
247 typedef boost::function<void(mira::pilot::AbstractMetricPlannerPtr, bool)>
UpdateGoalFn;
251 void update(
const maps::CostMap& map);
254 void update(
const maps::CostMap& map,
const maps::DirtyRegions& dirty);
259 void plan(
const mira::maps::CostMap& curCostmap,
274 mDbgMarkerChannel = c;
277 mDbgNextSubGoalChannel = c;
282 void drawGateway(mira::model::Marker& marker, std::tuple<GatewayNodePtr, GatewayNodePtr, double> gw);
283 bool traverseLinks(GatewayHops& gatewayHops,
NodeSet& localizedNodes,
GatewayNodePtr node,
int hops);
285 void planCurrentPlanner();
288 void handleReplanningLastCostBased(
const mira::maps::CostMap& curCostmap);
289 double getCurrentPlannerCosts(
const Point2f& p,
bool ignoreDoubleBuffer);
292 void prepareVisitedList();
295 void determineLocalizedNodesWithGoal(
const NodePositionList& localizedNodes);
298 NextSubGoal& oBestSubGoal,
299 NextSubGoal& oSecondBestSubGoal);
300 void determineBestTopoSubGoals(
const GatewayNodeSet& gatewayNodes,
302 NextSubGoal& oBestSubGoal,
303 NextSubGoal& oSecondBestSubGoal);
304 bool isBetterThanSubGoal(
double costs,
int hops,
305 const NextSubGoal& subGoal);
308 double remainingcosts,
310 NextSubGoal& oSubGoal);
312 void handleNextPlanner();
313 void prepareNextPlanner();
315 bool isInGoalNode()
const;
316 bool isGoalNodeWithLocalization(
NodePtr n)
const;
324 void computeLeafCosts(
NodePtr node);
326 void updateNodeCosts(
NodePtr node,
const Stamped<mira::maps::GridMap<double>>& costmap);
327 void computeNodeCosts(
NodePtr node,
const Stamped<mira::maps::GridMap<double>>& costmap,
bool useCache);
332 void readNavFuncFromCache(
const std::string& gatewayName,
333 const Stamped<mira::maps::GridMap<double>>& costmap,
335 maps::CostMap& navFn,
337 std::string& cacheFileName);
338 void writeNavFuncToCache(
const maps::CostMap& navFn,
339 const std::string& md5sum,
340 std::string& cacheFileName);
365 bool mAllowGoalsWithInfiniteCosts;
367 std::string dbgTimeNow;
369 bool mEnableReplanning;
370 float mTolerableDetourBeforeReplan;
372 Time mReplanTimeoutStart;
375 Time mLastValidPlanningTime;
void reset()
Definition: MetricCostmapTopoMapPlanner.h:182
std::string getGatewayNodeName()
Definition: MetricCostmapTopoMapPlanner.h:194
void reset()
Definition: MetricCostmapTopoMapPlanner.h:103
std::list< NodePosition > NodePositionList
Definition: MetricCostmapTopoMapPlanner.h:143
mira::maps::CostMap map
Definition: MetricCostmapTopoMapPlanner.h:92
void resetCostMaps()
Reset all cost maps to the inital values.
PlannerContextPtr getCurrentPlanner()
Definition: MetricCostmapTopoMapPlanner.h:227
double getValueFiltered(const Point2f &worldPos) const
Definition: MetricCostmapTopoMapPlanner.h:90
boost::filesystem::path Path
PlannerContextPtr getNextPlanner()
Definition: MetricCostmapTopoMapPlanner.h:231
Hybrid metric-topological planner for 2D costmaps.
Definition: MetricCostmapTopoMapPlanner.h:52
NodePtr node
Definition: MetricCostmapTopoMapPlanner.h:139
mira::maps::GridMap< double > getNavFunction(bool ignoreDoubleBuffer=false)
Setter< T > setter(void(*f)(const T &))
boost::shared_ptr< GatewayNode > GatewayNodePtr
Definition: TopoMapFwd.h:87
void setGoal(const NodePositionList &goalNodes, UpdateGoalFn updateGoalFn)
NodePosition()
Definition: MetricCostmapTopoMapPlanner.h:136
NodePosition(NodePtr node, const std::string &frame, const Point2f &pos)
Definition: MetricCostmapTopoMapPlanner.h:137
static void printNextSubGoal(const NextSubGoal &nsg, const std::string &name)
void reflect(Reflector &r)
Definition: MetricCostmapTopoMapPlanner.h:111
PlannerContext * PlannerContextPtr
Definition: MetricCostmapTopoMapPlanner.h:118
mira::pilot::AbstractMetricPlannerPtr planner
Definition: MetricCostmapTopoMapPlanner.h:91
void update(const maps::CostMap &map)
update the planning context with the current costmap (entire area)
std::set< NodePtr, shared_ptr_sort< Node > > NodeSet
Definition: TopoMapFwd.h:101
Definition: MetricCostmapTopoMapPlanner.h:134
MetricCostmapTopoMapPlanner()
friend struct ResetCostMapsVisitor
Definition: MetricCostmapTopoMapPlanner.h:329
void setEventListener(IEventListener *listener)
Definition: MetricCostmapTopoMapPlanner.h:222
double remainingcosts
Definition: MetricCostmapTopoMapPlanner.h:164
void setDebugNextSubGoalChannel(Channel< NextSubGoal > c)
Definition: MetricCostmapTopoMapPlanner.h:276
void setDebugMarkerChannel(Channel< mira::model::Marker > c)
Definition: MetricCostmapTopoMapPlanner.h:273
void reflect(Reflector &r)
Definition: MetricCostmapTopoMapPlanner.h:61
mira::pilot::AbstractMetricPlanner::Carrot getCarrot(const Point2f &pos, int count, float length=1e10f) const
boost::shared_ptr< RegionAttribute > RegionAttributePtr
Definition: TopoMapFwd.h:77
Point2f pos
Definition: MetricCostmapTopoMapPlanner.h:141
Definition: MetricCostmapTopoMapPlanner.h:160
void plan(const mira::maps::CostMap &curCostmap, const Point2f &robotPos, const NodePositionList &localizedNodes, Duration plantime)
void initialize(TopoMapPtr map, Authority *authority)
initializes the planner with the given topo map
Getter< T > getter(T(*f)())
virtual ~IEventListener()
Definition: MetricCostmapTopoMapPlanner.h:149
mira::maps::DirtyRegions dirty
Definition: MetricCostmapTopoMapPlanner.h:93
boost::shared_ptr< Gateway > GatewayPtr
Definition: TopoMapFwd.h:86
Definition: MetricCostmapTopoMapPlanner.h:145
void setAdditionalLinkCosts(const std::string &fromGWName, const std::string &toGWName, double costs)
Define additional costs for a specific link.
GatewayNodePtr gw
Definition: MetricCostmapTopoMapPlanner.h:96
boost::function< void(mira::pilot::AbstractMetricPlannerPtr, bool)> UpdateGoalFn
Definition: MetricCostmapTopoMapPlanner.h:247
bool havePlan() const
Returns true if we have or have had a valid to the set goal.
NodePtr n
Definition: MetricCostmapTopoMapPlanner.h:161
void dummySetter(std::string s)
Definition: MetricCostmapTopoMapPlanner.h:197
NextSubGoal()
Definition: MetricCostmapTopoMapPlanner.h:177
PlannerContext()
Definition: MetricCostmapTopoMapPlanner.h:99
double costs
Definition: MetricCostmapTopoMapPlanner.h:163
std::string getNodeName()
Definition: MetricCostmapTopoMapPlanner.h:191
mira::maps::GridMap< uint8, 3 > dumpNavStatus(bool actualMap=false, bool costsInGoalRegion=true)
void setAdditionalLinkCosts(const std::string &fromGWName, const std::string &toGWName, double costs)
Definition: MetricCostmapTopoMapPlanner.h:266
bool active
Definition: MetricCostmapTopoMapPlanner.h:97
int hops
Definition: MetricCostmapTopoMapPlanner.h:165
std::string frame
Definition: MetricCostmapTopoMapPlanner.h:140
bool isInFinalApproach() const
Returns true, if the robot is within the goal node and driving directly to the goal.
Definition: MetricCostmapTopoMapPlanner.h:207
Rect2i rect
Definition: MetricCostmapTopoMapPlanner.h:94
boost::optional< double > lastCosts
Definition: MetricCostmapTopoMapPlanner.h:98
virtual void onNodeChanged(NodePtr currentNode, GatewayNodePtr usedGateway, GatewayNodePtr nextGateway)=0
Is called, after the robot has just moved into the next node.
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
NodePtr node
Definition: MetricCostmapTopoMapPlanner.h:95
bool finalApproach() const
Definition: MetricCostmapTopoMapPlanner.h:101
double getValue(const Point2f &worldPos) const
GatewayNodePtr gn
Definition: MetricCostmapTopoMapPlanner.h:162
Definition: TopoMapPlanner.h:34
std::map< GatewayNodePtr, CostInfo > VisitedList
Definition: TopoMapPlanner.h:125
void resetAllAdditionalLinkCosts()
Reset all additional gateways costs to zero.
std::set< GatewayNodePtr, shared_ptr_sort< GatewayNode > > GatewayNodeSet
Definition: TopoMapFwd.h:102
void reflect(Reflector &r)
Definition: MetricCostmapTopoMapPlanner.h:168