ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
vehiclemodel.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 #include <adore/sim/afactory.h>
17 #include <adore/fun/afactory.h>
18 #include <adore/params/afactory.h>
20 #include <adore/mad/oderk4.h>
21 #include <adore/mad/adoremath.h>
22 #include <iostream>
23 
24 namespace adore
25 {
30  namespace apps
31  {
42  class VehicleModel//@TODO: public AFixedRateApp - derive from process template which controls execution-timing during non-realtime simulation
43  {
44  private:
46  double last_time_;
55  adoreMatrix<double,10,1> x_;
69  protected:
72 
73 
74  public:
84  :indicator_right_off_from_(std::numeric_limits<double>::min()),indicator_left_off_from_(std::numeric_limits<double>::min())
85  {
86  simulationID_ = simulationID;
87  v2xStationID_ = v2xStationID;
88  integration_step_ = 0.005;
89  last_time_valid_ = false;
90  x_ = dlib::zeros_matrix<double>(10l,1l);
94  if(external_ego_measurement_models)
95  {
96  odom_output_ = nullptr;
97  gps_output_ = nullptr;
98  }
99  else
100  {
103  }
109  automatic_control_ = true;
110  checkpoint_clearance_ = false;
112  supress_input_ = false;
113  indstateReader_ = adore::fun::FunFactoryInstance::get()->getIndicatorCommandReader();
114  }
115 
119  void setAutomaticControl(bool value)
120  {
121  automatic_control_=value;
122  }
123 
128  {
130  }
131 
135  void setSupressInput(bool value)
136  {
137  supress_input_ = value;
138  }
139 
140  bool setIndicatorRightOn(double duration)
141  {
142  if(!last_time_valid_)
143  {
144  return false;
145  }
147  return true;
148  }
149 
150  bool setIndicatorLeftOn(double duration)
151  {
152  if(!last_time_valid_)
153  {
154  return false;
155  }
157  return true;
158  }
159 
164  virtual void run()
165  {
166  if( timer_->hasData() )
167  {
168 
169  if( reset_pose_feed_->hasNext() )
170  {
173  x_(0) = pose.getX();
174  x_(1) = pose.getY();
175  x_(2) = pose.getPSI();
176 
177  x_(3) = 0.0;
178  x_(4) = 0.0;
179  x_(5) = 0.0;
180  x_(6) = 0.0;
181  x_(7) = 0.0;
182  x_(8) = 0.0;
183  x_(9) = 0.0;
184  }
185  if( reset_twist_feed_->hasNext() )
186  {
189  x_(3) = twist.getVx();
190  x_(4) = twist.getVy();
191  x_(5) = twist.getOmega();
192  x_(6) = 0.0;
193  x_(7) = 0.0;
194  x_(8) = 0.0;
195  x_(9) = 0.0;
196  }
197 
198  double current_time;
199  timer_->getData(current_time);
200 
201  //handle checkpoint clearance event
203  {
204  last_time_checkpoint_clearance_ = current_time;
205  checkpoint_clearance_ = false;
206  }
207  bool delayed_checkpoint_clearance = (current_time - last_time_checkpoint_clearance_)<3.0;
208 
209  if(last_time_valid_)
210  {
211  if( automatic_control_
212  && control_input_->hasData()
213  && !supress_input_ )
214  {
216  }
217  else
218  {
219  u_.setAcceleration(0.0);
220  u_.setSteeringAngle(0.0);
221  }
222 
223  auto T = adore::mad::sequence(last_time_,integration_step_,current_time);
224 
225  x_(6) = u_.getAcceleration();
227  x_(8) = 0.0; //dax=0
228  x_(9) = 0.0; //ddelta=0
230  auto X = solver_.solve(&model,T,x_);
231  x_ = dlib::colm(X,X.nc()-1);
232 
233  //vehicle state measurement
235  xout.setX(x_(0));
236  xout.setY(x_(1));
237  xout.setZ(0.0);
238  xout.setPSI(x_(2));
239  xout.setvx(x_(3));
240  xout.setvy(x_(4));
241  xout.setOmega(x_(5));
242  xout.setAx(x_(6));
243  xout.setDelta(x_(7));
244  xout.setTime(current_time);
245  sim_output_->write(xout);
246  if(gps_output_!=nullptr)gps_output_->write(xout);
247  if(odom_output_!=nullptr)odom_output_->write(xout);
248 
249  //vehicle extended state
251  {
253  }
259  xxout.setCheckpointClearance(delayed_checkpoint_clearance);
263 
264  //publication of vehicle state to other vehicles
266  double length = params_->get_a()+params_->get_b()+params_->get_c()+params_->get_d();
267  double distance_to_center = length*0.5-params_->get_d();
268  yout.center_(0) = xout.getX() + std::cos(xout.getPSI())*distance_to_center;
269  yout.center_(1) = xout.getY() + std::sin(xout.getPSI())*distance_to_center;
270  yout.center_(2) = xout.getZ();
271  yout.classification_ = adore::env::traffic::Participant::EClassification::CAR;
272  yout.classification_certainty_ = 1.0;
273  yout.existance_certainty_ = 1.0;
274  yout.acceleration_x_ = xout.getAx();
275  yout.vx_ = xout.getvx();
276  yout.vy_ = xout.getvy() + xout.getOmega() * distance_to_center;
277  yout.yawrate_ = xout.getOmega();
278  yout.observation_time_ = current_time;
279  yout.height_ = 1.8;
280  yout.length_ = length;
281  yout.width_ = params_->get_bodyWidth();
282  yout.yaw_ = xout.getPSI();
283  yout.trackingID_ = simulationID_;
285  participant_writer_->write(yout);
286 
287  last_time_ = current_time;
288  }
289  else
290  {
291  last_time_ = current_time;
292  last_time_valid_ = true;
293  }
294  }
295  }
296 
297  };
298  }
299 }
a vehicle model which can be used in simulations
Definition: vehiclemodel.h:43
adore::mad::AReader< adore::fun::MotionCommand > * control_input_
Definition: vehiclemodel.h:58
adore::mad::AReader< adore::fun::IndicatorCommand > * indstateReader_
Definition: vehiclemodel.h:63
bool checkpoint_clearance_
Definition: vehiclemodel.h:51
params::APVehicle * params_
Definition: vehiclemodel.h:45
adore::mad::AReader< double > * timer_
Definition: vehiclemodel.h:57
adore::mad::OdeRK4< double > solver_
Definition: vehiclemodel.h:65
virtual void run()
simulation step of the vehicle model
Definition: vehiclemodel.h:164
double indicator_left_off_from_
Definition: vehiclemodel.h:53
adore::mad::AWriter< adore::fun::VehicleMotionState9d > * gps_output_
Definition: vehiclemodel.h:60
bool supress_input_
Definition: vehiclemodel.h:52
adore::mad::AWriter< adore::fun::VehicleMotionState9d > * odom_output_
Definition: vehiclemodel.h:61
adore::mad::AWriter< adore::fun::VehicleExtendedState > * extended_state_output_
Definition: vehiclemodel.h:62
void setSupressInput(bool value)
supress input to introduce errors, without deactivating automatic control
Definition: vehiclemodel.h:135
adore::sim::AFactory::TParticipantWriter * participant_writer_
Definition: vehiclemodel.h:68
adore::mad::AWriter< adore::fun::VehicleMotionState9d > * sim_output_
Definition: vehiclemodel.h:59
double last_time_
Definition: vehiclemodel.h:46
adore::mad::AFeed< adore::sim::ResetVehiclePose > * reset_pose_feed_
Definition: vehiclemodel.h:66
bool last_time_valid_
Definition: vehiclemodel.h:49
adore::mad::AFeed< adore::sim::ResetVehicleTwist > * reset_twist_feed_
Definition: vehiclemodel.h:67
adoreMatrix< double, 10, 1 > x_
Definition: vehiclemodel.h:55
bool automatic_control_
Definition: vehiclemodel.h:50
bool setIndicatorRightOn(double duration)
Definition: vehiclemodel.h:140
bool setIndicatorLeftOn(double duration)
Definition: vehiclemodel.h:150
adore::fun::IndicatorCommand indicatorCommand_
Definition: vehiclemodel.h:64
void setCheckpointClearance()
confirmation of current checkout
Definition: vehiclemodel.h:127
double integration_step_
Definition: vehiclemodel.h:47
adore::env::traffic::Participant::TV2XStationID v2xStationID_
Definition: vehiclemodel.h:71
double indicator_right_off_from_
Definition: vehiclemodel.h:54
adore::fun::MotionCommand u_
Definition: vehiclemodel.h:56
VehicleModel(bool external_ego_measurement_models, adore::env::traffic::Participant::TTrackingID simulationID, adore::env::traffic::Participant::TV2XStationID v2xStationID)
Construct a new Vehicle Model object.
Definition: vehiclemodel.h:83
adore::env::traffic::Participant::TTrackingID simulationID_
Definition: vehiclemodel.h:70
void setAutomaticControl(bool value)
switches between manual and automatic control input
Definition: vehiclemodel.h:119
double last_time_checkpoint_clearance_
Definition: vehiclemodel.h:48
static adore::fun::AFactory * get()
Definition: afactory.h:170
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: vlb_openloop.h:32
Definition: vehicleextendedstate.h:26
void setGearState(GearState gearState)
Definition: vehicleextendedstate.h:54
void setCheckpointClearance(bool checkpointClearance)
Definition: vehicleextendedstate.h:106
void setAutomaticControlAccelerationActive(bool automaticControlAccelerationActive)
Definition: vehicleextendedstate.h:86
@ Drive
Definition: vehicleextendedstate.h:30
void setIndicatorRightOn(bool indicatorRightOn)
Definition: vehicleextendedstate.h:70
void setAutomaticControlAccelerationOn(bool automaticControlAccelerationOn)
Definition: vehicleextendedstate.h:78
void setIndicatorLeftOn(bool indicatorLeftOn)
Definition: vehicleextendedstate.h:62
void setAutomaticControlSteeringOn(bool automaticControlSteeringOn)
Definition: vehicleextendedstate.h:94
virtual bool hasNext() const =0
virtual void getLatest(T &value)=0
virtual void getData(T &value)=0
virtual bool hasData() const =0
virtual bool hasUpdate() const =0
virtual void write(const T &value)=0
virtual adoreMatrix< T > solve(AOdeModel< T > *model, const adoreMatrix< double, 1, 0 > &time, const adoreMatrix< double, 0, 1 > &x0) override
Definition: oderk4.h:37
virtual APVehicle * getVehicle() const =0
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_steeringRatio() 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
virtual TVehicleMotionStateWriter * getVehicleMotionStateWriter()=0
write updates on the true vehicle motion state
virtual TVehicleMotionStateWriter * getOdometryEstimatedVehicleStateWriter()=0
write updates on the odometry estimated vehicle motion state
virtual TVehicleMotionStateWriter * getLocalizationEstimatedVehicleStateWriter()=0
write updates on the localization estimated vehicle motion state
virtual TMotionCommandReader * getMotionCommandReader()=0
read a motion command
virtual TVehiclePoseResetFeed * getVehiclePoseResetFeed()=0
read simulation commands for vehicle position and orientation resetting
virtual TVehicleTwistResetFeed * getVehicleTwistResetFeed()=0
read simulation commands for vehicle speed resetting
virtual TVehicleExtendedStateWriter * getVehicleExtendedStateWriter()=0
write updates on the vehicle extended state (buttons, etc.)
virtual TSimulationTimeReader * getSimulationTimeReader()=0
read the simulation time
virtual TParticipantWriter * getParticipantWriter()=0
send ego state to simulation feed
static adore::sim::AFactory * get()
Definition: afactory.h:145
adoreMatrix< T, 1, 0 > sequence(T x0, T dx, T xend)
Definition: adoremath.h:51
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
Definition: areaofeffectconverter.h:20
This struct holds the motion state of the vehicle in 9d.
Definition: vehiclemotionstate9d.h:39
void setZ(double value)
Set the z-coordinate.
Definition: vehiclemotionstate9d.h:127
void setY(double value)
Set the y-coordinate.
Definition: vehiclemotionstate9d.h:121
double getX() const
Get the x-coordinate.
Definition: vehiclemotionstate9d.h:54
double getvx() const
Get the longitudinal velocity.
Definition: vehiclemotionstate9d.h:78
void setAx(double value)
Set the longitudinal acceleration.
Definition: vehiclemotionstate9d.h:157
double getOmega() const
Get the yaw rate.
Definition: vehiclemotionstate9d.h:90
void setvx(double value)
set the longitudinal velocity
Definition: vehiclemotionstate9d.h:139
double getY() const
Get the y-coordinate.
Definition: vehiclemotionstate9d.h:60
double getPSI() const
Get the heading.
Definition: vehiclemotionstate9d.h:72
double getAx() const
Get the longitudinal acceleration.
Definition: vehiclemotionstate9d.h:96
void setOmega(double value)
Set the yaw rate.
Definition: vehiclemotionstate9d.h:151
double getvy() const
Get the lateral velocity.
Definition: vehiclemotionstate9d.h:84
void setX(double value)
Set the x-coordinate.
Definition: vehiclemotionstate9d.h:115
double getZ() const
Get the z-coordinate.
Definition: vehiclemotionstate9d.h:66
void setPSI(double value)
set the heading
Definition: vehiclemotionstate9d.h:133
void setvy(double value)
set the lateral velocity
Definition: vehiclemotionstate9d.h:145
void setDelta(double value)
Set the steering angle.
Definition: vehiclemotionstate9d.h:163
void setTime(double value)
Set the time.
Definition: vehiclemotionstate9d.h:109
Struct for representing a participant in traffic.
Definition: participant.h:30
double acceleration_x_
Definition: participant.h:106
double width_
Definition: participant.h:101
double vy_
Definition: participant.h:104
double yaw_
Definition: participant.h:99
double vx_
Definition: participant.h:103
adoreMatrix< double, 3, 1 > center_
Definition: participant.h:98
long long int TV2XStationID
Definition: participant.h:33
EClassification classification_
Definition: participant.h:95
TTrackingID trackingID_
Definition: participant.h:78
double classification_certainty_
Definition: participant.h:96
double height_
Definition: participant.h:102
int TTrackingID
Definition: participant.h:32
double existance_certainty_
Definition: participant.h:80
TV2XStationID v2xStationID_
Definition: participant.h:79
double length_
Definition: participant.h:100
double yawrate_
Definition: participant.h:105
double observation_time_
Definition: participant.h:81
Definition: indicatorcommand.h:25
bool getIndicatorLeftOn() const
Definition: indicatorcommand.h:35
bool getIndicatorRightOn() const
Definition: indicatorcommand.h:45
provides encapsulation of values needed to reset the vehicle pose in a simulation
Definition: resetvehiclepose.h:26
double getX() const
Definition: resetvehiclepose.h:35
double getY() const
Definition: resetvehiclepose.h:43
double getPSI() const
Definition: resetvehiclepose.h:51
provides encapsulation of values needed to reset the vehicle twist (vx,vy and omega) in a simulation
Definition: resetvehicletwist.h:26
double getVy() const
Definition: resetvehicletwist.h:41
double getVx() const
Definition: resetvehicletwist.h:32
double getOmega() const
Definition: resetvehicletwist.h:50