ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
localroadmap.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  * Daniel Heß - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
20 #include <adore/env/afactory.h>
21 #include <adore/params/afactory.h>
22 #include <adore/mad/com_patterns.h>
26 
27 namespace adore
28 {
29  namespace env
30  {
31  namespace BorderBased
32  {
37  class LocalRoadMap
38  {
39  private:
63  void updateData()
64  {
65  while (borderFeed_->hasNext())
66  {
67  Border* b = new Border();
68  borderFeed_->getNext(*b);
69  Border* result = borderSet_.getBorder(b->m_id);
70  if (result!=nullptr)//object exists => delete and create new
71  {
73  }
75  }
77  {
78  std::pair<BorderBased::BorderID,double> datum;
80  adore::env::NavigationCost cost(datum.second);
81  borderCostMap_.emplace(datum.first, cost).first->second = cost;//create and update
82  }
84  }
89  void discard_radius_based(double radius)
90  {
93  egoState_.getX()-radius,egoState_.getX()+radius,
94  egoState_.getY()-radius,egoState_.getY()+radius));
95  }
96  public:
105  : precedenceSet_(envfactory->getPrecedenceRuleFeed())
106  , connectionSet_(envfactory->getControlledConnectionFeed())
109  {
110  borderFeed_ = envfactory->getBorderFeed();
111  navigationDataFeed_ = envfactory->getNavigationDataFeed();
112  vehicleReader_ = envfactory->getVehicleMotionStateReader();
113  apLocalRoadMap_ = paramsfactory->getLocalRoadMap();
114  apVehicle_ = paramsfactory->getVehicle();
115  }
116 
124  {
125  return &borderSet_;
126  }
133  {
134  return &precedenceSet_;
135  }
142  {
143  return &egoState_;
144  }
146  {
147  return apVehicle_;
148  }
155  {
156  return &borderTrace_;
157  }
164  {
165  return matchedLane_;
166  }
173  {
174  return &borderCostMap_;
175  }
176 
182  {
184  }
185 
186 
195  double getNavigationCost(double x,double y,double z)
196  {
197  double min_cost = 1.0e99;
199  for(auto it = candidates.begin();it!=candidates.end();it++)
200  {
201  if(borderSet_.borderTypeValid(*it))
202  {
203  //@TODO: scan z component to rule out mismatches with bridges etc
204  auto result = borderCostMap_.find((*it)->m_id);
205  if(result!=borderCostMap_.end())
206  {
207  double cost0 = result->second.getCombinedCost();
208  double cost1 = 1.0e99;
209  double d;
210  double s = (*it)->m_path->getClosestParameter(x,y,1,2);
211  double L = (*it)->getLength();
212  for(auto it2 = borderSet_.getSuccessors(*it);it2.current()!=it2.end();it2.current()++)
213  {
214  auto result2 = borderCostMap_.find((it2.current())->second->m_id);
215  if(result2!=borderCostMap_.end())
216  {
217  double c = result2->second.getCombinedCost();
218  if(c<cost1)
219  {
220  cost1 = c;
221  }
222  }
223  }
224  if(cost1==1.0e99)
225  {
226  d = std::abs(cost0-s);
227  }
228  else
229  {
230  d = cost0 + s/L * (cost1-cost0);
231  }
232  if( d<min_cost )
233  {
234  min_cost = d;
235  }
236  }
237  }
238  }
239  return min_cost;
240  }
241 
242 
247  {
249  }
250 
251 
256  void update(bool matched_lane_proposal_valid=false,BorderID matched_lane_proposal_id = BorderID())
257  {
258  try{
259  updateData();
260  }catch(...){std::cout<<"Failed to update data\n";}
261  double radius = apLocalRoadMap_->getDiscardRadius();
262  try{
263  discard_radius_based(radius);
264  }catch(...){std::cout<<"Failed to discard radius based\n";}
265  //get lane matching candidates
266  try{
267  lanesNearVehicle_.clear();
269  egoState_.getX(),
270  egoState_.getY(),
271  egoState_.getPSI(),
273  apVehicle_->get_d(),
276  );
277  }catch(...){std::cout<<"Failed to match lanes\n";}
278  Border* matched_lane_proposal = matched_lane_proposal_valid
279  ?borderSet_.getBorder(matched_lane_proposal_id)
280  :nullptr;
281  if(matched_lane_proposal!=nullptr)
282  {
283  matchedLane_ = matched_lane_proposal;
284  }
285  else
286  {
287  if( lanesNearVehicle_.size()>0 )
288  {
290  {
292  }
293  else
294  {
296  }
297  }
298  else
299  {
300  matchedLane_ = nullptr;
301  }
302  }
303  if(matchedLane_!=nullptr)
304  {
307  }
310  }
312  {
313  return &connectionSet_;
314  }
315  };
316  }
317  }
318 }
abstract factory for adore::env communication
Definition: afactory.h:41
Definition: bordercostmap.h:31
efficiently store borders in boost R-tree
Definition: borderset.h:99
void removeBorders(const BorderSubSet &subset)
remove all borders in the given set
Definition: borderset.h:593
BorderSubSet getBordersAtPoint(double x, double y, double max_lane_width)
get all borders at the given point
Definition: borderset.h:403
itCoordinate2Border getSuccessors(Border *b)
get an interator pair for all borders which follow after b
Definition: borderset.h:996
void insert_border(Border *b, bool force_insert=false)
insert new border into this
Definition: borderset.h:225
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
void erase_border(const BorderID &oldID)
erase border from this
Definition: borderset.h:269
bool borderTypeValid(Border *b)
check whether border type is in allowed types of set
Definition: borderset.h:204
itRegion2Border getBordersOutsideRegion(double x0, double x1, double y0, double y1)
get all borders outside of region as iterator pair
Definition: borderset.h:464
Definition: bordertrace.h:30
void insert(Border &border)
Definition: bordertrace.h:43
void setDistanceLimit(double distance_limit)
Definition: bordertrace.h:41
Definition: lanematchingstrategy.h:105
virtual Border * getBestMatch(BorderSubSet *bordersInRegion, adore::env::VehicleMotionState9d *ego) override
Definition: lanematchingstrategy.h:128
Definition: lanematchingstrategy.h:242
virtual Border * getBestMatch(BorderSubSet *borderSubset, adore::env::VehicleMotionState9d *ego) override
Definition: lanematchingstrategy.h:256
Definition: localroadmap.h:38
BorderTrace * getBorderTrace()
Get the BorderTrace.
Definition: localroadmap.h:154
void update(bool matched_lane_proposal_valid=false, BorderID matched_lane_proposal_id=BorderID())
update the local road map
Definition: localroadmap.h:256
AFactory::TNavigationDataFeed * navigationDataFeed_
Definition: localroadmap.h:44
Border * matchedLane_
Definition: localroadmap.h:48
bool isNavigationActive()
transfers value of APLocalRoadMap->isNavigationActive is true
Definition: localroadmap.h:181
void discard_radius_based(double radius)
Remove Borders outside a certain area.
Definition: localroadmap.h:89
BorderSubSet lanesNearVehicle_
Definition: localroadmap.h:47
void updateEgoState()
update only the ego state
Definition: localroadmap.h:246
adore::env::ControlledConnectionSet connectionSet_
Definition: localroadmap.h:42
VehicleMotionState9d egoState_
Definition: localroadmap.h:45
adore::env::ControlledConnectionSet * getControlledConnectionSet()
Definition: localroadmap.h:311
adore::params::APVehicle * apVehicle_
Definition: localroadmap.h:54
adore::params::APLocalRoadMap * apLocalRoadMap_
Definition: localroadmap.h:53
PrecedenceSet * getPrecedenceSet()
Get the PrecedenceSet object.
Definition: localroadmap.h:132
Border * getMatchedBorder()
Get the matched border.
Definition: localroadmap.h:163
VehicleMotionState9d getEgoState()
Definition: localroadmap.h:117
BorderCostMap * getBorderCostMap()
Get the BorderCostMap object.
Definition: localroadmap.h:172
BorderBased::LMSNavigation lms_navigation_
Definition: localroadmap.h:52
LocalRoadMap(adore::env::AFactory *envfactory=adore::env::EnvFactoryInstance::get(), adore::params::AFactory *paramsfactory=adore::params::ParamsFactoryInstance::get())
Construct a new LocalRoadMap object.
Definition: localroadmap.h:103
double getNavigationCost(double x, double y, double z)
Get the navigation cost for border on a certain point.
Definition: localroadmap.h:195
AFactory::TVehicleMotionStateReader * vehicleReader_
Definition: localroadmap.h:46
BorderSet * getBorderSet()
Get the BorderSet object.
Definition: localroadmap.h:123
adore::params::APVehicle * getVehicleParameters()
Definition: localroadmap.h:145
VehicleMotionState9d * getVehicleState()
Get the VehicleState.
Definition: localroadmap.h:141
BorderCostMap borderCostMap_
Definition: localroadmap.h:50
BorderSet borderSet_
Definition: localroadmap.h:40
adore::env::PrecedenceSet precedenceSet_
Definition: localroadmap.h:41
BorderBased::LMSContinuation lms_continuation_
Definition: localroadmap.h:51
AFactory::TBorderFeed * borderFeed_
Definition: localroadmap.h:43
void updateData()
update the data of local road map
Definition: localroadmap.h:63
BorderTrace borderTrace_
Definition: localroadmap.h:49
Definition: controlledconnection.h:147
virtual void update(double radius, double X, double Y)
Definition: controlledconnection.h:204
static adore::env::AFactory * get()
Definition: afactory.h:236
PrecedenceSet contains PrecedenceRules, indexed by the area they affect.
Definition: precedence.h:179
void update(double radius, double x, double y)
Definition: precedence.h:189
Definition: com_patterns.h:29
virtual void getNext(T &value)=0
virtual bool hasNext() const =0
Definition: com_patterns.h:68
virtual void getData(T &value)=0
abstract factory for adore::params classes
Definition: afactory.h:54
abstract class to configure the local view of the road map
Definition: ap_local_road_map.h:26
virtual bool isNavigationActive() const =0
virtual double getDiscardRadius() const =0
virtual double getBorderTraceLength() const =0
abstract class for vehicle configuration related paremeters
Definition: ap_vehicle.h:29
virtual double get_b() const =0
rear axle to cog
virtual double get_bodyWidth() const =0
virtual double get_d() const =0
rear border to rear axle
virtual double get_a() const =0
cog to front axle
virtual double get_c() const =0
front axle to front border
static adore::params::AFactory * get()
Definition: afactory.h:103
std::vector< Border * > BorderSubSet
Definition: borderset.h:92
x
Definition: adore_set_goal.py:30
y
Definition: adore_set_goal.py:31
z
Definition: adore_set_goal.py:32
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
BorderID m_id
Definition: border.h:68
T1 & current()
Definition: borderset.h:50
Struct to organize navigation cost.
Definition: navigationcost.h:26
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39
double getX() const
Get the x-coordinate.
Definition: vehiclemotionstate9d.h:54
double getY() const
Get the y-coordinate.
Definition: vehiclemotionstate9d.h:60
double getPSI() const
Get the heading.
Definition: vehiclemotionstate9d.h:72