ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
feedbackcontroller.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2022 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ß
13  * Jan Lauermann
14  ********************************************************************************/
15 #pragma once
16 
17 #include <adore/mad/aodesolver.h>
20 #include <adore/fun/afactory.h>
21 #include <adore/params/afactory.h>
22 #include <list>
23 
24 namespace adore
25 {
26  namespace apps
27  {
29  {
30  private:
40  double last_t_;
41  double last_ddelta_;
43  double dt_;
44  std::list<double> dt_list_;
46  protected:
51 
52 
53  public:
55  :linear_tracking_controller_(adore::params::ParamsFactoryInstance::get()->getVehicle(),
56  adore::params::ParamsFactoryInstance::get()->getTrajectoryTracking())
57  {
61  spr_reader_ = adore::fun::FunFactoryInstance::get()->getOdomSetPointRequestReader();
62  state_reader_ = adore::fun::FunFactoryInstance::get()->getVehicleOdometryMotionStateReader();
63  x_state_reader_ = adore::fun::FunFactoryInstance::get()->getVehicleExtendedStateReader();
64  cmd_writer_ = adore::fun::FunFactoryInstance::get()->getMotionCommandWriter();
66  last_t_ = -1.0;
67  last_ddelta_ = 0.0;
69  dt_ = 0.0;
70  dt_list_max_size_ = 100;
71  }
73  {
74  delete spr_reader_;
75  delete state_reader_;
76  delete x_state_reader_;
77  delete cmd_writer_;
78  }
79  void run()
80  {
81  if( state_reader_==nullptr || !state_reader_->hasData() )return;
83  const double t = state_.getTime();
84  if(t!=last_t_)
85  {
86  double dt_now = t-last_t_;
87  dt_list_.push_front(dt_now);
88  while(dt_list_.size()>dt_list_max_size_)dt_list_.pop_back();
89  dt_ = 0.0;
90  for(auto value:dt_list_)dt_+=value;
91  dt_ = dt_ / (double)(dt_list_.size());
92  last_t_ = t;
93  std::cout<<"dt="<<dt_<<std::endl;
94  }
95  else
96  {
97  return;
98  }
99 
101  {
103  }
104  const double t_activation_delay = 0.5;
105  const double t_active = std::max(0.0,last_t_-last_t_manual_control_-t_activation_delay);
106  const bool automatic_control = t_active>0.0;
107  std::cout<<t_active<<", ";
108 
109  if( spr_reader_!=0 && spr_reader_->hasData() )
110  {
111 
113  spr_reader_->getData(spr_tmp);
114  if(spr_tmp.isActive(t))spr_ = spr_tmp;
115 
117  if(spr_.isActive(t))
118  {
119  //trajectory tracking operation
120  auto ref_state = spr_.interpolateReference(t,ap_vehicle_);
121  switch(x_state_.getGearState())
122  {
124  {
126  if(!automatic_control)
127  {
129  }
130  else
131  {
133  }
135  }
136  break;
138  {
139  //@TODO: implement a behavior for reversing
140  }
141  break;
142  default:
143  {
144  //@TODO: implement a behavior for unknown gear
146  if(!automatic_control)
147  {
149  }
150  else
151  {
153  }
155  }
156  break;
157  }
158  }
159  else
160  {
161  //uncontrolled emergency break
163  cmd_.setSteeringAngle(0.0);
164  if(spr_.setPoints.size()==0)
165  {
166  std::cout<<" No SetPointRequest available!\n";
167  }
168  else
169  {
170  std::cout<<"SetPointRequest timeout t="<<t<<" tSPR=["<<spr_.setPoints.front().tStart<<";"<<spr_.setPoints.back().tEnd<<"]\n";
171  }
172  }
173  }
174 
175  //apply steering ratio
177 
178  //fullstop mechanism
179  //(prevent vehicle from restarting due to minor localization drift)
181  {
182  cmd_.setAcceleration(-1.0);
183  cmd_.setSteeringAngle(0.0);
184  }
185 
186  //steering rate limiter
187  const double ddelta_max_default = ap_tracking_->getDDeltaMax() * 100.0 * dt_; // @TODO: ddeltamax should be given as *steering* (not steering-wheel) change per *second* (not per iteration)
188  const double v_full_ddelta = 5;//@TODO create parameter
189  const double ddelta_min_rel = 0.001;//@TODO create parameter
190  const double ddelta_max_v = ddelta_max_default * adore::mad::bound(ddelta_min_rel,state_.getvx()/v_full_ddelta,1.0);
191  const double t_full_ddelta = 10;//@TODO create parameter
192  const double ddelta_max_transition = ddelta_max_default * adore::mad::bound(ddelta_min_rel,t_active/t_full_ddelta,1.0);
193  const double ddelta_max = std::min(ddelta_max_v,ddelta_max_transition);
194  const double delta_max = last_steering_angle_ + ddelta_max;
195  const double delta_min = last_steering_angle_ - ddelta_max;
196  std::cout<<dt_<<", "<<ddelta_max_default<<", "<<ddelta_max<<", "<<ddelta_max_transition<<", "<<ddelta_max_v<<std::endl;
198 
199  //deactivate output, if manual control
200  if(!automatic_control)//automation system is not accelerating
201  {
202  cmd_.setAcceleration(0.0);
203  cmd_.setSteeringAngle(state_.getDelta() * ap_vehicle_->get_steeringRatio());//set to current steering wheel angle
204  }
205 
206 
207  //track the last steering angle for rate limitation
209 
210  //output control command
212 
213  }
214 
215  };
216  }
217 }
bool automatic_control
Definition: adore_vehiclemodel_node.cpp:75
Definition: feedbackcontroller.h:29
double last_t_
Definition: feedbackcontroller.h:40
std::list< double > dt_list_
Definition: feedbackcontroller.h:44
adore::fun::VehicleMotionState9d state_
Definition: feedbackcontroller.h:49
int dt_list_max_size_
Definition: feedbackcontroller.h:45
virtual ~FeedbackController()
Definition: feedbackcontroller.h:72
adore::fun::VehicleExtendedState x_state_
Definition: feedbackcontroller.h:34
adore::fun::SetPointRequest spr_
Definition: feedbackcontroller.h:33
void run()
Definition: feedbackcontroller.h:79
adore::fun::MotionCommand cmd_
Definition: feedbackcontroller.h:35
adore::mad::AReader< adore::fun::VehicleExtendedState > * x_state_reader_
Definition: feedbackcontroller.h:32
FeedbackController()
Definition: feedbackcontroller.h:54
adore::params::APVehicle * ap_vehicle_
Definition: feedbackcontroller.h:36
double last_t_manual_control_
Definition: feedbackcontroller.h:42
adore::mad::AReader< adore::fun::VehicleMotionState9d > * state_reader_
Definition: feedbackcontroller.h:48
double dt_
Definition: feedbackcontroller.h:43
double last_ddelta_
Definition: feedbackcontroller.h:41
double last_steering_angle_
Definition: feedbackcontroller.h:39
adore::mad::AWriter< adore::fun::MotionCommand > * cmd_writer_
Definition: feedbackcontroller.h:50
adore::params::APEmergencyOperation * ap_emergency_
Definition: feedbackcontroller.h:38
adore::params::APTrajectoryTracking * ap_tracking_
Definition: feedbackcontroller.h:37
adore::mad::AReader< adore::fun::SetPointRequest > * spr_reader_
Definition: feedbackcontroller.h:47
adore::fun::LinearTrackingController linear_tracking_controller_
Definition: feedbackcontroller.h:31
static adore::fun::AFactory * get()
Definition: afactory.h:170
Definition: linear_tracking_controller.h:39
void compute_control_input(const VehicleMotionState9d &x, const PlanarVehicleState10d &xref, MotionCommand &u)
Definition: linear_tracking_controller.h:78
void setUseIntegrator(bool value)
Definition: linear_tracking_controller.h:68
void resetIntegrator(bool value)
Definition: linear_tracking_controller.h:70
Definition: motioncommand.h:26
void setAcceleration(double acceleration)
Definition: motioncommand.h:51
double getSteeringAngle() const
Definition: motioncommand.h:37
double getAcceleration() const
Definition: motioncommand.h:47
void setSteeringAngle(double steeringAngle)
Definition: motioncommand.h:41
Definition: setpointrequest.h:35
PlanarVehicleState10d interpolateReference(double t, adore::params::APVehicle *p) const
Definition: setpointrequest.h:112
bool isActive(double t) const
Definition: setpointrequest.h:332
std::vector< SetPoint > setPoints
Definition: setpointrequest.h:38
Definition: vehicleextendedstate.h:26
@ Drive
Definition: vehicleextendedstate.h:30
@ Reverse
Definition: vehicleextendedstate.h:30
bool getAutomaticControlOn() const
Definition: vehicleextendedstate.h:98
GearState getGearState() const
Definition: vehicleextendedstate.h:51
virtual void getData(T &value)=0
virtual bool hasData() const =0
virtual void write(const T &value)=0
virtual APTrajectoryTracking * getTrajectoryTracking() const =0
virtual APVehicle * getVehicle() const =0
virtual APEmergencyOperation * getEmergencyOperation() const =0
abstract class containing parameters concerning emergency operation behaviour
Definition: ap_emergency_operation.h:25
virtual double getamin() const =0
abstract class containing parameters to configure the behaviour of the trajactory tracking controller
Definition: ap_trajectory_tracking.h:26
virtual double getDDeltaMax() const =0
steering angle: maximum absolute control input change per control update. Maximum steering rate then ...
abstract class for vehicle configuration related paremeters
Definition: ap_vehicle.h:29
virtual double get_steeringRatio() const =0
static adore::params::AFactory * get()
Definition: afactory.h:103
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
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
Definition: areaofeffectconverter.h:20
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39
double getvx() const
Get the longitudinal velocity.
Definition: vehiclemotionstate9d.h:78
double getDelta() const
Get the steering angle.
Definition: vehiclemotionstate9d.h:102
double getTime() const
Get the time.
Definition: vehiclemotionstate9d.h:48