Drake
dynamic_bicycle_car.h
Go to the documentation of this file.
1 #pragma once
2
3 #include "drake/automotive/gen/dynamic_bicycle_car_input.h"
4 #include "drake/automotive/gen/dynamic_bicycle_car_params.h"
5 #include "drake/automotive/gen/dynamic_bicycle_car_state.h"
7
8 namespace drake {
9 namespace automotive {
10
11 /// DynamicBicycleCar implements a planar rigid body bicycle model of an
12 /// automobile with a non-linear brush tire model from Bobier (2012) [1]. This
13 /// is a simplified model that assumes a vehicle that has two wheels: one at the
14 /// front, and one at the rear. Also, this three-DOF model captures the dynamics
15 /// in the lateral (Cy), longitudinal (Cx), and yaw (about Cz) directions but
16 /// not the roll (about Cx) and pitch (about Cy) directions.
17 ///
18 /// There are three coordinate frames of interest in this model: a local frame L
19 /// fixed on earth with origin Lo, a frame attached to the vehicle's chassis C
20 /// with the origin of C being Co located at a distance of Lf from the front
21 /// axle along the center line of the vehicle, and a steering frame D with the
22 /// origin Do located at the front axle along the center line of the vehicle.
23 /// Note that the point Co is also referred to as the control point Cp, and
24 /// although the location of the vehicle's center of mass Ccm can move depending
25 /// on weight transfer dynamics, it is assumed that the location of Ccm is
26 /// coincident with Co and Ccp. L is a cartesian, right handed coordinate system
27 /// with Lz being gravity aligned (gravity acts in the negative Lz direction).
28 ///
29 /// The states of the model are:
30 /// - Lx measure of the location of Cp from Lo p_LoCp_x [m]
31 /// - Ly measure of the location of Cp from Lo p_LoCp_y [m]
32 /// - Yaw angle from Lx to Cx with positive Lz sense yaw_LC [rad]
33 /// - Cx measure of Cp's velocity in L v_LCp_x [m/s]
34 /// - Cy measure of Cp's velocity in L v_LCp_y [m/s]
35 /// - C's angular velocity in frame L yawDt_LC [rad/s]
36 ///
37 /// Inputs to this system:
38 /// - Steer angle from Cx to Dx with positive Cz sense steer_CD [rad]
39 /// - The Cx measure of the Longitudinal force on body C at Cp f_Cp_x [N]
40 ///
41 /// Outputs of this system:
42 /// - A DynamicBicycleCarState containing the 6-dimensional state vector of
43 /// the vehicle.
44 ///
45 /// Note that the vehicle's angular velocity in L yawDt_LC is sometimes
46 /// referred to as the yaw rate r, and the tire angle is sometimes referred
47 /// to as δ.
48 ///
49 /// Instantiated templates for the following kinds of T's are provided:
50 /// - double
51 /// - drake::AutoDiffXd
52 /// - drake::symbolic::Expression
53 ///
54 /// [1] C. Bobier. A Phase Portrait Approach to Vehicle Stability
55 /// and Envelope Control. Ph. D. thesis (Stanford University), 2012.
56 /// pp. 22 - 25, pp. 35.
57 ///
58 /// [2] H. Pacejka, Tire and vehicle dynamics, 3rd ed. Society of Automotive
59 /// Engineers and Butterworth-Heinemann, 2012.
60 ///
61 /// [3] G. Heydinger, R. Bixel, W. Garrott, M. Pyne, J. Howe and D. Guenther,
62 /// "Measured Vehicle Inertial Parameters-NHTSA’s Data Through November
63 /// 1998", SAE Technical Paper Series, 1999. p. 24.
64 ///
65 /// @ingroup automotive_plants
66
67 template <typename T>
68 class DynamicBicycleCar final : public systems::LeafSystem<T> {
69  public:
71
72  /// Default constructor.
74
75  /// Scalar-converting copy constructor. See @ref system_scalar_conversion.
76  template <typename U>
78  : DynamicBicycleCar<T>() {}
79
80  /// Specifies whether to use the front or rear tire for calculating various
81  /// parameters.
82  enum class Tire {
83  kFrontTire,
84  kRearTire,
85  };
86
87  /// Returns the port to output the state.
89
90  /// Returns the input port to the tire angle and applied longitudinal force.
92
93  const DynamicBicycleCarState<T>& get_state(
94  const systems::Context<T>& context) const;
95
96  DynamicBicycleCarState<T>& get_mutable_state(
97  systems::Context<T>* context) const;
98
99  /// Slip angle of front or rear tires.
100  static T CalcTireSlip(const DynamicBicycleCarState<T>& state,
101  const DynamicBicycleCarParams<T>& params,
102  const T& steer_angle, Tire tire_select);
103
104  /// Normal forces on the front or rear tires.
105  static T CalcNormalTireForce(const DynamicBicycleCarParams<T>& params,
106  const T& f_x, Tire tire_select);
107
108  /// Lateral tire forces on the front or rear tires.
109  static T CalcLateralTireForce(const T& tire_slip_angle,
110  const T& c_alpha, const T& f_z,
111  const T& mu);
112
113  private:
114  // Evaluates the input port and returns the scalar value of the steering
115  // angle.
116  const T get_steer(const systems::Context<T>& context) const {
117  return this->EvalVectorInput(context, 0)
118  ->GetAtIndex(DynamicBicycleCarInputIndices::kSteerCd);
119  }
120
121  // Evaluates the input port and returns the scalar value of the longitudinal
122  // force.
123  const T get_longitudinal_force(const systems::Context<T>& context) const {
124  return this->EvalVectorInput(context, 0)
125  ->GetAtIndex(DynamicBicycleCarInputIndices::kFCpX);
126  }
127
128  // Copies the state out to the output port.
129  void CopyStateOut(const systems::Context<T>& context,
130  DynamicBicycleCarState<T>* output) const;
131
132  // Calculates the time derivatives of the state.
133  void DoCalcTimeDerivatives(
134  const systems::Context<T>& context,
135  systems::ContinuousState<T>* derivatives) const override;
136 };
137
138 } // namespace automotive
139 } // namespace drake
DynamicBicycleCar(const DynamicBicycleCar< U > &)
Scalar-converting copy constructor. See System Scalar Conversion.
Definition: dynamic_bicycle_car.h:77
const Vec< T > * EvalVectorInput(const Context< T > &context, int port_index) const
Returns the value of the vector-valued input port with the given port_index as a BasicVector or a spe...
Definition: system.h:529
Definition: bullet_model.cc:22
const systems::OutputPort< T > & get_output_port() const
Returns the port to output the state.
Definition: dynamic_bicycle_car.cc:31
static T CalcNormalTireForce(const DynamicBicycleCarParams< T > &params, const T &f_x, Tire tire_select)
Normal forces on the front or rear tires.
Definition: dynamic_bicycle_car.cc:84
const systems::InputPort< T > & get_input_port() const
Returns the input port to the tire angle and applied longitudinal force.
Definition: dynamic_bicycle_car.cc:36
Context is an abstract class template that represents all the typed values that are used in a System&#39;...
Definition: context.h:40
static T CalcTireSlip(const DynamicBicycleCarState< T > &state, const DynamicBicycleCarParams< T > &params, const T &steer_angle, Tire tire_select)
Slip angle of front or rear tires.
Definition: dynamic_bicycle_car.cc:66
An OutputPort belongs to a System and represents the properties of one of that System&#39;s output ports...
Definition: output_port.h:71
A superclass template that extends System with some convenience utilities that are not applicable to ...
Definition: leaf_system.h:81
Tire
Specifies whether to use the front or rear tire for calculating various parameters.
Definition: dynamic_bicycle_car.h:82
DynamicBicycleCar implements a planar rigid body bicycle model of an automobile with a non-linear bru...
Definition: dynamic_bicycle_car.h:68
const DynamicBicycleCarState< T > & get_state(const systems::Context< T > &context) const
Definition: dynamic_bicycle_car.cc:42
DynamicBicycleCar()
Default constructor.
Definition: dynamic_bicycle_car.cc:13
boolean< T > T
Definition: drake_bool_deprecated.h:26
ContinuousState is a view of, and optionally a container for, all the continuous state variables xc o...
Definition: continuous_state.h:76
DynamicBicycleCarState< T > & get_mutable_state(systems::Context< T > *context) const
Definition: dynamic_bicycle_car.cc:51
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:33
This extends InputPortBase with some scalar type-dependent methods.
Definition: input_port.h:22
static T CalcLateralTireForce(const T &tire_slip_angle, const T &c_alpha, const T &f_z, const T &mu)
Lateral tire forces on the front or rear tires.
Definition: dynamic_bicycle_car.cc:101
double steer_angle
Definition: dynamic_bicycle_car_test.cc:18