ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
trajectory_planner_lf.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ß - trajectory planner for lane following maneuvers
13  ********************************************************************************/
14 
15 
16 #pragma once
17 
18 #include <adore/fun/afactory.h>
19 #include <adore/env/afactory.h>
20 #include <adore/params/afactory.h>
31 
32 
33 namespace adore
34 {
35  namespace apps
36  {
41  {
42  private:
47 
58  protected:
60  private:
72  int id_;
73  std::string plannerName_;
76  public:
78  {
79  delete nominal_planner_;
80  delete emergency_planner_;
81  }
82  TrajectoryPlannerLF(int id=0,std::string plannerName = "lane-following",double lateral_i_grid = 0.0):
83  connectionSet_(adore::env::EnvFactoryInstance::get()->getVehicleMotionStateReader(),
84  adore::env::EnvFactoryInstance::get()->getControlledConnectionFeed()),
85  checkPointSet_(adore::env::EnvFactoryInstance::get()->getVehicleMotionStateReader(),
86  adore::env::EnvFactoryInstance::get()->getCheckPointFeed()),
87  ngo_(adore::env::EnvFactoryInstance::get(),three_lanes_.getCurrentLane(),0,0),
88  prediction_(),
90  conflicts_(three_lanes_.getCurrentLane()),
93  {
94  id_ = id;
95  lateral_i_grid_ = lateral_i_grid;
96  const_penalty_ = 0.0;
97  plannerName_ = plannerName;
103  auto pLongitudinalPlanner = adore::params::ParamsFactoryInstance::get()->getLongitudinalPlanner();
108  //create nominal planner and add additional constraints
111  &ngo_,
114  pLongitudinalPlanner,
115  pLateralPlanner,
116  pTacticalPlanner,
117  pvehicle_,
119  lateral_i_grid);
120 
121  //create emergency planner
123  pLateralPlanner,
124  pTacticalPlanner,
125  pvehicle_,
127  lateral_i_grid);
133 
134  }
135  void setConstPenalty(double value)
136  {
137  const_penalty_ = value;
138  }
139  void setSpeedScale(double value)
140  {
142  }
144  {
145  nominal_planner_->addConstraint(constraint);
146  }
147  void setStopPoint(int value)
148  {
149  if(value<0)
150  {
152  }
153  else
154  {
156  }
157 
158  }
159 
164  virtual void computeTrajectory(const adore::fun::PlanningRequest& planning_request, adore::fun::PlanningResult& planning_result) override
165  {
166  //document planner result
167  planning_result.id = id_; // in lfbehavior, there is only one maneuver
168  planning_result.name = plannerName_;
170  planning_result.iteration = planning_request.iteration;
171  planning_result.nominal_maneuver_valid = false;
172  planning_result.combined_maneuver_valid = false;
173 
175  auto current = three_lanes_.getCurrentLane();
176  ngo_.update();
181  conflicts_.update();
182 
183 
184  if(!current->isValid())
185  {
186  planning_result.status_string = "current lane invalid";
187  return;
188  }
189 
191 
192  auto x0=planning_request.initial_state.toMotionState();
195  {
196  planning_result.status_string = "nominal maneuver planning failed, "+ nominal_planner_->getStatus();
197  return;
198  }
199 
201  planning_result.nominal_maneuver_valid = true;
205 
206  // adore::fun::RestartEffort re; //test whether trajectory is long enough to justify restarting from ~0
207  // if(!re.isValid(planning_result.nominal_maneuver))
208  // {
209  // planning_result.status_string = "not restarting, maneuver too short";
210  // return;
211  // }
212 
213  //if emergencyManeuverAMax and AMin are different, compute three maneuvers for {amin, (amin+amax)/2, amax}
214  //otherwise compute just one maneuver for amin
215  std::vector<double> emergency_acceleration;
216  emergency_acceleration.push_back(pEmergencyOperation_->getEmergencyManeuverAMin());
219  {
220  emergency_acceleration.push_back((pEmergencyOperation_->getEmergencyManeuverAMin()
222  emergency_acceleration.push_back(pEmergencyOperation_->getEmergencyManeuverAMax());
223  }
224 
225  bool collision_detection_passed = false;
226 
227  for(double a_em:emergency_acceleration)
228  {
231  emergency_planner_->compute(x0em.toMotionState());
232 
234  {
235  continue;
236  }
237 
238  planning_result.combined_maneuver.setPoints.clear();
240  planning_result.combined_maneuver.removeAfter(planning_request.t_emergency_start);
241  planning_result.combined_maneuver.setPoints.back().tEnd = planning_request.t_emergency_start;
243 
244 
245  if(collision_detection_.isValid(planning_result.combined_maneuver))
246  {
247  collision_detection_passed = true;
248  break;
249  }
250  }
251 
252 
254  {
255  planning_result.status_string += "emergency maneuver planning failed";
256  return;
257  }
258 
259  double front_buffer_space = pTacticalPlanner_->getCollisionDetectionFrontBufferSpace();
260  double lateral_precision = pTacticalPlanner_->getCollisionDetectionLateralPrecision();
262  pvehicle_->get_a()+pvehicle_->get_b()+pvehicle_->get_c()+pvehicle_->get_d()+front_buffer_space,
264  pvehicle_->get_d(),//spr reference point at rear axle
265  lateral_precision);
269  spr_swath.append_cylinder_swath_linear(planning_result.combined_maneuver,planning_result.combined_maneuver_swath,true);
271  spr_swath.append_cylinder_swath_linear(planning_result.nominal_maneuver,planning_result.nominal_maneuver_swath,true);
272 
273  if(!collision_detection_passed)
274  {
275  planning_result.status_string = "collision detected for combined maneuver";
276  return;
277  }
278 
280  if(planning_result.combined_maneuver.setPoints.size()==0)
281  {
282  planning_result.status_string = "stopping";
283  return;
284  }
285 
286  planning_result.combined_maneuver_valid = true;
287  int laneid = 0;
289  planning_result.objective_values.insert({navcostOnLane.getName(),
290  navcostOnLane.getCost(planning_result.nominal_maneuver)});
291 
293  planning_result.objective_values.insert({navcostNormalized.getName(),
294  navcostNormalized.getCost(planning_result.nominal_maneuver)});
295 
297  planning_result.objective_values.insert({lacccost.getName(),
298  lacccost.getCost(planning_result.nominal_maneuver)});
299 
301  planning_result.objective_values.insert({ljerkcost.getName(),
302  ljerkcost.getCost(planning_result.nominal_maneuver)});
303 
305  planning_result.objective_values.insert({progressLoss.getName(),
306  progressLoss.getCost(planning_result.nominal_maneuver)});
307 
308  planning_result.objective_values.insert({"const_penalty",const_penalty_});
309 
310  //ttc cost
311  planning_result.objective_values.insert({ttcCost_.getName(),
312  ttcCost_.getCost(planning_result.nominal_maneuver)});
313 
314 
316  {
317  case 0://turned off
318  {
319  planning_result.objective_values.insert({coercion_detection_.getName(),0.0});
320  }
321  break;
322  case 1://encode as objective value
323  {
324  planning_result.objective_values.insert({coercion_detection_.getName(),
326  ? 0.0 : 1.0});
327  }
328  break;
329  case 2://encode as constraint
330  {
331  bool coercion_detection_passed = coercion_detection_.isValid(planning_result.nominal_maneuver);
332  planning_result.combined_maneuver_valid = coercion_detection_passed && planning_result.combined_maneuver_valid;
333  if(!coercion_detection_passed)
334  {
335  planning_result.status_string = "coercion detected for nominal maneuver";
336  }
337  }
338  break;
339  }
340 
341 
342 
343  int number_of_time_steps = nominal_planner_->getProgressSolver().lbx().nc();
344  auto time_steps = adore::mad::linspace(nominal_planner_->getPlanningHorizon()/number_of_time_steps,nominal_planner_->getPlanningHorizon(),number_of_time_steps);
346  planning_result.nominal_maneuver_longitudinal_lbx.getData() = dlib::join_cols(time_steps,nominal_planner_->getProgressSolver().lbx());
347  planning_result.nominal_maneuver_longitudinal_ubx.getData() = dlib::join_cols(time_steps,nominal_planner_->getProgressSolver().ubx());
349  planning_result.nominal_maneuver_lateral_lbx.getData() = dlib::join_cols(time_steps,nominal_planner_->getOffsetSolver().lbx());
350  planning_result.nominal_maneuver_lateral_ubx.getData() = dlib::join_cols(time_steps,nominal_planner_->getOffsetSolver().ubx());
351 
352  //indicator activation if hinted at
353  double s,n;
354  current->toRelativeCoordinates(planning_request.initial_state.x0ref.getX(),
355  planning_request.initial_state.x0ref.getY(),
356  s,n);
357  // double sg0 = target_lc->getProgressOfGateOpen();
358  // double indicator_lookahead = pTacticalPlanner_->getIndicatorLookahead();
359  // if(s+indicator_lookahead>sg0)
360  {
361  planning_result.indicator_left = current->getLeftIndicatorHint(s);
362  planning_result.indicator_right = current->getRightIndicatorHint(s);
363  }
364 
365  }
366  };
367  }
368 }
Base class for different trajectory planners: Handles communication w/ decision making module....
Definition: trajectory_planner_base.h:31
Decoupled trajectory planner, which uses TrajectoryPlannerBase to compute and provide a PlanningResul...
Definition: trajectory_planner_lf.h:41
void setStopPoint(int value)
Definition: trajectory_planner_lf.h:147
double const_penalty_
Definition: trajectory_planner_lf.h:75
virtual void computeTrajectory(const adore::fun::PlanningRequest &planning_request, adore::fun::PlanningResult &planning_result) override
update data, views and recompute maneuver
Definition: trajectory_planner_lf.h:164
adore::fun::SPRTTCNominal ttcCost_
Definition: trajectory_planner_lf.h:62
double lateral_i_grid_
Definition: trajectory_planner_lf.h:74
adore::env::ThreeLaneViewDecoupled three_lanes_
Definition: trajectory_planner_lf.h:59
virtual ~TrajectoryPlannerLF()
Definition: trajectory_planner_lf.h:77
std::string plannerName_
Definition: trajectory_planner_lf.h:73
adore::fun::BasicLaneFollowingPlanner< 20, 5 > TNominalPlanner
Definition: trajectory_planner_lf.h:43
adore::env::ControlledConnectionSet4Ego checkPointSet_
Definition: trajectory_planner_lf.h:55
adore::env::DecoupledConflictPointView conflicts_
Definition: trajectory_planner_lf.h:64
adore::params::APVehicle * pvehicle_
Definition: trajectory_planner_lf.h:48
adore::params::APEmergencyOperation * pEmergencyOperation_
Definition: trajectory_planner_lf.h:51
adore::params::APPrediction * ppred_
Definition: trajectory_planner_lf.h:52
adore::fun::SPRNonCoercive coercion_detection_
Definition: trajectory_planner_lf.h:63
void addConstraint(fun::ANominalConstraint *constraint)
Definition: trajectory_planner_lf.h:143
adore::env::ConnectionsOnLane * checkPointsOnLane_
Definition: trajectory_planner_lf.h:57
adore::fun::BasicMRMPlanner< 20, 5 > TEmergencyPlanner
Definition: trajectory_planner_lf.h:44
adore::env::ControlledConnectionSet4Ego connectionSet_
Definition: trajectory_planner_lf.h:54
TrajectoryPlannerLF(int id=0, std::string plannerName="lane-following", double lateral_i_grid=0.0)
Definition: trajectory_planner_lf.h:82
TNominalPlanner * nominal_planner_
Definition: trajectory_planner_lf.h:45
TEmergencyPlanner * emergency_planner_
Definition: trajectory_planner_lf.h:46
int id_
Definition: trajectory_planner_lf.h:72
adore::params::APTacticalPlanner * pTacticalPlanner_
Definition: trajectory_planner_lf.h:49
adore::params::APTrajectoryGeneration * pTrajectoryGeneration_
Definition: trajectory_planner_lf.h:50
adore::fun::SPRInvariantCollisionFreedom collision_detection_
Definition: trajectory_planner_lf.h:69
adore::env::DecoupledTrafficPredictionView prediction_
Definition: trajectory_planner_lf.h:61
void setSpeedScale(double value)
Definition: trajectory_planner_lf.h:139
adore::env::ConnectionsOnLane * connectionsOnLane_
Definition: trajectory_planner_lf.h:56
adore::env::NavigationGoalObserver ngo_
Definition: trajectory_planner_lf.h:53
void setConstPenalty(double value)
Definition: trajectory_planner_lf.h:135
Definition: connectionsonlane.h:33
void update()
Definition: connectionsonlane.h:82
Specialization of ControlledConnectionSet: Filters connections in range of ego.
Definition: controlledconnection.h:232
virtual void update()
Definition: controlledconnection.h:243
Definition: decoupledconflictpointview.h:25
void update()
Definition: decoupledconflictpointview.h:36
Definition: decoupledtrafficpredictionview.h:24
void update()
Definition: decoupledtrafficpredictionview.h:43
Definition: navigationgoalobserver.h:31
void update()
Definition: navigationgoalobserver.h:56
Definition: threelaneviewdecoupled.h:32
virtual adore::view::ALane * getCurrentLane()
Definition: threelaneviewdecoupled.h:405
void update()
Definition: threelaneviewdecoupled.h:373
Definition: anominalplanner.h:52
Definition: basiclanefollowingplanner.h:37
void addConstraint(ANominalConstraint *constraint)
Definition: basiclanefollowingplanner.h:142
void setConflictSet(adore::view::AConflictPointSet *conflicts)
Definition: basiclanefollowingplanner.h:158
void setSpeedScale(double value)
Definition: basiclanefollowingplanner.h:154
Plans minimum risk maneuvers on given lane. K number of control points for planning....
Definition: basicmrmplanner.h:36
double getPlanningHorizon() const
Definition: decoupled_lflc_planner.h:327
virtual const SetPointRequest * getSetPointRequest() const override
Definition: decoupled_lflc_planner.h:491
TProgressSolver & getProgressSolver()
Definition: decoupled_lflc_planner.h:335
std::string getStatus()
Definition: decoupled_lflc_planner.h:348
virtual bool hasValidPlan() const override
Definition: decoupled_lflc_planner.h:484
TOffsetSolver & getOffsetSolver()
Definition: decoupled_lflc_planner.h:339
virtual void compute(const VehicleMotionState9d &initial_state) override
Definition: decoupled_lflc_planner.h:372
virtual const SetPointRequest * getSetPointRequest() const
Definition: mrmplanner.h:273
void setAMin(double value)
Definition: mrmplanner.h:55
void setTStall(double value)
Definition: mrmplanner.h:53
virtual void compute(const VehicleMotionState9d &initial_state)
Definition: mrmplanner.h:175
void setJMax(double value)
Definition: mrmplanner.h:52
void setAStall(double value)
Definition: mrmplanner.h:54
void setSecondAttempt(bool value)
Definition: mrmplanner.h:56
virtual bool hasValidPlan() const
Definition: mrmplanner.h:266
Definition: basicsetpointrequestevaluators.h:148
virtual double getCost(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:155
virtual std::string getName() const override
Definition: basicsetpointrequestevaluators.h:154
Definition: basicsetpointrequestevaluators.h:32
virtual bool isValid(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:46
Definition: basicsetpointrequestevaluators.h:364
virtual std::string getName() const override
Definition: basicsetpointrequestevaluators.h:366
virtual double getCost(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:367
Definition: basicsetpointrequestevaluators.h:378
virtual double getCost(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:381
virtual std::string getName() const override
Definition: basicsetpointrequestevaluators.h:380
Definition: basicsetpointrequestevaluators.h:178
virtual std::string getName() const override
Definition: basicsetpointrequestevaluators.h:189
virtual double getCost(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:190
Definition: basicsetpointrequestevaluators.h:68
std::string getName() const
Definition: basicsetpointrequestevaluators.h:99
virtual bool isValid(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:82
Definition: basicsetpointrequestevaluators.h:256
virtual double getCost(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:268
virtual std::string getName() const override
Definition: basicsetpointrequestevaluators.h:267
Definition: basicsetpointrequestevaluators.h:107
virtual double getCost(const adore::fun::SetPointRequest &spr) const override
Definition: basicsetpointrequestevaluators.h:117
virtual std::string getName() const override
Definition: basicsetpointrequestevaluators.h:116
Definition: setpointrequestswath.h:26
void append_cylinder_swath_linear(const SetPointRequest &spr, adore::mad::OccupancyCylinderTree &prediction, bool terminal=false)
Definition: setpointrequestswath.h:55
void setLonError(double value)
Definition: setpointrequestswath.h:42
void setAccelerationErrorSlow(double value)
Definition: setpointrequestswath.h:44
void setDuration(double value)
Definition: setpointrequestswath.h:43
void setLatError(double value)
Definition: setpointrequestswath.h:41
void cropAfterFirstStop(double vxslow)
remove SetPoints after first stop Method looks for first downward zero crossing of vx and removes all...
Definition: setpointrequest.h:412
SetPoint interpolateSetPoint(double t, adore::params::APVehicle *p) const
Definition: setpointrequest.h:145
void removeAfter(double t)
Definition: setpointrequest.h:211
void copyTo(SetPointRequest &destination) const
Definition: setpointrequest.h:293
std::vector< SetPoint > setPoints
Definition: setpointrequest.h:38
PlanarVehicleState10d x0ref
Definition: setpoint.h:32
VehicleMotionState9d toMotionState() const
Definition: setpoint.h:46
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
t_lbx & lbx()
Definition: lq_oc_single_shooting.h:713
t_ubx & ubx()
Definition: lq_oc_single_shooting.h:714
t_resultfun & result_fun()
Definition: lq_oc_single_shooting.h:704
virtual APLateralPlanner * getLateralPlanner() const =0
virtual APTacticalPlanner * getTacticalPlanner() const =0
virtual APTrajectoryGeneration * getTrajectoryGeneration() const =0
virtual APVehicle * getVehicle() const =0
virtual APPrediction * getPrediction() const =0
virtual APEmergencyOperation * getEmergencyOperation() const =0
virtual APLongitudinalPlanner * getLongitudinalPlanner() const =0
abstract class containing parameters concerning emergency operation behaviour
Definition: ap_emergency_operation.h:25
virtual double getEmergencyManeuverAMax() const =0
virtual double getEmergencyManeuverJMin() const =0
virtual double getEmergencyManeuverAMin() const =0
virtual double getEmergencyManeuverTStall() const =0
parameter interface for parameters related to prediction
Definition: ap_prediction.h:28
virtual double get_roadbased_prediction_duration() const =0
prediction duration for objects that can be matched to road
abstract classs containing parameters to configure aspects and constraints of the tactical planner
Definition: ap_tactical_planner.h:25
virtual int getCoercionPreventionStrategy() const =0
getCoercionPreventionStrategy returns 0 switched off, 1 objective function, 2 constraint
virtual double getCollisionDetectionLateralError() const =0
virtual double getTerminateAfterFirstStopThresholdSpeed() const =0
virtual double getCollisionDetectionFrontBufferSpace() const =0
virtual double getCollisionDetectionLongitudinalError() const =0
virtual double getCollisionDetectionLateralPrecision() const =0
virtual double getNominalSwathAccelerationError() const =0
abstract class containing parameters to configure the behaviour of trajectory generation
Definition: ap_trajectory_generation.h:26
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
adoreMatrix< T, 1, n > linspace(T x0, T x1)
Definition: adoremath.h:91
x0
Definition: adore_set_goal.py:25
Definition: areaofeffectconverter.h:20
double getX() const
Definition: planarvehiclestate10d.h:62
double getY() const
Definition: planarvehiclestate10d.h:63
Definition: planning_request.h:22
double t_emergency_start
Definition: planning_request.h:26
SetPoint initial_state
Definition: planning_request.h:27
long long int iteration
Definition: planning_request.h:23
Definition: planning_result.h:29
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_lateral_lbx
Definition: planning_result.h:56
bool combined_maneuver_valid
Definition: planning_result.h:64
adore::mad::LLinearPiecewiseFunctionM< double, 4 > nominal_maneuver_longitudinal_plan
Definition: planning_result.h:43
std::string name
Definition: planning_result.h:32
static const int NOMINAL_DRIVING
Definition: planning_result.h:75
adore::mad::LLinearPiecewiseFunctionM< double, 4 > nominal_maneuver_lateral_plan
Definition: planning_result.h:54
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_longitudinal_lbx
Definition: planning_result.h:46
std::string status_string
Definition: planning_result.h:65
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_lateral_ubx
Definition: planning_result.h:59
std::unordered_map< std::string, double > objective_values
Definition: planning_result.h:68
int id
Definition: planning_result.h:30
int maneuver_type
Definition: planning_result.h:72
adore::mad::OccupancyCylinderTree combined_maneuver_swath
Definition: planning_result.h:40
bool indicator_right
Definition: planning_result.h:77
bool nominal_maneuver_valid
Definition: planning_result.h:63
int iteration
Definition: planning_result.h:31
adore::mad::OccupancyCylinderTree nominal_maneuver_swath
Definition: planning_result.h:38
bool indicator_left
Definition: planning_result.h:76
SetPointRequest nominal_maneuver
Definition: planning_result.h:33
SetPointRequest combined_maneuver
Definition: planning_result.h:35
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_longitudinal_ubx
Definition: planning_result.h:50