ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
plot_planning_details.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2023 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  * Matthias Nichting
13  *
14  ********************************************************************************/
15 
16 #pragma once
18 #include <adore/fun/afactory.h>
19 #include <adore/mad/adoremath.h>
20 
21 namespace adore
22 {
23  namespace apps
24  {
30  {
31  private:
38  std::string filter_;
45 
46  public:
47  PlanningDetailsPlotter(std::string filter = "")
48  : plot_longitudinal_(true)
49  , plot_lateral_(true)
54  , filter_(filter)
55  {
58  }
60  {
61  delete planning_result_feed_;
63  }
65  {
68  figure_lon1_->setTitle("Longitudinal Plan - s");
69  figure_lon1_->setXLabel("t (s)");
70  figure_lon1_->setYLabel("s (m)");
73  figure_lon1_->show();
75  figure_lon2_->setTitle("Longitudinal Plan - ds(b),dds(g),ddds(r)");
76  figure_lon2_->setXLabel("t (s)");
77  figure_lon2_->setYLabel("ds (m/s)");
80  figure_lon2_->show();
82  figure_lat1_->setTitle("Lateral Plan - n");
83  figure_lat1_->setXLabel("t (s)");
84  figure_lat1_->setYLabel("n (m)");
85  figure_lat1_->show();
89  figure_lat2_->setTitle("Lateral Plan - dn(b),ddn(r),dddn(g)");
90  figure_lat2_->setXLabel("t (s)");
91  figure_lat2_->setYLabel("dn (m/s)");
92  figure_lat2_->show();
95  }
97  {
98  delete fig_factory_;
99  delete figure_lon1_;
100  delete figure_lon2_;
101  delete figure_lat1_;
102  delete figure_lat2_;
103  }
105  {
106  if(!planning_result.nominal_maneuver_valid)return;
107  auto& longitudinal_plan = planning_result.nominal_maneuver_longitudinal_plan.getData();
108  const int N = longitudinal_plan.nc();
109  double XN[N];
110  double YN[N];
111  const std::string& name= planning_result.name;
112  adore::mad::copyRowToArray(longitudinal_plan, XN, 0); // t
113  adore::mad::copyRowToArray(longitudinal_plan, YN, 1); // s
114  figure_lon1_->plot(name+"/s", XN, YN, N, "LineColor=0,0,1");
115  adore::mad::copyRowToArray(longitudinal_plan, YN, 2); // ds
116  figure_lon2_->plot(name+"/ds", XN, YN, N, "LineColor=0,0,1");
117  adore::mad::copyRowToArray(longitudinal_plan, YN, 3); // dds
118  figure_lon2_->plot(name+"/dds", XN, YN, N, "LineColor=1,0,0");
119  adore::mad::copyRowToArray(longitudinal_plan, YN, 4); // ddds
120  figure_lon2_->plot(name+"/ddds", XN, YN, N, "LineColor=0,0.5,0");
121 
122  auto& longitudinal_lbx = planning_result.nominal_maneuver_longitudinal_lbx.getData();
123  auto& longitudinal_ubx = planning_result.nominal_maneuver_longitudinal_ubx.getData();
124  const int n_lon_b = longitudinal_lbx.nc();
125  if (n_lon_b > 0)
126  {
127  const int nr_lon_b = longitudinal_lbx.nr();
128  double X_lon_b[n_lon_b];
129  double Y_lon_b[n_lon_b];
130  if (nr_lon_b > 1)
131  {
132  adore::mad::copyRowToArray(longitudinal_lbx, X_lon_b, 0); // t
133  adore::mad::copyRowToArray(longitudinal_lbx, Y_lon_b, 1); // s
134  for (int i = 0; i < n_lon_b; ++i)
135  {
136  if (Y_lon_b[i] < s_lower_bound_clipped_)
137  Y_lon_b[i] = s_lower_bound_clipped_;
138  }
139  figure_lon1_->plot(name+"/slb", X_lon_b, Y_lon_b, n_lon_b, "LineColor=1,0,0");
140  adore::mad::copyRowToArray(longitudinal_ubx, Y_lon_b, 1); // s
141  for (int i = 0; i < n_lon_b; ++i)
142  {
143  if (Y_lon_b[i] > s_upper_bound_clipped_)
144  Y_lon_b[i] = s_upper_bound_clipped_;
145  }
146  figure_lon1_->plot(name+"/sub", X_lon_b, Y_lon_b, n_lon_b, "LineColor=1,0,0");
147  }
148  if (nr_lon_b > 2)
149  {
150  adore::mad::copyRowToArray(longitudinal_lbx, Y_lon_b, 2); // ds
151  figure_lon2_->plot(name+"/dslb", X_lon_b, Y_lon_b, n_lon_b, "LineColor=1,0,0");
152  adore::mad::copyRowToArray(longitudinal_ubx, Y_lon_b, 2); // ds
153  figure_lon2_->plot(name+"/dsub", X_lon_b, Y_lon_b, n_lon_b, "LineColor=1,0,0");
154  }
155  }
156  }
158  {
159  if(!planning_result.nominal_maneuver_valid)return;
160  auto& lateral_plan = planning_result.nominal_maneuver_lateral_plan.getData();
161  const int N = lateral_plan.nc();
162  double XN[N];
163  double YN[N];
164  const std::string& name= planning_result.name;
165  adore::mad::copyRowToArray(lateral_plan, XN, 0); // t
166  adore::mad::copyRowToArray(lateral_plan, YN, 1); // s
167  figure_lat1_->plot(name+"/n", XN, YN, N, "LineColor=0,0,1");
168 
169  auto& lateral_lbx = planning_result.nominal_maneuver_lateral_lbx.getData();
170  auto& lateral_ubx = planning_result.nominal_maneuver_lateral_ubx.getData();
171  const int n_lat_b = lateral_lbx.nc();
172  if (n_lat_b > 0)
173  {
174  const int nr_lat_b = lateral_lbx.nr();
175  double X_lat_b[n_lat_b];
176  double Y_lat_b[n_lat_b];
177  if (nr_lat_b > 1)
178  {
179  adore::mad::copyRowToArray(lateral_lbx, X_lat_b, 0); // t
180  adore::mad::copyRowToArray(lateral_lbx, Y_lat_b, 1); // s
181  for (int i = 0; i < n_lat_b; ++i)
182  {
183  if (Y_lat_b[i] < n_lower_bound_clipped_)
184  Y_lat_b[i] = n_lower_bound_clipped_;
185  }
186  figure_lat1_->plot(name+"/nlb", X_lat_b, Y_lat_b, n_lat_b, "LineColor=1,0,0");
187  adore::mad::copyRowToArray(lateral_ubx, Y_lat_b, 1); // n
188  for (int i = 0; i < n_lat_b; ++i)
189  {
190  if (Y_lat_b[i] > n_upper_bound_clipped_)
191  Y_lat_b[i] = n_upper_bound_clipped_;
192  }
193 
194  figure_lat1_->plot(name+"/nub", X_lat_b, Y_lat_b, n_lat_b, "LineColor=1,0,0");
195  }
196  }
197  }
198  void run()
199  {
200  while (planning_result_feed_->hasNext())
201  {
202  fun::PlanningResult latest_planning_result;
203  planning_result_feed_->getNext(latest_planning_result);
204  if(!filter_.empty() && filter_.find(latest_planning_result.name) == std::string::npos)
205  {
206  continue;
207  }
208  if (latest_planning_result.nominal_maneuver_valid && plot_longitudinal_)
209  {
210  plot_longitudinal_planning_information(latest_planning_result);
211  }
212  if (latest_planning_result.nominal_maneuver_valid && plot_lateral_)
213  {
214  plot_lateral_planning_information(latest_planning_result);
215  }
216  }
217  }
218  };
219  } // namespace apps
220 } // namespace adore
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: plot_planning_details.h:30
bool plot_longitudinal_
Definition: plot_planning_details.h:32
void run()
Definition: plot_planning_details.h:198
adore::mad::AFeed< adore::fun::PlanningResult > * planning_result_feed_
Definition: plot_planning_details.h:44
~PlanningDetailsPlotter()
Definition: plot_planning_details.h:59
double n_upper_bound_clipped_
Definition: plot_planning_details.h:36
PlanningDetailsPlotter(std::string filter="")
Definition: plot_planning_details.h:47
DLR_TS::PlotLab::AFigureStub * figure_lon1_
Definition: plot_planning_details.h:40
double s_lower_bound_clipped_
Definition: plot_planning_details.h:35
DLR_TS::PlotLab::AFigureStub * figure_lon2_
Definition: plot_planning_details.h:41
DLR_TS::PlotLab::FigureStubFactory * fig_factory_
Definition: plot_planning_details.h:39
double n_lower_bound_clipped_
Definition: plot_planning_details.h:37
void initialize_plot()
Definition: plot_planning_details.h:64
void plot_lateral_planning_information(fun::PlanningResult &planning_result)
Definition: plot_planning_details.h:157
DLR_TS::PlotLab::AFigureStub * figure_lat1_
Definition: plot_planning_details.h:42
double s_upper_bound_clipped_
Definition: plot_planning_details.h:34
bool plot_lateral_
Definition: plot_planning_details.h:33
void plot_longitudinal_planning_information(fun::PlanningResult &planning_result)
Definition: plot_planning_details.h:104
DLR_TS::PlotLab::AFigureStub * figure_lat2_
Definition: plot_planning_details.h:43
std::string filter_
Definition: plot_planning_details.h:38
void terminate_plot()
Definition: plot_planning_details.h:96
static adore::fun::AFactory * get()
Definition: afactory.h:170
virtual void getNext(T &value)=0
virtual bool hasNext() const =0
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
void copyRowToArray(const adoreMatrix< T, nr, nc > &m, T *target, int col)
Definition: adoremath.h:154
Definition: areaofeffectconverter.h:20
Definition: planning_result.h:29
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_lateral_lbx
Definition: planning_result.h:56
adore::mad::LLinearPiecewiseFunctionM< double, 4 > nominal_maneuver_longitudinal_plan
Definition: planning_result.h:43
std::string name
Definition: planning_result.h:32
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
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_lateral_ubx
Definition: planning_result.h:59
bool nominal_maneuver_valid
Definition: planning_result.h:63
adore::mad::LLinearPiecewiseFunctionM< double, 3 > nominal_maneuver_longitudinal_ubx
Definition: planning_result.h:50