ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
navigation_management.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  ********************************************************************************/
13 
14 
15 #pragma once
16 
21 
22 #include "adore/mad/com_patterns.h"
23 #include "adore/mad/csvlog.h"
24 
25 namespace adore
26 {
27  namespace env
28  {
30  {
32  double m_maxCost;
35 
39 
41  {
42  /* border is found at exact target position */
43  adore::env::BorderBased::Border* matchedBorder = nullptr;
44  double destinationX[] = { m_destination.m_X };
45  double destinationY[] = { m_destination.m_Y};
47  m_map.getGlobalMap()->matchLanesInRegion(destinationX,destinationY,1,borders);
48  bool borderFound = false;
49 
50  if(borders.size()>0)
51  {
52  for(auto border = borders.begin();border!=borders.end();border++)
53  {
54  if((*border)->m_type == adore::env::BorderBased::BorderType::DRIVING)
55  {
56  matchedBorder = *border;
57  borderFound = true;
58  }
59  }
60  }
61 
62  /* no border is found at exact target position */
63  if(!borderFound)
64  {
65  LOG_W("Dadore_CORE_Navigation.cpp: No borders were found for given point. Trying to use closest border...");
66  for(double distance = 1.0;;distance = distance +10.0)
67  {
68  auto bordersInArea = m_map.getGlobalMap()->getBordersInRegion(m_destination.m_X-distance,m_destination.m_X+distance,m_destination.m_Y-distance,m_destination.m_Y+distance);
69  auto minDistance = distance;
70  for(;bordersInArea.first!=bordersInArea.second;bordersInArea.first++)
71  {
72  double distanceToBorder = distance;
73  auto curBorder = bordersInArea.first->second;
75  {
76  continue;
77  }
78  curBorder->m_path->getClosestParameter(m_destination.m_X,m_destination.m_Y,1,2,distanceToBorder);
79  if(distanceToBorder<minDistance)
80  {
81  matchedBorder = curBorder;
82  minDistance = distanceToBorder;
83  borderFound = true;
84  }
85 
86 
87  }
88  if(borderFound) break;
89  if(distance>1000)
90  {
91  LOG_E("No border to navigate to was found.");
92  break;
93  }
94  }
95  }
96  if(matchedBorder==nullptr)
97  {
98  LOG_E("Dadore_CORE_Navigation.cpp: No border to navigate to was found.");
99  }
100  else
101  {
102  LOG_I("Found border to navigate to.");
103  }
104  return matchedBorder;
105  }
106 
107  void setMaxCost()
108  {
109  /* costs are negative */
110  m_maxCost = 0;
111  for(auto it = m_borderCosts.begin(); it!=m_borderCosts.end(); it++)
112  {
113  if(it->second < m_maxCost)
114  {
115  m_maxCost = it->second;
116  }
117  }
118  m_maxCost = std::abs(m_maxCost);
119  }
120 
121 
122  public:
124  {
127  m_maxCost = -1;
128  m_goalChanged = true;
129  m_laneChangePenalty = 100.0;
130  }
131 
132  void setLaneChangePenalty(double value)
133  {
134  m_laneChangePenalty = value;
135  }
136 
138  {
140  }
141 
142  double getMaxCost()
143  {
144  return m_maxCost;
145  }
146 
147  bool hasMap()
148  {
149  return m_map.getGlobalMap()->size() > 0;
150  }
151 
153  {
154  m_map.init(set);
156  }
157 
158  /*
159  * update:
160  * - check for target change
161  * - check for map changes
162  */
163  void update(BorderBased::Coordinate newDestination, bool destinationValid)
164  {
165  /* check for map changes via lane border feed */
167 
168  /* if destination changed and is valid, use new destination */
169  if(destinationValid && newDestination != m_destination)
170  {
171  setDestination(newDestination);
172  m_goalChanged = true;
173  }
174  /* if destination didn't change but map did, replan with old destination */
176  {
178  m_goalChanged = true;
179  }
180  else
181  {
182  m_goalChanged = false;
183  }
184  }
185 
186  bool goalChanged()
187  {
188  return m_goalChanged;
189  }
190 
191  /*
192  * reset:
193  * - reset map and navBorderObserver to base set
194  */
195  void reset()
196  {
197  m_map.reset();
200  }
201 
202  /*
203  * clear:
204  * - clear local border set to re-send navigation information
205  */
206  void clear()
207  {
209  }
210 
211  /* change target, reset border costs, reset localmap to send all new updates */
213  {
214  /* set new target */
215  m_destination = c;
216 
217  /* clear current border costs */
218  m_borderCosts.clear();
219 
220  /* prepare graph usage */
223  auto targetBorder = getBorderFromCurrentTarget();
224  if(targetBorder!=nullptr)
225  {
226  BorderBased::Node startNode(targetBorder);
227 
228  /* build graph and generate new costs, use navBorderObserver to generate graph */
230  graph.init(dynamic_cast<BorderBased::BorderSet*>(&m_navBorderObserver),cost_function);
231  graph.djikstra(&startNode, &m_borderCosts);
232  setMaxCost();
233  }
234 
235  /* clear local border set to send new update */
237  }
238 
239  void run(double x, double y, double r, std::vector<adore::env::BorderBased::Border*> &newBorders, std::vector<adore::env::BorderBased::BorderID> &outdatedBorders, int MAX_SEND_NUMBER = 40)
240  {
241  m_map.run(x,y,r,newBorders,outdatedBorders,MAX_SEND_NUMBER);
242  }
243 
245  {
246  auto entry = m_borderCosts.find(id);
247 
248  /* border costs are stored as negative values, transform to positive here */
249  if(entry != m_borderCosts.end())
250  {
251  return std::abs(entry->second);
252  }
254  }
255 
257  {
258  return m_map.getGlobalMap()->getBorder(id);
259  }
260 
262  {
263  return m_map.getGlobalMap();
264  }
265  };
266  }
267 }
void setLaneChangePenalty(double value)
Definition: bordergraph.h:165
Definition: bordergraph.h:213
std::unordered_map< adore::env::BorderBased::BorderID, double, adore::env::BorderBased::BorderIDHasher > BorderCostMap
Definition: bordergraph.h:220
void djikstra(adore::env::BorderBased::Node *startNode, BorderCostMap *closedList)
Definition: bordergraph.h:247
void init(BorderSet *borderSet)
Definition: bordergraph.h:236
void addFeed(adore::mad::AFeed< Border > *feed)
Definition: border_observer.h:64
efficiently store borders in boost R-tree
Definition: borderset.h:99
void clear()
remove all borders from this, delete object if this is owner
Definition: borderset.h:284
itRegion2Border getBordersInRegion(double x0, double x1, double y0, double y1)
get all borders in this within region
Definition: borderset.h:370
void matchLanesInRegion(double *x, double *y, int count, BorderSubSet &targetSet)
get a vector of borders, which describe lanes that match the specified region
Definition: borderset.h:481
Border * getBorder(const BorderID &id) const
retrieve a border by ID
Definition: borderset.h:628
int size()
number of borders in this
Definition: borderset.h:1497
Definition: navigation_border_observer.h:29
void init(BorderSet *set)
Definition: navigation_border_observer.h:40
bool navigationReplanningNecessary()
Definition: navigation_border_observer.h:82
virtual void update() override
Definition: navigation_border_observer.h:50
Automatically manage local map and necessary updates based on vehicle position and last state of obje...
Definition: map_border_management.h:37
void init(adore::env::BorderBased::BorderSet *baseSet)
initialization routine with base map
Definition: map_border_management.h:164
void reset()
undo all changes to global map and clears local map
Definition: map_border_management.h:193
void clearLocalMap()
clear local map
Definition: map_border_management.h:184
adore::env::BorderBased::BorderSet * getGlobalMap()
Definition: map_border_management.h:210
void run(double x, double y, double r, std::vector< adore::env::BorderBased::Border * > &newBorders, std::vector< adore::env::BorderBased::BorderID > &outdatedBorders, std::vector< adore::env::BorderBased::BorderID > &updatedBorders, int MAX_SEND_NUMBER=40)
Definition: map_border_management.h:272
Definition: navigation_management.h:30
bool hasMap()
Definition: navigation_management.h:147
void addFeed(adore::mad::AFeed< adore::env::BorderBased::Border > *feed)
Definition: navigation_management.h:137
void update(BorderBased::Coordinate newDestination, bool destinationValid)
Definition: navigation_management.h:163
BorderBased::NavigationBorderObserver m_navBorderObserver
Definition: navigation_management.h:38
NavigationManagement()
Definition: navigation_management.h:123
double m_maxCost
Definition: navigation_management.h:32
MapBorderManagement m_map
Definition: navigation_management.h:31
BorderBased::Coordinate m_destination
Definition: navigation_management.h:36
void setDestination(BorderBased::Coordinate c)
Definition: navigation_management.h:212
void init(BorderBased::BorderSet *set)
Definition: navigation_management.h:152
adore::env::BorderBased::Border * getBorder(adore::env::BorderBased::BorderID id)
Definition: navigation_management.h:256
bool goalChanged()
Definition: navigation_management.h:186
bool m_goalChanged
Definition: navigation_management.h:33
void setMaxCost()
Definition: navigation_management.h:107
double m_laneChangePenalty
Definition: navigation_management.h:34
adore::env::BorderBased::BorderSet * getGlobalMap()
Definition: navigation_management.h:261
BorderBased::Border * getBorderFromCurrentTarget()
Definition: navigation_management.h:40
void run(double x, double y, double r, std::vector< adore::env::BorderBased::Border * > &newBorders, std::vector< adore::env::BorderBased::BorderID > &outdatedBorders, int MAX_SEND_NUMBER=40)
Definition: navigation_management.h:239
void setLaneChangePenalty(double value)
Definition: navigation_management.h:132
double getMaxCost()
Definition: navigation_management.h:142
BorderBased::BorderGraph::BorderCostMap m_borderCosts
Definition: navigation_management.h:37
void reset()
Definition: navigation_management.h:195
double getBorderCost(BorderBased::BorderID id)
Definition: navigation_management.h:244
void clear()
Definition: navigation_management.h:206
#define LOG_W(...)
log on warning level
Definition: csvlog.h:46
#define LOG_I(...)
log on info level
Definition: csvlog.h:37
#define LOG_E(...)
log on error level
Definition: csvlog.h:55
@ DRIVING
Definition: border.h:39
std::vector< Border * > BorderSubSet
Definition: borderset.h:92
void set(T *data, T value, int size)
Definition: adoremath.h:39
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
x
Definition: adore_set_goal.py:30
y
Definition: adore_set_goal.py:31
r
Definition: adore_suppress_lanechanges.py:209
Definition: areaofeffectconverter.h:20
This struct identifies a Border by the coordinates of the starting and the end point.
Definition: borderid.h:31
The border struct contains data of the smallest.
Definition: border.h:62
This struct represents 3-dimensional coordines.
Definition: coordinate.h:34
double m_Y
Definition: coordinate.h:35
double m_X
Definition: coordinate.h:35
Definition: bordergraph.h:28
T1 first
Definition: borderset.h:47