ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
occupancycylinderprediction.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 implementation and API
13  ********************************************************************************/
14 #pragma once
16 #include "participant.h"
17 #include "velocityprediction.h"
18 
19 namespace adore
20 {
21  namespace env
22  {
27  {
28  public:
31  int branchID_;
34  float confidence_;
35  };
36 
40  typedef std::vector<OccupancyCylinderPrediction> OccupancyCylinderPredictionSet;
41 
45  template <typename T>
47  {
48  public:
55  virtual bool predict(const T& p, OccupancyCylinderPredictionSet& set)const =0;
56  };
61  class OCStraightLinePrediction:public OCPredictionStrategy<traffic::Participant>
62  {
63  private:
64  double t_max_utc_;
66  double lat_error_;
67  double lon_error_;
68  double v_max_;
69  double a_max_;
70  double a_min_;
71  double time_headway_;
72  double time_leeway_;
73  double width_ub_;
74  double width_lb_;
76  public:
77  void setTMaxUTC(double value){t_max_utc_=value;}
78  void setLatPrecision(double value){lat_precision_=value;}
79  void setLatError(double value){lat_error_=value;}
80  void setLonError(double value){lon_error_=value;}
81  void setVMax(double value){v_max_=value;}
82  void setAMax(double value){a_max_=value;}
83  void setAMin(double value){a_min_=value;}
84  void setTimeHeadway(double value){time_headway_=value;}
85  void setTimeLeeway(double value){time_leeway_=value;}
86  void setWidthUB(double value){width_ub_=value;}
87  void setWidthLB(double value){width_lb_=value;}
89  a_max_(0.0),a_min_(0.0),time_headway_(2.0),time_leeway_(1.0),width_ub_(10.0),width_lb_(0.5){}
90  virtual bool predict(const traffic::Participant& p, OccupancyCylinderPredictionSet& set)const override
91  {
92  double width;
93  double length;
94  double psi;
95  double dx;
96  double dy;
97  double v = std::sqrt(p.getVx()*p.getVx()+p.getVy()*p.getVy());
98  const double form_factor = std::min(p.getWidth(),p.getLength())/std::max(p.getWidth(),p.getLength());
99  const double area = p.getWidth()*p.getLength();
100  auto pos0 = p.getCenter();
101  const double t0 = p.getObservationTime();
102  const double t1 = (std::max)(t0,t_max_utc_);
103  //huge objects: usually not on the road
104  if(area>100.0 && form_factor>0.8)
105  {
106  OccupancyCylinderPrediction prediction;
107  prediction.trackingID_ = p.getTrackingID();
108  prediction.v2xStationID_ = p.getStationID();
109  prediction.branchID_ = set.size();
110  prediction.predecessorID_ = -1;
111  prediction.confidence_ = 0.5;
112  double r = std::sqrt(p.getWidth()*p.getWidth()+p.getLength()*p.getLength())*0.5;
113  prediction.occupancy_.insert(adore::mad::OccupancyCylinder(r,pos0(0),pos0(1),t0,t1));
114  set.push_back(prediction);
115  return true;
116  }
117  //object orientation correction
118  if(p.getWidth()>p.getLength() && v<0.25)
119  {
120  width = p.getLength();
121  length = p.getWidth();
122  psi = p.getYaw() + M_PI*0.5;
123  dx = std::cos(psi);
124  dy = std::sin(psi);
125  v = 0.0;
126  }
127  else
128  {
129  length = p.getLength();
130  width = p.getWidth();
131  psi = p.getYaw();
132  const double cospsi = std::cos(psi);
133  const double sinpsi = std::sin(psi);
134  if(v<0.1)
135  {
136  dx = cospsi;
137  dy = sinpsi;
138  }
139  else
140  {
141  dx = cospsi * p.getVx()/v - sinpsi * p.getVy()/v;
142  dy = sinpsi * p.getVx()/v + cospsi * p.getVy()/v;
143  }
144  }
145  width = adore::mad::bound(width_lb_,width,width_ub_);
146  const double b = width*0.5 + lat_error_;
147  const double r = b+lat_precision_;
148  const double ds = 2.0 * std::sqrt(r*r-b*b);
149  const double dt = t1-t0;
150  const double l = length + 2.0*lon_error_;
151  const double k = (int)std::ceil(l/ds);
152  const double s0 = -k*ds*0.5 + 0.5*ds;
153  const double t_acc = a_max_>=0.0?dt:std::min((-v/a_max_),dt);
154  const double s1 = +k*ds*0.5 + v*dt + 0.5*a_max_*t_acc*t_acc - 0.5*ds;
157  RampPrediction ramp;
158  ramp.predict_s_tva(-l*0.5,v,a_min_,a_min_<0.0?0.0:v_max_,t0,0.1,t1,rear_end_s_tva);//lower bound: back of behicle with amin
159  ramp.predict_s_tva(+l*0.5,v,a_max_,a_max_<0.0?0.0:v_max_,t0,0.1,t1,front_end_s_tva);//upper bound: front of vehicle with amax
160 
161  OccupancyCylinderPrediction prediction;
162  prediction.trackingID_ = p.getTrackingID();
163  prediction.v2xStationID_ = p.getStationID();
164  prediction.branchID_ = set.size();
165  prediction.predecessorID_ = -1;
166  prediction.confidence_ = 1.0;
167  for(double s = s0;s<=s1;s+=ds)
168  {
169  const double x = pos0(0) + dx * s;
170  const double y = pos0(1) + dy * s;
171  double t0i,t1i;
172  //first time entering circle with front of vehicle
173  t0i = front_end_s_tva.f(adore::mad::bound(front_end_s_tva.limitLo(),s-ds*0.5,front_end_s_tva.limitHi()))(0);
174  t0i -= time_headway_;
175  //latest time exiting circle with back of vehicle
176  t1i = rear_end_s_tva.f(adore::mad::bound(rear_end_s_tva.limitLo(),s+ds*0.5,rear_end_s_tva.limitHi()))(0);
177  t1i += time_leeway_;
178  prediction.occupancy_.insert(adore::mad::OccupancyCylinder(r,x,y,t0i,t1i));
179  }
180  set.push_back(prediction);
181  return true;
182  }
183 
184  };
185  }
186 }
#define M_PI
Definition: arraymatrixtools.h:24
Definition: occupancycylinderprediction.h:47
virtual bool predict(const T &p, OccupancyCylinderPredictionSet &set) const =0
Definition: occupancycylinderprediction.h:62
double lat_error_
Definition: occupancycylinderprediction.h:66
double a_min_
Definition: occupancycylinderprediction.h:70
double width_lb_
Definition: occupancycylinderprediction.h:74
double lat_precision_
Definition: occupancycylinderprediction.h:65
void setWidthLB(double value)
Definition: occupancycylinderprediction.h:87
void setVMax(double value)
Definition: occupancycylinderprediction.h:81
void setLatError(double value)
Definition: occupancycylinderprediction.h:79
double lon_error_
Definition: occupancycylinderprediction.h:67
double width_ub_
Definition: occupancycylinderprediction.h:73
void setLatPrecision(double value)
Definition: occupancycylinderprediction.h:78
void setWidthUB(double value)
Definition: occupancycylinderprediction.h:86
void setTimeLeeway(double value)
Definition: occupancycylinderprediction.h:85
void setTMaxUTC(double value)
Definition: occupancycylinderprediction.h:77
double a_max_
Definition: occupancycylinderprediction.h:69
double t_max_utc_
Definition: occupancycylinderprediction.h:64
double time_leeway_
Definition: occupancycylinderprediction.h:72
void setAMax(double value)
Definition: occupancycylinderprediction.h:82
virtual bool predict(const traffic::Participant &p, OccupancyCylinderPredictionSet &set) const override
Definition: occupancycylinderprediction.h:90
OCStraightLinePrediction()
Definition: occupancycylinderprediction.h:88
void setAMin(double value)
Definition: occupancycylinderprediction.h:83
void setLonError(double value)
Definition: occupancycylinderprediction.h:80
double v_max_
Definition: occupancycylinderprediction.h:68
double time_headway_
Definition: occupancycylinderprediction.h:71
void setTimeHeadway(double value)
Definition: occupancycylinderprediction.h:84
Definition: velocityprediction.h:22
void predict_s_tva(double s0, double v0, double a0, double delay, double a1, double vbound, double t0, double dt, double t1, adore::mad::LLinearPiecewiseFunctionM< double, 3 > &result)
Definition: velocityprediction.h:24
virtual CT f(DT x) const override
Definition: llinearpiecewisefunction.h:251
virtual DT limitLo() const override
Definition: llinearpiecewisefunction.h:264
virtual DT limitHi() const override
Definition: llinearpiecewisefunction.h:259
Definition: occupancycylinder.h:84
void insert(const VolumeType &volume)
Definition: vectorbasedvolumetree.h:90
std::vector< OccupancyCylinderPrediction > OccupancyCylinderPredictionSet
Definition: occupancycylinderprediction.h:40
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
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
void set(T *data, T value, int size)
Definition: adoremath.h:39
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
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
Definition: occupancycylinderprediction.h:27
int branchID_
Definition: occupancycylinderprediction.h:31
int trackingID_
Definition: occupancycylinderprediction.h:30
int v2xStationID_
Definition: occupancycylinderprediction.h:29
adore::mad::OccupancyCylinderTree occupancy_
Definition: occupancycylinderprediction.h:33
float confidence_
Definition: occupancycylinderprediction.h:34
int predecessorID_
Definition: occupancycylinderprediction.h:32
Struct for representing a participant in traffic.
Definition: participant.h:30
double getLength() const
Definition: participant.h:155
TTrackingID getTrackingID() const
Definition: participant.h:109
double getObservationTime() const
Definition: participant.h:112
const adoreMatrix< double, 3, 1 > & getCenter() const
Definition: participant.h:124
double getYaw() const
Definition: participant.h:154
TV2XStationID getStationID() const
Definition: participant.h:110
double getWidth() const
Definition: participant.h:156
double getVy() const
Definition: participant.h:158
double getVx() const
Definition: participant.h:157
Definition: occupancycylinder.h:25