ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
threelaneviewdecoupled.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
16 #include <adore/env/afactory.h>
21 
22 namespace adore
23 {
24  namespace env
25  {
32  {
33  public:
35  {
36  public:
39  double s_offset_;
41  double limitS(double s)
42  {
43  s-=s_offset_;
44  return adore::mad::bound(
48  }
52  virtual bool isValid() const override
53  {
54  return data_.isValid;
55  }
59  virtual double getSMax()const override
60  {
62  }
66  virtual double getSMin()const override
67  {
68  return +s_offset_;
69  }
73  bool syncS(ALane* master)
74  {
75  s_offset_ = 0.0;
76  if(!isValid()||!master->isValid())return false;
77  double X,Y,Z,sout,tmp;
78  for(double s = master->getSMin();s<master->getSMax();s+=1.0)
79  {
80  master->toEucledianCoordinates(s,0.0,X,Y,Z);
81  this->toRelativeCoordinates(X,Y,sout,tmp);
82  if(sout>=getSMax())return false;
83  if(sout>getSMin())
84  {
85  s_offset_ = s-sout;
86  return true;
87  }
88  }
89  return false;
90  }
95  double getProgressOfWidthOpen() const
96  {
98  }
104  {
106  }
110  virtual const adore::view::TrafficQueue& getOnLaneTraffic()const override
111  {
112  return queueOnThisLane_.getQueue();
113  }
117  virtual const adore::view::ConflictSet& getConflictSet()const override
118  {
119  throw std::logic_error("Not implemented");
120  }
124  virtual double getSpeedLimit(double s) override
125  {
126  return data_.speedLimit_fct(limitS(s));
127  }
131  double getLeftIndicatorHint(double s) override
132  {
134  }
138  double getRightIndicatorHint(double s) override
139  {
141  }
145  virtual bool hasSpeedRecommendation(double s)const override
146  {
147  return false;
148  }
152  virtual double getSpeedRecommendation(double s)const override
153  {
154  throw std::logic_error("Not implemented");
155  return 0.0;
156  }
157  virtual double getNavigationCost(double s) override
158  {
159  if(data_.navigationCost_fct.getData().nc()<2)return 1.0e10;
161  }
167  virtual void boundNavigationCost(double s0,double s1,double& cmin,double& cmax) override
168  {
169  if(data_.navigationCost_fct.getData().nc()<2)
170  {
171  cmin = 1.0e10;
172  cmax = 1.0e10;
173  return;
174  }
175  adoreMatrix<double,1,1> y0,y1;
176  s0 = limitS(s0);
177  s1 = limitS(s1);
181  cmin = y0;cmax = y1;
182  }
183 
187  virtual double getHeading(double s) override
188  {
189  // return data_.centerHeading_fct(limitS(s));
190  auto n = data_.centerNormal_fct(limitS(s));
191  // return std::atan2(n(1),n(0))-M_PI*0.5;
192  return std::atan2(-n(0),n(1));
193  }
199  virtual double getCurvature(double s, int derivative) override
200  {
201  if (derivative <= 0)
202  {
204  }
205  else if (derivative <= 1)
206  {
208  }
209  else
210  {
211  return 0.0;
212  }
213  }
217  virtual double getOffsetOfLeftBorder(double s) override
218  {
219  return data_.leftDistance_fct(limitS(s));
220  }
224  virtual double getOffsetOfRightBorder(double s) override
225  {
226  return data_.rightDistance_fct(limitS(s));
227  }
231  virtual void toRelativeCoordinates(double xe,double ye,double& s,double& n) override
232  {
233  // if(!adore::mad::toRelativeWithNormalExtrapolation(xe,ye,&data_.centerSmoothed_fct,&data_.centerNormal_fct,s,n))
234  {
235  s = data_.centerSmoothed_fct.getClosestParameter(xe, ye, 1, 2, n);
236  }
238  }
242  virtual void toEucledianCoordinates(double s,double n,double& xe,double& ye,double& ze) override
243  {
244  s = limitS(s);
246  ze=0.0;
247  }
248 
249  };
250 
252  {
253  public:
257  double limitS(double s)
258  {
259  return target_->limitS(s);
260  }
261  LaneChangeViewProxy():source_(nullptr),target_(nullptr){}
262  void setLanes(LaneProxy* source,LaneProxy* target)
263  {
264  source_=source;
265  target_=target;
266  }
267  virtual adore::view::ALane* getSourceLane() override
268  {
269  return source_;
270  }
274  virtual adore::view::ALane* getTargetLane() override
275  {
276  return target_;
277  }
282  {
283  return data_.direction;
284  }
289  virtual double getProgressOfGateOpen() const override
290  {
291  return data_.gate_s0 + target_->getSMin();
292  }
297  virtual double getProgressOfGateClosed() const override
298  {
299  return data_.gate_s1 + target_->getSMin();
300  }
304  virtual double getOffsetOfStartOuterBorder(double s) override
305  {
306 
308  }
312  virtual double getOffsetOfSeparatingBorder(double s) override
313  {
315  }
319  virtual double getOffsetOfDestinationOuterBorder(double s) override
320  {
322  }
323 
327  virtual double getNavigationCostDifference() override
328  {
329  double smin_target,smax_target,smin_source,smax_source;
330  target_->boundNavigationCost(target_->getSMin(),target_->getSMax(),smin_target,smax_target);
331  source_->boundNavigationCost(source_->getSMin(),source_->getSMax(),smin_source,smax_source);
332  return smin_target-smin_source;
333  // double s = (getProgressOfGateOpen() + getProgressOfGateClosed())*0.5;
334  // return target_->getNavigationCost(s) - source_->getNavigationCost(s);
335  }
336 
337 
338  };
339 
340  private:
352  public:
353  ThreeLaneViewDecoupled(bool monitor_traffic=true):monitor_traffic_(monitor_traffic)
354  {
356  if(monitor_traffic_)
357  {
359  }
360  else
361  {
362  tpsetReader_ = nullptr;
363  }
364 
367  }
369  {
370  delete laneFeed_;
371  if(tpsetReader_!=nullptr)delete tpsetReader_;
372  }
373  void update()
374  {
375  bool recompute_traffic_queues = false;
376  if (laneFeed_->hasNext())
377  {
379  laneFeed_->getLatest(combinedGeometry);
380  center_.data_ = *combinedGeometry.center;
381  left_.data_ = *combinedGeometry.left;
382  right_.data_ = *combinedGeometry.right;
383  to_left_.data_ = *combinedGeometry.leftChange;
384  to_right_.data_ = *combinedGeometry.rightChange;
385  recompute_traffic_queues = true;
386  left_.syncS(&center_);
387  right_.syncS(&center_);
388  }
390  {
392  recompute_traffic_queues = true;
393  }
394  if(recompute_traffic_queues)
395  {
399  }
400  }
401 
406  {
407  return &center_;
408  }
413  {
414  return &to_left_;
415  }
420  {
421  return &to_right_;
422  }
423  };
424  }
425 }
virtual TParticipantSetReader * getTrafficParticipantSetReader()=0
virtual TLaneGeometryFeed * getLaneGeometryFeed()=0
efficiently store borders in boost R-tree
Definition: borderset.h:99
static adore::env::AFactory * get()
Definition: afactory.h:236
Definition: threelaneviewdecoupled.h:252
virtual double getProgressOfGateClosed() const override
Definition: threelaneviewdecoupled.h:297
LaneProxy * source_
Definition: threelaneviewdecoupled.h:254
virtual double getNavigationCostDifference() override
Definition: threelaneviewdecoupled.h:327
virtual adore::view::ALane * getSourceLane() override
Definition: threelaneviewdecoupled.h:267
void setLanes(LaneProxy *source, LaneProxy *target)
Definition: threelaneviewdecoupled.h:262
virtual double getOffsetOfSeparatingBorder(double s) override
Definition: threelaneviewdecoupled.h:312
virtual double getProgressOfGateOpen() const override
Definition: threelaneviewdecoupled.h:289
adore::env::BorderBased::LaneChangeDataProxy data_
Definition: threelaneviewdecoupled.h:256
virtual double getOffsetOfStartOuterBorder(double s) override
Definition: threelaneviewdecoupled.h:304
LaneProxy * target_
Definition: threelaneviewdecoupled.h:255
LaneChangeViewProxy()
Definition: threelaneviewdecoupled.h:261
double limitS(double s)
Definition: threelaneviewdecoupled.h:257
virtual double getOffsetOfDestinationOuterBorder(double s) override
Definition: threelaneviewdecoupled.h:319
virtual adore::view::ALane * getTargetLane() override
Definition: threelaneviewdecoupled.h:274
virtual adore::view::ALaneChangeView::direction getLCDirection() const override
Definition: threelaneviewdecoupled.h:281
Definition: threelaneviewdecoupled.h:35
virtual void toEucledianCoordinates(double s, double n, double &xe, double &ye, double &ze) override
Definition: threelaneviewdecoupled.h:242
bool syncS(ALane *master)
Definition: threelaneviewdecoupled.h:73
virtual double getOffsetOfLeftBorder(double s) override
Definition: threelaneviewdecoupled.h:217
double getProgressOfWidthOpen() const
Definition: threelaneviewdecoupled.h:95
virtual double getHeading(double s) override
Definition: threelaneviewdecoupled.h:187
virtual const adore::view::ConflictSet & getConflictSet() const override
Definition: threelaneviewdecoupled.h:117
adore::env::BorderBased::LaneGeometryDataProxy data_
Definition: threelaneviewdecoupled.h:37
virtual double getSMax() const override
Definition: threelaneviewdecoupled.h:59
virtual double getSMin() const override
Definition: threelaneviewdecoupled.h:66
double limitS(double s)
Definition: threelaneviewdecoupled.h:41
double getProgressOfWidthClosed() const
Definition: threelaneviewdecoupled.h:103
virtual double getOffsetOfRightBorder(double s) override
Definition: threelaneviewdecoupled.h:224
virtual double getSpeedRecommendation(double s) const override
Definition: threelaneviewdecoupled.h:152
virtual void boundNavigationCost(double s0, double s1, double &cmin, double &cmax) override
Definition: threelaneviewdecoupled.h:167
virtual double getSpeedLimit(double s) override
Definition: threelaneviewdecoupled.h:124
double getRightIndicatorHint(double s) override
Definition: threelaneviewdecoupled.h:138
virtual void toRelativeCoordinates(double xe, double ye, double &s, double &n) override
Definition: threelaneviewdecoupled.h:231
adore::env::traffic::TrafficQueueOnALane queueOnThisLane_
Definition: threelaneviewdecoupled.h:38
virtual double getNavigationCost(double s) override
Definition: threelaneviewdecoupled.h:157
virtual double getCurvature(double s, int derivative) override
Definition: threelaneviewdecoupled.h:199
double s_offset_
Definition: threelaneviewdecoupled.h:39
virtual bool isValid() const override
Definition: threelaneviewdecoupled.h:52
virtual const adore::view::TrafficQueue & getOnLaneTraffic() const override
Definition: threelaneviewdecoupled.h:110
virtual bool hasSpeedRecommendation(double s) const override
Definition: threelaneviewdecoupled.h:145
double getLeftIndicatorHint(double s) override
Definition: threelaneviewdecoupled.h:131
LaneProxy()
Definition: threelaneviewdecoupled.h:40
Definition: threelaneviewdecoupled.h:32
adore::env::traffic::TParticipantSet participantSet_
Definition: threelaneviewdecoupled.h:349
virtual adore::view::ALaneChangeView * getLeftLaneChange()
Definition: threelaneviewdecoupled.h:412
LaneProxy left_
Definition: threelaneviewdecoupled.h:344
LaneChangeViewProxy to_left_
Definition: threelaneviewdecoupled.h:347
adore::env::BorderBased::BorderSet * borderSet_
Definition: threelaneviewdecoupled.h:342
LaneProxy center_
Definition: threelaneviewdecoupled.h:345
LaneChangeViewProxy to_right_
Definition: threelaneviewdecoupled.h:348
LaneProxy right_
Definition: threelaneviewdecoupled.h:346
virtual adore::view::ALaneChangeView * getRightLaneChange()
Definition: threelaneviewdecoupled.h:419
ThreeLaneViewDecoupled(bool monitor_traffic=true)
Definition: threelaneviewdecoupled.h:353
virtual adore::view::ALane * getCurrentLane()
Definition: threelaneviewdecoupled.h:405
adore::env::AFactory::TLaneGeometryFeed * laneFeed_
Definition: threelaneviewdecoupled.h:341
void update()
Definition: threelaneviewdecoupled.h:373
adore::env::AFactory::TParticipantSetReader * tpsetReader_
Definition: threelaneviewdecoupled.h:343
bool monitor_traffic_
Definition: threelaneviewdecoupled.h:350
virtual ~ThreeLaneViewDecoupled()
Definition: threelaneviewdecoupled.h:368
Definition: trafficqueueonalane.h:30
const adore::view::TrafficQueue & getQueue() const
Definition: trafficqueueonalane.h:34
void mapVehicles(adore::view::ALane *lane, adore::env::traffic::TParticipantSet *participantSet)
Map traffic unto lane.
Definition: trafficqueueonalane.h:41
Definition: com_patterns.h:29
virtual bool hasNext() const =0
virtual void getLatest(T &value)=0
CT f_bounded(DT x)
Definition: alfunction.h:117
Definition: com_patterns.h:68
virtual void getData(T &value)=0
virtual bool hasData() const =0
virtual CT f(DT x) const override
Definition: llinearpiecewisefunction.h:251
virtual void bound(const DT &xmin, const DT &xmax, CT &ymin, CT &ymax) override
Definition: llinearpiecewisefunction.h:278
double getClosestParameter(T px, T py, int d1, int d2, T &n_min) const
Definition: llinearpiecewisefunction.h:1014
virtual DT limitLo() const override
Definition: llinearpiecewisefunction.h:264
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
virtual DT limitHi() const override
Definition: llinearpiecewisefunction.h:259
Definition: alanechangeview.h:27
direction
Definition: alanechangeview.h:42
Definition: alane.h:28
Definition: athreelaneview.h:30
Definition: conflictset.h:176
std::vector< Participant > TParticipantSet
Definition: participant.h:164
interval< T > atan2(interval< T > y, interval< T > x)
Definition: intervalarithmetic.h:234
T bound(T lb, T value, T ub)
Definition: adoremath.h:569
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
bool fromRelative(double s, double t, const T1 pi, const T1 pj, const T2 ni, const T2 nj, double &X, double &Y, double &Z)
Transform from relative coordinates to Euclidean coordinates.
Definition: adoremath.h:475
std::vector< TrafficObject > TrafficQueue
Definition: trafficobject.h:183
y0
Definition: adore_set_goal.py:26
y1
Definition: adore_set_pose.py:29
Definition: areaofeffectconverter.h:20
Definition: lanecombinedgeometry.h:27
std::shared_ptr< LaneGeometryDataProxy > center
Definition: lanecombinedgeometry.h:29
std::shared_ptr< LaneChangeDataProxy > rightChange
Definition: lanecombinedgeometry.h:35
std::shared_ptr< LaneChangeDataProxy > leftChange
Definition: lanecombinedgeometry.h:33
std::shared_ptr< LaneGeometryDataProxy > right
Definition: lanecombinedgeometry.h:34
std::shared_ptr< LaneGeometryDataProxy > left
Definition: lanecombinedgeometry.h:30
simple struct to hole data relevant to lane change geometry
Definition: lanechangedataproxy.h:32
double gate_s0
Definition: lanechangedataproxy.h:33
adore::view::ALaneChangeView::direction direction
Definition: lanechangedataproxy.h:35
adore::mad::function_type_scalar separatingBorderDistance_fct
Definition: lanechangedataproxy.h:38
adore::mad::function_type_scalar targetOuterBorderDistance_fct
Definition: lanechangedataproxy.h:37
double gate_s1
Definition: lanechangedataproxy.h:34
adore::mad::function_type_scalar sourceOuterBorderDistance_fct
Definition: lanechangedataproxy.h:39
Definition: lanegeometrydataproxy.h:25
adore::mad::function_type_scalar left_indicator_hint_fct
Definition: lanegeometrydataproxy.h:34
adore::mad::function_type_scalar navigationCost_fct
Definition: lanegeometrydataproxy.h:32
adore::mad::function_type_scalar centerSmoothedCurvature_fct
Definition: lanegeometrydataproxy.h:30
adore::mad::function_type_scalar right_indicator_hint_fct
Definition: lanegeometrydataproxy.h:35
adore::mad::function_type_scalar rightDistance_fct
Definition: lanegeometrydataproxy.h:28
bool isValid
Definition: lanegeometrydataproxy.h:37
adore::mad::function_type2d centerNormal_fct
Definition: lanegeometrydataproxy.h:29
adore::mad::function_type_scalar speedLimit_fct
Definition: lanegeometrydataproxy.h:33
adore::mad::function_type_scalar leftDistance_fct
Definition: lanegeometrydataproxy.h:27
adore::mad::function_type_xyz centerSmoothed_fct
Definition: lanegeometrydataproxy.h:26
adore::mad::function_type_scalar centerSmoothedCurvatureDerivative_fct
Definition: lanegeometrydataproxy.h:31