ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
test_mrm_planner.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
13  ********************************************************************************/
14 
15 #pragma once
16 
17 #include <adore/fun/afactory.h>
20 #include <adore/env/afactory.h>
21 #include <adore/params/afactory.h>
26 
27 namespace adore
28 {
29  namespace apps
30  {
36  {
37  private:
52 
68  public:
70  adore::fun::AFactory* funFactory,
71  adore::params::AFactory* PARAMS_Factory)
72  :envFactory_(envFactory),funFactory_(funFactory),paramsFactory_(PARAMS_Factory),
73  roadmap_(envFactory,paramsFactory_),trafficMap_(roadmap_.getBorderSet(),envFactory),
75  {
77  pTacticalPlanner_ = PARAMS_Factory->getTacticalPlanner();
78  plat_ = PARAMS_Factory->getLateralPlanner();
79  planner_ = new TPlanner(&lfv_,
80  PARAMS_Factory->getLateralPlanner(),
81  pvehicle_,
82  PARAMS_Factory->getTrajectoryGeneration());
91  PARAMS_Factory->getTrajectoryGeneration());
92 
93  planner_->getOffsetSolver().getInformationSet().add(followCenterlineReference_);
94  planner_->getOffsetSolver().getInformationSet().add(lateralAccelerationReference_);;
95  planner_->getOffsetSolver().getInformationSet().add(lateralJerkReference_);
96  planner_->getOffsetSolver().getInformationSet().add(lateralOffsetConstraintLFUB_);
97  planner_->getOffsetSolver().getInformationSet().add(lateralOffsetConstraintLFLB_);
98  planner_->getOffsetSolver().getInformationSet().add(headingConstraintUB_);
99  planner_->getOffsetSolver().getInformationSet().add(headingConstraintLB_);
100 
102  xreader_ = funFactory->getVehicleMotionStateReader();
103  wwriter_ = funFactory->getSetPointRequestWriter();
104  init_plot();
105 
106  }
108  {
109  delete planner_;
112  delete lateralJerkReference_;
115  delete headingConstraintUB_;
116  delete headingConstraintLB_;
117  delete pvehicle_;
118  delete pvehicle_;
119  delete pTacticalPlanner_;
120  delete plat_;
121  }
126  void run()
127  {
128  roadmap_.update();
130  lfv_.update();
131  xreader_->getData(x_);
132  auto x_replan = x_;
133  bool reset = true;
134  if(planner_->hasValidPlan())
135  {
136  auto spr = planner_->getSetPointRequest();
137  double t = x_.getTime();
138  if( spr->isActive(t) )
139  {
140  auto x_ref = spr->interpolateReference(t,pvehicle_);
141  double dx = x_.getX()-x_ref.getX();
142  double dy = x_.getY()-x_ref.getY();
143  if(dx*dx+dy*dy<pTacticalPlanner_->getResetRadius())
144  {
145  x_replan.setX(x_ref.getX());
146  x_replan.setY(x_ref.getY());
147  x_replan.setPSI(x_ref.getPSI());
148  x_replan.setvx(x_ref.getvx());
149  x_replan.setvy(x_ref.getvy());
150  x_replan.setOmega(x_ref.getOmega());
151  x_replan.setAx(x_ref.getAx());
152  x_replan.setDelta(x_ref.getDelta());
153  reset = false;
154  }
155  }
156  }
157  if(reset)std::cout<<"TestTrajectoryPlanner: Reset initial state.\n";
158  planner_->compute(x_replan);
159  if(planner_->hasValidPlan())
160  {
162  plot();
163  }
164  }
165  void plot()
166  {
167  static const int N = 20*5+1;
168  double XN[N];
169  double YN[N];
170  auto& longitudinal_plan = planner_->getLongitudinalPlan().getData();
171  auto& lateral_plan = planner_->getLateralPlan().getData();
172  adore::mad::copyRowToArray(longitudinal_plan,XN,0);//t
173  adore::mad::copyRowToArray(longitudinal_plan,YN,1);//s
174  figure_lon1->plot("s",XN,YN,N,"LineColor=0,0,1");
175  adore::mad::copyRowToArray(longitudinal_plan,YN,2);//ds
176  figure_lon2->plot("ds",XN,YN,N,"LineColor=0,0,1");
177  adore::mad::copyRowToArray(longitudinal_plan,YN,3);//dds
178  figure_lon2->plot("dds",XN,YN,N,"LineColor=1,0,0");
179  adore::mad::copyRowToArray(longitudinal_plan,YN,4);//ddds
180  figure_lon2->plot("ddds",XN,YN,N,"LineColor=0,0.5,0");
181  //@todo: plot lateral result, if required
182  }
183  void init_plot()
184  {
187  figure_lon1->setTitle("Longitudinal Plan - s");
188  figure_lon1->setXLabel("t (s)");
189  figure_lon1->setYLabel("s (m)");
192  figure_lon1->show();
194  figure_lon2->setTitle("Longitudinal Plan - ds(b),dds(g),ddds(r)");
195  figure_lon2->setXLabel("t (s)");
196  figure_lon2->setYLabel("ds (m/s)");
199  figure_lon2->show();
200  //@TODO: uncomment if plotting of lateral result is required
201  // figure_lat1 = fig_factory->createFigureStub(5);
202  // figure_lat1->setTitle("Lateral Plan - n");
203  // figure_lat1->setXLabel("t (s)");
204  // figure_lat1->setYLabel("n (m)");
205  // figure_lat1->show();
206  // figure_lat1->showAxis();
207  // figure_lat1->showGrid();
208  // figure_lat2 = fig_factory->createFigureStub(6);
209  // figure_lat2->setTitle("Lateral Plan - dn(b),ddn(r),dddn(g)");
210  // figure_lat2->setXLabel("t (s)");
211  // figure_lat2->setYLabel("dn (m/s)");
212  // figure_lat2->show();
213  // figure_lat2->showAxis();
214  // figure_lat2->showGrid();
215  }
216  };
217  }
218 }
Definition: afigurestub.h:24
virtual void setXLabel(std::string value)=0
virtual void setTitle(std::string value)=0
virtual void setYLabel(std::string value)=0
virtual void plot(std::string hashtag, double *X, double *Y, double *Z, int size, std::string options)=0
Definition: figurestubfactory.h:25
AFigureStub * createFigureStub(int windowID)
Definition: figurestubfactory.h:45
test bench implementation for minimum risk maneuver planner
Definition: test_mrm_planner.h:36
void plot()
Definition: test_mrm_planner.h:165
adore::fun::VehicleMotionState9d x_
Definition: test_mrm_planner.h:50
adore::fun::LateralOffsetConstraintLF * lateralOffsetConstraintLFUB_
Definition: test_mrm_planner.h:56
adore::mad::AReader< adore::fun::VehicleMotionState9d > * xreader_
Definition: test_mrm_planner.h:48
adore::params::APTacticalPlanner * pTacticalPlanner_
Definition: test_mrm_planner.h:43
adore::fun::LateralJerkReference * lateralJerkReference_
Definition: test_mrm_planner.h:55
adore::env::BorderBased::LaneFollowingView lfv_
Definition: test_mrm_planner.h:47
adore::mad::AWriter< adore::fun::SetPointRequest > * wwriter_
Definition: test_mrm_planner.h:49
adore::env::traffic::TrafficMap trafficMap_
Definition: test_mrm_planner.h:46
DLR_TS::PlotLab::AFigureStub * figure_lat2
Definition: test_mrm_planner.h:67
adore::env::BorderBased::LocalRoadMap roadmap_
Definition: test_mrm_planner.h:45
TestMRMPlanner(adore::env::AFactory *envFactory, adore::fun::AFactory *funFactory, adore::params::AFactory *PARAMS_Factory)
Definition: test_mrm_planner.h:69
adore::params::APLateralPlanner * plat_
Definition: test_mrm_planner.h:44
adore::fun::AFactory * funFactory_
Definition: test_mrm_planner.h:40
adore::fun::FollowPrecedingVehicle * followVehicleConstraint_
Definition: test_mrm_planner.h:61
DLR_TS::PlotLab::AFigureStub * figure_lon1
Definition: test_mrm_planner.h:64
adore::fun::MRMPlanner< 20, 5 > TPlanner
Definition: test_mrm_planner.h:38
void run()
update function of the trajectory planner
Definition: test_mrm_planner.h:126
void init_plot()
Definition: test_mrm_planner.h:183
~TestMRMPlanner()
Definition: test_mrm_planner.h:107
adore::fun::LateralOffsetConstraintLF * lateralOffsetConstraintLFLB_
Definition: test_mrm_planner.h:57
TPlanner * planner_
Definition: test_mrm_planner.h:51
adore::env::AFactory * envFactory_
Definition: test_mrm_planner.h:39
DLR_TS::PlotLab::AFigureStub * figure_lon2
Definition: test_mrm_planner.h:65
adore::fun::HeadingConstraint * headingConstraintUB_
Definition: test_mrm_planner.h:58
adore::fun::HeadingConstraint * headingConstraintLB_
Definition: test_mrm_planner.h:59
adore::params::APVehicle * pvehicle_
Definition: test_mrm_planner.h:42
DLR_TS::PlotLab::AFigureStub * figure_lat1
Definition: test_mrm_planner.h:66
DLR_TS::PlotLab::FigureStubFactory * fig_factory
Definition: test_mrm_planner.h:63
adore::fun::FollowCenterlineReference * followCenterlineReference_
Definition: test_mrm_planner.h:53
adore::fun::LateralAccelerationReference * lateralAccelerationReference_
Definition: test_mrm_planner.h:54
adore::params::AFactory * paramsFactory_
Definition: test_mrm_planner.h:41
abstract factory for adore::env communication
Definition: afactory.h:41
virtual TVehicleMotionStateReader * getVehicleMotionStateReader()=0
LaneFollowingview provides traffic related information for the current lane.
Definition: lanefollowingview.h:42
void update()
update the LaneFollowingView
Definition: lanefollowingview.h:87
Definition: localroadmap.h:38
void update(bool matched_lane_proposal_valid=false, BorderID matched_lane_proposal_id=BorderID())
update the local road map
Definition: localroadmap.h:256
Definition: trafficmap.h:36
void update()
Update the TrafficMap.
Definition: trafficmap.h:126
@ LB
Definition: anominalplanner.h:56
@ UB
Definition: anominalplanner.h:56
Definition: basicconstraintsandreferences.h:650
Definition: basicconstraintsandreferences.h:858
Definition: basicconstraintsandreferences.h:409
Definition: basicconstraintsandreferences.h:547
Definition: basicconstraintsandreferences.h:575
Definition: basicconstraintsandreferences.h:700
Definition: mrmplanner.h:32
virtual const SetPointRequest * getSetPointRequest() const
Definition: mrmplanner.h:273
TPostProcessConstraints::TInformationSet & getInformationSet()
Definition: mrmplanner.h:78
virtual void compute(const VehicleMotionState9d &initial_state)
Definition: mrmplanner.h:175
LateralPlanner< K, P > & getOffsetSolver()
Definition: mrmplanner.h:259
TPartialPlan & getLateralPlan()
Definition: mrmplanner.h:252
virtual bool hasValidPlan() const
Definition: mrmplanner.h:266
TPartialPlan & getLongitudinalPlan()
Definition: mrmplanner.h:248
void add(ANominalReference *r)
Definition: anominalplannerinformation.h:68
virtual void getData(T &value)=0
virtual void write(const T &value)=0
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
abstract factory for adore::params classes
Definition: afactory.h:54
virtual APLateralPlanner * getLateralPlanner() const =0
virtual APTacticalPlanner * getTacticalPlanner() const =0
virtual APTrajectoryGeneration * getTrajectoryGeneration() const =0
virtual APVehicle * getVehicle() const =0
abstract class containing parameters related to configuring the lateral planner
Definition: ap_lateral_planner.h:26
abstract classs containing parameters to configure aspects and constraints of the tactical planner
Definition: ap_tactical_planner.h:25
abstract class for vehicle configuration related paremeters
Definition: ap_vehicle.h:29
void copyRowToArray(const adoreMatrix< T, nr, nc > &m, T *target, int col)
Definition: adoremath.h:154
Definition: areaofeffectconverter.h:20
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 getY() const
Get the y-coordinate.
Definition: vehiclemotionstate9d.h:60
double getTime() const
Get the time.
Definition: vehiclemotionstate9d.h:48