ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
lateralplanner.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 "anominalplanner.h"
18 #include "roadcoordinates.h"
19 #include <adore/view/alane.h>
21 #include <adore/mad/adoremath.h>
25 
26 namespace adore
27 {
28  namespace fun
29  {
39  template<int K,int P>
41  {
42  public:
43  static const int N = 3;//number of states
44  static const int R = 1;//number of inputs
45  // static const int K = 20;//number of optimization time steps
46  // static const int P = 5;//number of post-interpolation steps
51  protected:
52  TInformationSet info_;//reference and constraint defintion
53  private://solvers, constraint/reference definitions, initial state
54  TOffsetSolver offset_solver_;//solver for lateral planning
55  double n0_,dn0_,ddn0_;//lateral initial state
56  double T_[K+1];
57  double T_end_;
63  bool valid_;
64 
66  {
67  //default values for cost function of lateral optimization problem
68  offset_solver_.wx()(0) = 6.0;
69  offset_solver_.wx()(1) = 1.0;
70  offset_solver_.wx()(2) = 1.0;
71  offset_solver_.wu()(0) = 1.0;
72  offset_solver_.wx_end()(0) = 0.0;
73  offset_solver_.wx_end()(1) = 0.0;
74  offset_solver_.wx_end()(2) = 0.0;
75  offset_solver_.geps()(0) = 1.0e1;
76  offset_solver_.geps()(1) = 1.0e1;
77  offset_solver_.geps()(2) = 1.0e1;
78  offset_solver_.ubeps()(0) = 0.05;
79  offset_solver_.ubeps()(1) = 0.05;
80  offset_solver_.ubeps()(2) = 0.0;
81  }
82 
83  void initialize(double Tend)
84  {
85  T_end_ = Tend;
86  double dt_int = Tend/(K*P);
87  adore::mad::linspace(0.0,Tend,T_,K+1);
88  adore::mad::define_integrator_chain<double,N>(offset_solver_.Ad(),offset_solver_.Bd(),Tend/K);
89  adore::mad::define_integrator_chain<double,N>(offset_solver_.Ad_p(),offset_solver_.Bd_p(),dt_int);
90 
91 
92  {
93  qpOASES::Options options;
94  options.setToMPC();
95  options.printLevel = qpOASES::PL_NONE;
96  offset_solver_.getQProblem()->setOptions(options);
97  offset_solver_.setMaxCPUTime(0.01);//default value
99  }
100  }
101 
105  void prepare_offset_computation(TLongitudinalPlan* longitudinal_plan,double t0_offset,double s0_offset)
106  {
107  double ti,tj,s,ds;
108  s = longitudinal_plan->fi(0.0,0) + s0_offset;
109  ds = longitudinal_plan->fi(0.0,1);
110  offset_solver_.x0()(0) = n0_;
111  offset_solver_.x0()(1) = adore::mad::bound(info_.getLB(1,1,0.0,s,ds),dn0_,info_.getUB(1,1,0.0,s,ds));
112  offset_solver_.x0()(2) = adore::mad::bound(info_.getLB(1,2,0.0,s,ds),ddn0_,info_.getUB(1,2,0.0,s,ds));
113  // std::cout<<"LateralPlanner::prepare_offset_computation():"<<std::endl<<"s: n(lb, ref, ub) n'(lb, ref, ub) n''(lb, ref, ub)"<<std::endl;
114  // std::cout<<"x0: ("<<offset_solver_.x0()(0)<<", "<<offset_solver_.x0()(1)<<", "<<offset_solver_.x0()(2)<<")"<<std::endl;
115  for(int i=0;i<K;i++)
116  {
117  int j=i+1;
118  ti = T_[i]+t0_offset;
119  tj = T_[j]+t0_offset;
120  s = longitudinal_plan->fi(T_[j],0) + s0_offset;
121  ds = longitudinal_plan->fi(T_[j],1);
122 
123  offset_solver_.lbx()(0,i) = info_.getLB(1,0,tj,s,ds);
124  offset_solver_.lbx()(1,i) = info_.getLB(1,1,tj,s,ds);
125  offset_solver_.lbx()(2,i) = info_.getLB(1,2,tj,s,ds);
126  offset_solver_.lbu_hard()(0,i) = info_.getLB(1,3,tj,s,ds);
127 
128  offset_solver_.ubx()(0,i) = info_.getUB(1,0,tj,s,ds);
129  offset_solver_.ubx()(1,i) = info_.getUB(1,1,tj,s,ds);
130  offset_solver_.ubx()(2,i) = info_.getUB(1,2,tj,s,ds);
131  offset_solver_.ubu_hard()(0,i) = info_.getUB(1,3,tj,s,ds);
132 
133  info_.getReferenceIfAvailable(1,0,tj,s,ds,offset_solver_.y()(0,i));
134  info_.getReferenceIfAvailable(1,1,tj,s,ds,offset_solver_.y()(1,i));
135  info_.getReferenceIfAvailable(1,2,tj,s,ds,offset_solver_.y()(2,i));
136  info_.getReferenceIfAvailable(1,3,tj,s,ds,offset_solver_.uset()(0,i));
137  // std::cout<<s<<": ("<<offset_solver_.lbx()(0,i)<<", "<<offset_solver_.y()(0,i)<<", "<<offset_solver_.ubx()(0,i)<<")";
138  // std::cout<<" ("<<offset_solver_.lbx()(1,i)<<", "<<offset_solver_.y()(1,i)<<", "<<offset_solver_.ubx()(1,i)<<")";
139  // std::cout<<" ("<<offset_solver_.lbx()(2,i)<<", "<<offset_solver_.y()(2,i)<<", "<<offset_solver_.ubx()(2,i)<<")"<<std::endl;
140  }
141  }
142  bool update_guard(double& target,double value)
143  {
144  if(target!=value)
145  {
146  target=value;
147  return true;
148  }
149  return false;
150  }
152  {
153  if(aplat_!=nullptr)
154  {
165  {
167  }
168  }
169  }
170  public:
173  adore::params::APVehicle* apvehicle,
175  :roadCoordinates_(lfv,apvehicle,aptrajectory),
176  aplat_(aplat),aptraj_(aptrajectory),apvehicle_(apvehicle)
177  {
179  initialize(10.0);
180  valid_=false;
181  }
182  void setPlanningHorizon(double Tend)
183  {
184  initialize(Tend);
185  }
187  {
188  return info_;
189  }
191  {
192  return offset_solver_;
193  }
195  {
196  return roadCoordinates_;
197  }
198 
202  void compute(const VehicleMotionState9d& initial_state,TLongitudinalPlan* longitudinal_plan,double t0_offset,double s0_offset)
203  {
204  if(!roadCoordinates_.isValid())return;
205 
206  auto rc = roadCoordinates_.toRoadCoordinates(initial_state);
207  n0_ = rc.n0;
208  dn0_ = rc.n1;
209  ddn0_ = rc.n2;
210 
211  valid_ = false;
212 
213  //update constraints and reference
214  info_.update(t0_offset,s0_offset,longitudinal_plan->fi(0,1));
215 
216  /*
217  * step 1 - lateral planning
218  */
220  prepare_offset_computation(longitudinal_plan,t0_offset,s0_offset);
222  offset_solver_.setEndTime(this->T_end_);
223 
225  {
226  /*
227  * step 2 - full state trajectory
228  */
229  //find end of trajectory: first standstill
230  double t_start = longitudinal_plan->limitLo();
231  double t_end = longitudinal_plan->limitHi();
232  double t_end_new = t_start + 0.1;
233  double t_step = 0.01;
234  double v_stop = 0.05;
235  double a_stop = 0.001;
236  while( (longitudinal_plan->f(t_end_new)(1)>v_stop
237  || longitudinal_plan->f(t_end_new)(2)>a_stop)
238  && t_end_new<t_end-t_step )t_end_new+=t_step;
239 
241  aptraj_->getZDIntegrationLength()),t_end_new);
242 
243  auto integration_time = adore::mad::sequence(0.0,
245  t_end_new);//integration time
246 
247  auto trajectory = roadCoordinates_.toVehicleStateTrajectory(longitudinal_plan,
249  integration_time,
250  s0_offset,
251  initial_state.getPSI(),
252  initial_state.getOmega());
253  spr_.setPoints.clear();
254  spr_.append(integration_time,trajectory,aptraj_->getSetPointCount());
255  spr_.setStartTime(t0_offset);
256  valid_ = true;
257  }
258  }
260  {
261  return offset_solver_.result_fun();
262  }
263 
264 
265  double getTend() const
266  {
267  return T_end_;
268  }
269 
273  bool hasValidPlan()const
274  {
275  return valid_;
276  }
281  {
282  return &spr_;
283  }
287  double getCPUTime()const
288  {
289  return 0.0;
290  }
291  };
292  }
293 }
Definition: lateralplanner.h:41
adore::mad::LLinearPiecewiseFunctionM< double, N+R > TLateralPlan
Definition: lateralplanner.h:50
bool update_guard(double &target, double value)
Definition: lateralplanner.h:142
LateralPlanner(adore::view::ALane *lfv, adore::params::APLateralPlanner *aplat, adore::params::APVehicle *apvehicle, adore::params::APTrajectoryGeneration *aptrajectory)
Definition: lateralplanner.h:171
static const int R
Definition: lateralplanner.h:44
adore::params::APVehicle * apvehicle_
Definition: lateralplanner.h:61
SetPointRequest spr_
Definition: lateralplanner.h:62
void init_offset_default_cost()
Definition: lateralplanner.h:65
TOffsetSolver offset_solver_
Definition: lateralplanner.h:54
double T_end_
time steps, incl. 0 at 0
Definition: lateralplanner.h:57
static const int N
Definition: lateralplanner.h:43
RoadCoordinateConverter roadCoordinates_
end time of plan, defines planning horizon as [0,T_end_]
Definition: lateralplanner.h:58
bool hasValidPlan() const
Definition: lateralplanner.h:273
TLateralPlan & getLateralPlan()
Definition: lateralplanner.h:259
double ddn0_
Definition: lateralplanner.h:55
void prepare_offset_computation(TLongitudinalPlan *longitudinal_plan, double t0_offset, double s0_offset)
Definition: lateralplanner.h:105
adore::params::APTrajectoryGeneration * aptraj_
Definition: lateralplanner.h:60
double n0_
Definition: lateralplanner.h:55
adore::mad::LQ_OC_single_shooting< N, R, K, P > TOffsetSolver
Definition: lateralplanner.h:47
NominalPlannerInformationSet< N+1, 2 > TInformationSet
Definition: lateralplanner.h:48
double dn0_
Definition: lateralplanner.h:55
const SetPointRequest * getSetPointRequest() const
Definition: lateralplanner.h:280
adore::params::APLateralPlanner * aplat_
Definition: lateralplanner.h:59
TInformationSet info_
Definition: lateralplanner.h:52
double getTend() const
Definition: lateralplanner.h:265
void compute(const VehicleMotionState9d &initial_state, TLongitudinalPlan *longitudinal_plan, double t0_offset, double s0_offset)
Definition: lateralplanner.h:202
void initialize(double Tend)
Definition: lateralplanner.h:83
TOffsetSolver & getOffsetSolver()
Definition: lateralplanner.h:190
RoadCoordinateConverter & getRoadCoordinateConverter()
Definition: lateralplanner.h:194
double T_[K+1]
Definition: lateralplanner.h:56
TInformationSet & getInformationSet()
Definition: lateralplanner.h:186
void setPlanningHorizon(double Tend)
Definition: lateralplanner.h:182
double getCPUTime() const
Definition: lateralplanner.h:287
void update_offset_parameters()
Definition: lateralplanner.h:151
bool valid_
the result as a set-point request
Definition: lateralplanner.h:63
adore::mad::LLinearPiecewiseFunctionM< double, N+R > TLongitudinalPlan
Definition: lateralplanner.h:49
virtual double getLB(int dim, int der, double t, double s, double ds) const override
Definition: anominalplannerinformation.h:190
virtual void update(double t0, double s0, double ds0) override
Definition: anominalplannerinformation.h:209
virtual double getUB(int dim, int der, double t, double s, double ds) const override
Definition: anominalplannerinformation.h:168
virtual bool getReferenceIfAvailable(int dim, int der, double t, double s, double ds, double &ref) const override
Definition: anominalplannerinformation.h:147
Definition: roadcoordinates.h:46
adoreMatrix< double, 0, 0 > toVehicleStateTrajectory(adore::mad::AScalarToN< double, 4 > *lon_trajectory_rc, adore::mad::AScalarToN< double, 4 > *lat_trajectory_rc, const adoreMatrix< double, 1, 0 > &integration_time, double s0, double psi0, double omega0)
Definition: roadcoordinates.h:263
RoadCoordinates toRoadCoordinates(const PlanarVehicleState10d &x, bool log=false)
Definition: roadcoordinates.h:156
bool isValid()
Definition: roadcoordinates.h:128
Definition: setpointrequest.h:35
void setStartTime(double new_t0)
Definition: setpointrequest.h:86
void append(const adoreMatrix< double, 1, 0 > &T, const adoreMatrix< double, 0, 0 > &X, int N, int maneuverID=0)
Definition: setpointrequest.h:63
std::vector< SetPoint > setPoints
Definition: setpointrequest.h:38
virtual CT f(DT x) const override
Definition: llinearpiecewisefunction.h:251
virtual T fi(DT x, int row) const override
Definition: llinearpiecewisefunction.h:391
virtual DT limitLo() const override
Definition: llinearpiecewisefunction.h:264
virtual DT limitHi() const override
Definition: llinearpiecewisefunction.h:259
Definition: lq_oc_single_shooting.h:61
bool isSolved() const
Definition: lq_oc_single_shooting.h:635
void setMaxCPUTime(real_t value)
Definition: lq_oc_single_shooting.h:729
t_wx & wx()
Definition: lq_oc_single_shooting.h:706
t_Bd & Bd_p()
Definition: lq_oc_single_shooting.h:703
t_Ad & Ad()
Definition: lq_oc_single_shooting.h:700
qpOASES::QProblem * getQProblem()
Definition: lq_oc_single_shooting.h:728
t_lbx & lbx()
Definition: lq_oc_single_shooting.h:713
t_y & y()
Definition: lq_oc_single_shooting.h:720
void setSystemChanged(bool value)
Definition: lq_oc_single_shooting.h:680
t_ubu_hard & ubu_hard()
Definition: lq_oc_single_shooting.h:716
t_uset & uset()
Definition: lq_oc_single_shooting.h:721
t_Bd & Bd()
Definition: lq_oc_single_shooting.h:701
t_lbu_hard & lbu_hard()
Definition: lq_oc_single_shooting.h:715
void compute()
Definition: lq_oc_single_shooting.h:606
t_ubx & ubx()
Definition: lq_oc_single_shooting.h:714
t_wx_end & wx_end()
Definition: lq_oc_single_shooting.h:708
t_geps & geps()
Definition: lq_oc_single_shooting.h:711
t_Ad & Ad_p()
Definition: lq_oc_single_shooting.h:702
t_ubeps & ubeps()
Definition: lq_oc_single_shooting.h:717
t_resultfun & result_fun()
Definition: lq_oc_single_shooting.h:704
t_x0 & x0()
Definition: lq_oc_single_shooting.h:719
void setEndTime(double Tend)
Definition: lq_oc_single_shooting.h:684
t_wu & wu()
Definition: lq_oc_single_shooting.h:707
bool isFeasible() const
Definition: lq_oc_single_shooting.h:628
abstract class containing parameters related to configuring the lateral planner
Definition: ap_lateral_planner.h:26
virtual double getWeightEndAcc() const =0
getWeightEndAcc returns cost function weight for quadratic acceleration term at end point
virtual double getSlackAcc() const =0
getSlackAcc returns maximum slack of soft-constraints for acceleration
virtual double getSlackVel() const =0
getSlackVel returns maximum slack of soft-constraints for velocity
virtual double getSlackPos() const =0
getSlackPos returns maximum slack of soft-constraints for position
virtual double getWeightAcc() const =0
getWeightAcc returns cost function weight for quadratic acceleration term
virtual double getWeightVel() const =0
getWeightVel returns cost function weight for quadratic velocity error term
virtual double getWeightEndVel() const =0
getWeightEndVel returns cost function weight for quadratic velocity error term at end point
virtual double getWeightPos() const =0
getWeightPos returns cost function weight for quadratic position error term
virtual double getWeightEndPos() const =0
getWeightEndPos returns cost function weight for quadratic position error term at end point
virtual double getWeightJerk() const =0
getWeightJerk returns cost function weight for quadratic jerk term
abstract class containing parameters to configure the behaviour of trajectory generation
Definition: ap_trajectory_generation.h:26
virtual double getZDIntegrationStep() const =0
zero dynamics step size
virtual int getSetPointCount() const =0
number of set points in set-point request
virtual double getZDIntegrationLength() const =0
zero dynamics integration length
abstract class for vehicle configuration related paremeters
Definition: ap_vehicle.h:29
Definition: alane.h:28
adoreMatrix< T, 1, 0 > sequence(T x0, T dx, T xend)
Definition: adoremath.h:51
adoreMatrix< T, 1, n > linspace(T x0, T x1)
Definition: adoremath.h:91
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
Definition: areaofeffectconverter.h:20
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39
double getOmega() const
Get the yaw rate.
Definition: vehiclemotionstate9d.h:90
double getPSI() const
Get the heading.
Definition: vehiclemotionstate9d.h:72