ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
map_provider.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  * Robert Markowski- initial implementation
13  ********************************************************************************/
14 
15 #pragma once
20 #include <adore/env/afactory.h>
21 #include <adore/params/afactory.h>
22 #include <adore/mad/csvlog.h>
23 
24 #include "if_plotlab/plot_border.h"
25 
26 namespace adore
27 {
28  namespace apps
29  {
37  {
38  public:
39  struct Config
40  {
43  {
44  trans_x_ = 0;
45  trans_y_ = 0;
46  trans_z_ = 0;
47  rot_x_ = 0;
48  rot_y_ = 0;
49  rot_z_ = 0;
50  rot_psi_ = 0;
51  }
52  };
54 
55  void setConfig(Config config)
56  {
57  config_ = config;
58  }
59  private:
64  /* read: vehicle position */
66  /* read: border change tasks */
68 
69  /* write: border*/
71  /* write: precedence rule*/
73 
74  /* plot */
77 
78  unsigned int subscriber_count_;
79 
80  void parseTrackConfigs(std::string trackConfigs, env::BorderBased::BorderSet& targetSet)
81  {
82  std::string trackConfig = "";
83  std::stringstream trackstream(trackConfigs);
84  while(std::getline(trackstream,trackConfig,';'))
85  {
86  /* reading of single track configuration, comma separated */
87  std::stringstream trackConfigStream(trackConfig);
88  bool transform = false;
89  std::string xodrFilename = "";
90  std::string r2sReflineFilename = "";
91  std::string r2sLaneFilename = "";
92  std::string token = "";
93  while(std::getline(trackConfigStream,token,','))
94  {
95  if(token.size()<=5)
96  {
97  LOG_W("Unrecognizable token: %s", token.c_str());
98  continue;
99  }
100  if(token.compare("transform")==0)
101  {
102  transform = true;
103  }
104  else if(token.substr(token.size()-5,5).compare(".xodr")==0)
105  {
106  xodrFilename = token;
107  }
108  else
109  {
110  if(token.substr(token.size()-5,5).compare(".r2sr")==0)
111  {
112  r2sReflineFilename = token;
113  }
114  else if(token.substr(token.size()-5,5).compare(".r2sl")==0)
115  {
116  r2sLaneFilename = token;
117  }
118  else
119  {
120  LOG_W("Unrecognizable token: %s", token.c_str());
121  continue;
122  }
123  }
124 
125  }
126  /* process current file */
128  if(!xodrFilename.empty())
129  {
132  try
133  {
134  LOG_I("Processing file %s ...", xodrFilename.c_str());
135  converter.convert(xodrFilename.c_str(),&partialSet,transform);
136  LOG_I("Done.");
137  }
138  catch(const std::exception& e)
139  {
140  LOG_E("Could not parse file %s", xodrFilename.c_str());
141  std::cout << e.what() << '\n';
142  }
143 
144  /* add partial map to global map */
145  auto its = partialSet.getAllBorders();
146  for(;its.first!=its.second;its.first++)
147  {
148  targetSet.insert_border(its.first->second);
149  }
150  /* global map has responsibility for object/pointers */
151  partialSet.setIsOwner(false);
152  }
153  else if(!(r2sReflineFilename.empty() || r2sLaneFilename.empty()))
154  {
155  try
156  {
157  LOG_I("Processing files %s and %s ...", r2sReflineFilename.c_str(), r2sLaneFilename.c_str());
159  converter.convert(r2sReflineFilename,r2sLaneFilename, partialSet);
160  LOG_I("Done.");
161  }
162  catch(...)
163  {
164  LOG_E("Could not parse R2S files %s and %s", r2sReflineFilename.c_str(), r2sLaneFilename.c_str());
165  }
166 
167  /* add partial map to global map */
168  auto its = partialSet.getAllBorders();
169  for(;its.first!=its.second;its.first++)
170  {
171  targetSet.insert_border(its.first->second);
172  }
173  partialSet.setIsOwner(false);
174  }
175  else
176  {
177  LOG_E("Could not parse configuration: %s", trackConfig.c_str());
178  }
179  }
180  }
181 
182  public:
183  MapProvider( std::string trackConfigs,
185  Config config)
186  {
187  config_ = config;
188  /* process trackConfigs parameter, multiple paths to maps delimited by semicolon, comma separated additional configuration */
191  parseTrackConfigs(trackConfigs,globalSet);
198  map_management_.init(&globalSet);
199  precedence_set_.init(pset);
200  subscriber_count_ = 0;
201 
203  {
206  figure_->show();
208  }
209  }
214  virtual void run()
215  {
218  std::vector<env::BorderBased::BorderID> outdatedBorders;
219  std::vector<env::BorderBased::BorderID> updatedBorders;
220 
221  motion_state_reader_->getData(motion_state);
222 
224  {
227  }
228 
230  {
231  LOG_E("Received Message.");
235  }
236 
237  map_management_.run(motion_state.getX(),motion_state.getY(),params_->getVisibiltyRadius(),newBorders,outdatedBorders,updatedBorders,500);
238 
239  for(auto b = newBorders.begin(); b!=newBorders.end(); b++)
240  {
241  border_output_->write(**b);
242  }
243  for(auto b = updatedBorders.begin(); b!=updatedBorders.end(); b++)
244  {
246  }
247 
248  const double x0 = motion_state.getX()-params_->getVisibiltyRadius();
249  const double y0 = motion_state.getY()-params_->getVisibiltyRadius();
250  const double x1 = motion_state.getX()+params_->getVisibiltyRadius();
251  const double y1 = motion_state.getY()+params_->getVisibiltyRadius();
252  for(auto it = precedence_set_.getRulesInRegion(x0,y0,x1,y1);
253  it.current()!=it.end();
254  it.current()++)
255  {
256  auto rule = it.current()->second;
257  if(!precedence_set_local_.contains(*rule))
258  {
259  precedence_output_->write(*rule);
261  }
262  }
264  }
265 
266  };
267  }
268 }
Definition: figurestubfactory.h:25
AFigureStub * createFigureStub(int windowID)
Definition: figurestubfactory.h:45
Definition: figurestubzmq.h:30
virtual void show() override
Definition: figurestubzmq.h:266
base class for middleware dependent implementations of the map provider module
Definition: map_provider.h:37
Config config_
Definition: map_provider.h:53
adore::env::PrecedenceSet precedence_set_
Definition: map_provider.h:62
unsigned int subscriber_count_
Definition: map_provider.h:78
MapProvider(std::string trackConfigs, adore::env::PrecedenceSet *pset, Config config)
Definition: map_provider.h:183
DLR_TS::PlotLab::FigureStubZMQ * figure_
Definition: map_provider.h:76
adore::env::PrecedenceSet precedence_set_local_
Definition: map_provider.h:63
adore::mad::AReader< adore::env::VehicleMotionState9d > * motion_state_reader_
Definition: map_provider.h:65
adore::mad::AFeed< adore::env::BorderTypeChangeProfile > * border_type_change_feed_
Definition: map_provider.h:67
DLR_TS::PlotLab::FigureStubFactory * figure_factory_
Definition: map_provider.h:75
adore::env::MapBorderManagement map_management_
Definition: map_provider.h:61
params::APMapProvider * params_
Definition: map_provider.h:60
void setConfig(Config config)
Definition: map_provider.h:55
virtual void run()
update function
Definition: map_provider.h:214
void parseTrackConfigs(std::string trackConfigs, env::BorderBased::BorderSet &targetSet)
Definition: map_provider.h:80
adore::env::AFactory::TBorderWriter * border_output_
Definition: map_provider.h:70
adore::env::AFactory::TPrecedenceRuleWriter * precedence_output_
Definition: map_provider.h:72
virtual TPrecedenceRuleWriter * getPrecedenceRuleWriter()=0
virtual TBorderTypeChangeProfileFeed * getBorderTypeChangeProfileFeed()=0
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
virtual TBorderWriter * getBorderWriter()=0
efficiently store borders in boost R-tree
Definition: borderset.h:99
void rotate(double psi, double rot_x=0.0, double rot_y=0.0)
Definition: borderset.h:156
void insert_border(Border *b, bool force_insert=false)
insert new border into this
Definition: borderset.h:225
BorderIteratorPair2 getAllBorders()
get all borders in this
Definition: borderset.h:356
void setIsOwner(bool isOwner)
set whether this owns objects in pointers
Definition: borderset.h:214
void translate(double trans_x, double trans_y, double trans_z)
Definition: borderset.h:171
static adore::env::AFactory * get()
Definition: afactory.h:236
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
adore::env::BorderBased::Border * getBorder(adore::env::BorderBased::BorderID &bId)
Direct access to border in global map for auxiliary uses like plotting.
Definition: map_border_management.h:175
void changeBorderType(adore::env::BorderBased::BorderType::TYPE t, double x, double y)
change border type of border at exactly the given position
Definition: map_border_management.h:300
void reset()
undo all changes to global map and clears local map
Definition: map_border_management.h:193
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
PrecedenceSet contains PrecedenceRules, indexed by the area they affect.
Definition: precedence.h:179
bool contains(const PrecedenceRule &rule)
check whether a rule is contained
Definition: precedence.h:313
void refocus(double x0, double y0, double x1, double y1)
removes all rules outside of a region
Definition: precedence.h:395
itRegion2PrecedenceRT getRulesInRegion(double x0, double y0, double x1, double y1) const
returns a subset of rules in a region
Definition: precedence.h:345
void insertRule(const PrecedenceRule &rule)
inserts a copy of the given rule into container
Definition: precedence.h:291
void init(PrecedenceSet *other)
initialize by copying entries
Definition: precedence.h:300
input: 2 files, reference lines and borders output: border file
Definition: r2s2borderbased.h:31
void convert(std::string referenceLineFile, std::string laneBorderFile, env::BorderBased::BorderSet &targetset)
convert to borders
Definition: r2s2borderbased.cpp:182
OpenDRIVE converter from file to object sets.
Definition: xodr2borderbased.h:43
struct adore::if_xodr::XODR2BorderBasedConverter::@1 sampling
sampling configuration object
double numberOfPointsPerBorder
Definition: xodr2borderbased.h:75
void convert(const char *filename, adore::env::BorderBased::BorderSet *target_set, adore::env::TCDSet *tcdSet, adore::env::BorderBased::LanePositionedObjectSet *stoplineSet, adore::env::BorderBased::ParkingSpotSet *parkingSpotSet, BorderIDTranslation *idTranslation, double *x0, double *y0, bool transform=false)
full conversion of OpenDRIVE map to object representations
Definition: xodr2borderbased.cpp:26
virtual void getNext(T &value)=0
virtual bool hasNext() const =0
virtual void getData(T &value)=0
Definition: com_patterns.h:97
virtual void write(const T &value)=0
virtual uint32_t getNumberOfSubscribers() const
Definition: com_patterns.h:118
virtual APMapProvider * getMapProvider() const =0
abstract class containing parameters to configure aspects of the map provider
Definition: ap_map_provider.h:25
virtual bool getActivatePlotting() const =0
virtual int getXODRLoaderPointsPerBorder() const =0
virtual double getVisibiltyRadius() const =0
static adore::params::AFactory * get()
Definition: afactory.h:103
#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
void plotBorderSet(adore::env::BorderBased::BorderSet &borderSet, DLR_TS::PlotLab::AFigureStub *figure)
Definition: plot_border.h:194
std::vector< Border * > BorderSubSet
Definition: borderset.h:92
x0
Definition: adore_set_goal.py:25
y0
Definition: adore_set_goal.py:26
y1
Definition: adore_set_pose.py:29
x1
Definition: adore_set_pose.py:28
Definition: areaofeffectconverter.h:20
Definition: map_provider.h:40
double trans_z_
Definition: map_provider.h:41
double rot_psi_
Definition: map_provider.h:41
double trans_x_
Definition: map_provider.h:41
double rot_z_
Definition: map_provider.h:41
double rot_x_
Definition: map_provider.h:41
double trans_y_
Definition: map_provider.h:41
double rot_y_
Definition: map_provider.h:41
Config()
Definition: map_provider.h:42
Definition: map_border_management.h:27
T1 & current()
Definition: precedence.h:226
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