ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
crosstraffic_constraint_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  * Daniel Heß - compute constraints, which help to avoid crosstraffic
13  ********************************************************************************/
14 
15 
16 #pragma once
17 
18 #include <adore/env/afactory.h>
19 #include <adore/params/afactory.h>
21 #include <unordered_set>
22 #include <vector>
23 
24 
25 namespace adore
26 {
27  namespace apps
28  {
29 
30 
35  {
36  private:
37  struct Conflict
38  {
39  double x,y,s,n,t0,t1,rxy;
41  Conflict(double x,double y,double s,double n,double t0,double t1,double rxy,adore::view::TrafficObject::TTrackingID id)
42  :x(x),y(y),s(s),n(n),t0(t0),t1(t1),rxy(rxy),id(id){}
43  };
47 
54  public:
56  {
57  delete prediction_reader_;
58  delete vehicle_state_reader_;
59  }
61  {
68  }
73  virtual void update()
74  {
76  if(!vehicle_state_reader_->hasData())return;
77  vehicle_state_reader_->getData(vehicle_state);
78 
81  {
82  ocp_set_.clear();
84  }
85 
86  if( three_lanes_.getCurrentLane()!=nullptr
88  {
89  double s_lower_bound,s_ego,n_ego,ds_ego;
90  three_lanes_.getCurrentLane()->toRelativeCoordinates(vehicle_state.getX(),vehicle_state.getY(),s_ego,n_ego);
91  ds_ego = vehicle_state.getvx();
92  double acc = (std::abs)(plplanner_->getAccLB()-0.05);
93  double distance_to_point = plplanner_->getStopDistanceToConflictPoint();
94  s_lower_bound = s_ego + 0.5 * ds_ego * ds_ego / acc + pvehicle_->get_a() + pvehicle_->get_b() + pvehicle_->get_c() + distance_to_point;
95 
96  std::unordered_set<adore::view::TrafficObject::TTrackingID> parallel_traffic_ids;
97 
98  add_ids(parallel_traffic_ids,three_lanes_.getCurrentLane()->getOnLaneTraffic());
101  {
103  }
106  {
108  }
109 
110  std::vector<Conflict> conflict_set;
111 
112  for(auto& element:ocp_set_)
113  {
114  if(parallel_traffic_ids.find(element.trackingID_)==parallel_traffic_ids.end())
115  {
116  // for(auto& cylinder:element.occupancy_.getLevel(element.occupancy_.getLevelCount()-1))
117  for(auto& cylinder:element.occupancy_.getLevel(0))
118  {
119  double x,y,s,n,xc,yc,zc;
120  x = cylinder.second.x_;
121  y = cylinder.second.y_;
123  if(s - cylinder.second.rxy_<s_lower_bound)continue;
125  double d = std::sqrt((x-xc)*(x-xc)+(y-yc)*(y-yc));
126  if(d-cylinder.second.rxy_>max_centerline_distance_)continue;
127  // if(s + cylinder.second.rxy_< s_ego - pvehicle_->get_d() + ds_ego * (std::max)(0.0,cylinder.second.t0_-vehicle_state.getTime()))continue;
128  conflict_set.push_back(Conflict(xc,yc,s - cylinder.second.rxy_,n,cylinder.second.t0_,cylinder.second.t1_,cylinder.second.rxy_,element.trackingID_));
129  }
130  }
131  }
132 
133  std::sort(conflict_set.begin(),conflict_set.end(),[](Conflict a,Conflict b){return a.s<b.s;});
134 
135  std::cout<<"-----------------------------------------"<<std::endl;
136  for(auto& c:conflict_set)
137  {
138  std::cout<<"s="<<c.s-s_lower_bound<<", t0="<<c.t0-vehicle_state.getTime()<<", t1="<<c.t1-vehicle_state.getTime()<<std::endl;
139  break;
140  }
141 
142  std::vector<adore::env::OccupancyCylinderPrediction> ocps;
143  if(conflict_set.size()>0)
144  {
145  adore::env::OccupancyCylinderPredictionSet conflictset_ocp;//reusing class/data transfer
146  auto item = conflict_set[0];
148  adore::mad::OccupancyCylinder oc(item.rxy,item.x,item.y,item.t0,item.t1);
149  ocp.occupancy_.insert(oc);
150  ocp.trackingID_ = item.id;
151  ocp.branchID_ = 0;
152  ocp.predecessorID_ = -1;
153  ocp.confidence_ = 1.0;
154  ocps.push_back(ocp);
155  }
157  }
158 
159  }
160  private:
161  void add_ids(std::unordered_set<adore::view::TrafficObject::TTrackingID>& parallel_traffic_ids,const adore::view::TrafficQueue& queue)
162  {
163  for(const auto& object:queue)
164  {
165  parallel_traffic_ids.insert(object.getTrackingID());
166  }
167  }
168  };
169  }
170 }
Definition: crosstraffic_constraint_provider.h:35
adore::env::ThreeLaneViewDecoupled three_lanes_
Definition: crosstraffic_constraint_provider.h:44
virtual void update()
update data, views and recompute constraints
Definition: crosstraffic_constraint_provider.h:73
adore::env::AFactory::TOCPredictionSetWriter * conflict_set_writer_
Definition: crosstraffic_constraint_provider.h:46
void add_ids(std::unordered_set< adore::view::TrafficObject::TTrackingID > &parallel_traffic_ids, const adore::view::TrafficQueue &queue)
Definition: crosstraffic_constraint_provider.h:161
adore::env::AFactory::TOCPredictionSetReader * prediction_reader_
Definition: crosstraffic_constraint_provider.h:45
double max_centerline_distance_
Definition: crosstraffic_constraint_provider.h:52
adore::params::APLongitudinalPlanner * plplanner_
Definition: crosstraffic_constraint_provider.h:51
adore::params::APVehicle * pvehicle_
Definition: crosstraffic_constraint_provider.h:50
adore::env::OccupancyCylinderPredictionSet ocp_set_
Definition: crosstraffic_constraint_provider.h:48
CrosstrafficConstraintProvider()
Definition: crosstraffic_constraint_provider.h:60
virtual ~CrosstrafficConstraintProvider()
Definition: crosstraffic_constraint_provider.h:55
adore::env::AFactory::TVehicleMotionStateReader * vehicle_state_reader_
Definition: crosstraffic_constraint_provider.h:49
virtual TOCPredictionSetWriter * getConflictSetWriter()=0
virtual TOCPredictionSetReader * getExpectedPredictionSetReader()=0
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
static adore::env::AFactory * get()
Definition: afactory.h:236
Definition: threelaneviewdecoupled.h:32
virtual adore::view::ALaneChangeView * getLeftLaneChange()
Definition: threelaneviewdecoupled.h:412
virtual adore::view::ALaneChangeView * getRightLaneChange()
Definition: threelaneviewdecoupled.h:419
virtual adore::view::ALane * getCurrentLane()
Definition: threelaneviewdecoupled.h:405
void update()
Definition: threelaneviewdecoupled.h:373
Definition: com_patterns.h:68
virtual void getData(T &value)=0
virtual bool hasData() const =0
virtual bool hasUpdate() const =0
Definition: com_patterns.h:97
virtual void write(const T &value)=0
void insert(const VolumeType &volume)
Definition: vectorbasedvolumetree.h:90
virtual APVehicle * getVehicle() const =0
virtual APLongitudinalPlanner * getLongitudinalPlanner() const =0
abstract class containing parameters related to configuring the longitudinal planner
Definition: ap_longitudinal_planner.h:26
virtual double getStopDistanceToConflictPoint() const =0
distance between stop position and conflict point
virtual double getAccLB() const =0
getAccLB returns longitudinal acceleration lower bound
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_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
virtual ALane * getTargetLane()=0
virtual void toRelativeCoordinates(double xe, double ye, double &s, double &n)=0
virtual const TrafficQueue & getOnLaneTraffic() const =0
virtual void toEucledianCoordinates(double s, double n, double &xe, double &ye, double &ze)=0
virtual bool isValid() const =0
std::vector< OccupancyCylinderPrediction > OccupancyCylinderPredictionSet
Definition: occupancycylinderprediction.h:40
std::vector< TrafficObject > TrafficQueue
Definition: trafficobject.h:183
x
Definition: adore_set_goal.py:30
y
Definition: adore_set_goal.py:31
Definition: areaofeffectconverter.h:20
Definition: crosstraffic_constraint_provider.h:38
double x
Definition: crosstraffic_constraint_provider.h:39
Conflict(double x, double y, double s, double n, double t0, double t1, double rxy, adore::view::TrafficObject::TTrackingID id)
Definition: crosstraffic_constraint_provider.h:41
adore::view::TrafficObject::TTrackingID id
Definition: crosstraffic_constraint_provider.h:40
double rxy
Definition: crosstraffic_constraint_provider.h:39
double t1
Definition: crosstraffic_constraint_provider.h:39
double s
Definition: crosstraffic_constraint_provider.h:39
double n
Definition: crosstraffic_constraint_provider.h:39
double y
Definition: crosstraffic_constraint_provider.h:39
double t0
Definition: crosstraffic_constraint_provider.h:39
Definition: occupancycylinderprediction.h:27
int branchID_
Definition: occupancycylinderprediction.h:31
int trackingID_
Definition: occupancycylinderprediction.h:30
adore::mad::OccupancyCylinderTree occupancy_
Definition: occupancycylinderprediction.h:33
float confidence_
Definition: occupancycylinderprediction.h:34
int predecessorID_
Definition: occupancycylinderprediction.h:32
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 getvx() const
Get the longitudinal velocity.
Definition: vehiclemotionstate9d.h:78
double getY() const
Get the y-coordinate.
Definition: vehiclemotionstate9d.h:60
double getTime() const
Get the time.
Definition: vehiclemotionstate9d.h:48
Definition: occupancycylinder.h:25
int TTrackingID
Definition: trafficobject.h:29