bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
fixed_wing_dynamics.h
Go to the documentation of this file.
1#ifndef BITSIM_DYNAMICS_FIXED_WING_DYNAMICS_H
2#define BITSIM_DYNAMICS_FIXED_WING_DYNAMICS_H
3
5
6#include <Eigen/Dense>
7
8#include <array>
9#include <vector>
10
11namespace bitsim::dynamics
12{
13
20
24namespace fw
25{
26enum Index : int
27{
28 PN = 0,
29 PE = 1,
30 PD = 2,
31 U = 3,
32 V = 4,
33 W = 5,
34 PHI = 6,
35 THETA = 7,
36 PSI = 8,
37 P = 9,
38 Q = 10,
39 R = 11
40};
41} // namespace fw
42
54
60{
61 std::array<real_t, 3> position;
62 real_t stiffness{2000.0};
63 real_t damping{120.0};
64 bool steers{false};
65 bool brakes{false};
66};
67
73{
74 // Mass and inertia
75 real_t mass{11.0};
76 real_t Jx{0.8244};
77 real_t Jy{1.135};
78 real_t Jz{1.759};
79 real_t Jxz{0.1204};
80
81 // Geometry and air
82 real_t S{0.55};
83 real_t b{2.8956};
84 real_t c{0.18994};
85 real_t rho{1.2682};
86 real_t e{0.9};
87
88 // Longitudinal coefficients
89 real_t CL0{0.23}, CL_alpha{5.61}, CL_q{7.95}, CL_de{0.13};
90 real_t CD0{0.043}, CD_q{0.0}, CD_de{0.0135};
91 real_t Cm0{0.0135}, Cm_alpha{-2.74}, Cm_q{-38.21}, Cm_de{-0.99};
94
95 // Lateral coefficients
96 real_t CY0{0.0}, CY_beta{-0.98}, CY_p{0.0}, CY_r{0.0}, CY_da{0.075}, CY_dr{0.19};
97 real_t Cl0{0.0}, Cl_beta{-0.13}, Cl_p{-0.51}, Cl_r{0.25}, Cl_da{0.17}, Cl_dr{0.0024};
98 real_t Cn0{0.0}, Cn_beta{0.073}, Cn_p{-0.069}, Cn_r{-0.095}, Cn_da{-0.011}, Cn_dr{-0.069};
99
100 // Propeller and motor
106 real_t CT0{0.09357}, CT1{-0.06044}, CT2{-0.1079};
107 real_t CQ0{0.005230}, CQ1{0.004970}, CQ2{-0.01664};
108
109 // Control limits [rad]
114
115 // Landing gear and ground
116 std::vector<LandingGearWheel> gear{
117 {{0.55, 0.0, 0.32}, 2000.0, 120.0, true, false},
118 {{-0.08, -0.45, 0.32}, 2000.0, 120.0, false, true},
119 {{-0.08, 0.45, 0.32}, 2000.0, 120.0, false, true},
120 };
125
130 static FixedWingParameters aerosonde() { return {}; }
131
132 real_t aspect_ratio() const { return b * b / S; }
133};
134
149
176{
177 public:
179
183 void step(const FixedWingControls &controls, real_t dt);
184
188 FixedWingState derivative(const FixedWingState &x, const FixedWingControls &controls) const;
189
193 FixedWingForces forces(const FixedWingState &x, const FixedWingControls &controls) const;
194
198 FixedWingControls limit(const FixedWingControls &controls) const;
199
203 void set_wind(const RealColVec3d &wind_ned) { wind_ = wind_ned; }
204 const RealColVec3d &wind() const noexcept { return wind_; }
205
206 const FixedWingState &state() const noexcept { return state_; }
207 FixedWingState &state() noexcept { return state_; }
208 const FixedWingParameters &parameters() const noexcept { return p_; }
209 real_t time() const noexcept { return time_; }
210
211 // The air data and the motion of the current state
212 real_t airspeed() const;
213 real_t alpha() const;
214 real_t beta() const;
215 real_t altitude() const { return -state_[fw::PD]; }
216 real_t ground_speed() const;
217 real_t course() const;
218 real_t climb_rate() const;
219 bool on_ground() const;
220
224 static RealMat3d rotation(real_t phi, real_t theta, real_t psi);
225
226 private:
228 FixedWingState state_;
229 RealColVec3d wind_{RealColVec3d::Zero()};
230 real_t time_{0.0};
231
232 // Gamma terms of the rotational equations
233 real_t g_[9];
234
235 void propeller_(real_t Va, real_t throttle, real_t &thrust, real_t &torque) const;
236};
237
238} // namespace bitsim::dynamics
239
240#endif // BITSIM_DYNAMICS_FIXED_WING_DYNAMICS_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
FixedWingState & state() noexcept
Definition fixed_wing_dynamics.h:207
bool on_ground() const
whether a wheel touches the ground
Definition fixed_wing_dynamics.cpp:270
real_t course() const
the direction of the velocity over the ground [rad]
Definition fixed_wing_dynamics.cpp:256
FixedWingDynamics(const FixedWingParameters &parameters, const FixedWingState &state)
Definition fixed_wing_dynamics.cpp:34
void step(const FixedWingControls &controls, real_t dt)
Advance by dt [s] with the given controls, which are first limited.
Definition fixed_wing_dynamics.cpp:223
const FixedWingState & state() const noexcept
Definition fixed_wing_dynamics.h:206
FixedWingForces forces(const FixedWingState &x, const FixedWingControls &controls) const
Definition fixed_wing_dynamics.cpp:102
real_t altitude() const
Definition fixed_wing_dynamics.h:215
FixedWingState derivative(const FixedWingState &x, const FixedWingControls &controls) const
Definition fixed_wing_dynamics.cpp:200
real_t time() const noexcept
Definition fixed_wing_dynamics.h:209
const RealColVec3d & wind() const noexcept
Definition fixed_wing_dynamics.h:204
real_t beta() const
Definition fixed_wing_dynamics.cpp:247
real_t ground_speed() const
Definition fixed_wing_dynamics.cpp:249
real_t alpha() const
Definition fixed_wing_dynamics.cpp:246
void set_wind(const RealColVec3d &wind_ned)
The wind, in the world [m/s]; the direction it blows towards.
Definition fixed_wing_dynamics.h:203
real_t climb_rate() const
[m/s], positive up
Definition fixed_wing_dynamics.cpp:263
static RealMat3d rotation(real_t phi, real_t theta, real_t psi)
Definition fixed_wing_dynamics.cpp:55
FixedWingControls limit(const FixedWingControls &controls) const
Definition fixed_wing_dynamics.cpp:63
const FixedWingParameters & parameters() const noexcept
Definition fixed_wing_dynamics.h:208
real_t airspeed() const
Definition fixed_wing_dynamics.cpp:245
Where each value is in a FixedWingState.
Definition fixed_wing_dynamics.h:25
Index
Definition fixed_wing_dynamics.h:27
@ THETA
Definition fixed_wing_dynamics.h:35
@ PE
Definition fixed_wing_dynamics.h:29
@ V
Definition fixed_wing_dynamics.h:32
@ PD
Definition fixed_wing_dynamics.h:30
@ P
Definition fixed_wing_dynamics.h:37
@ PN
Definition fixed_wing_dynamics.h:28
@ U
Definition fixed_wing_dynamics.h:31
@ Q
Definition fixed_wing_dynamics.h:38
@ PSI
Definition fixed_wing_dynamics.h:36
@ PHI
Definition fixed_wing_dynamics.h:34
@ R
Definition fixed_wing_dynamics.h:39
@ W
Definition fixed_wing_dynamics.h:33
Models of how things move: wheeled robots, a bicycle, a quadrotor and a fixed wing aircraft,...
Definition bicycle_vehicle_model_dynamics.cpp:10
UnalignedMat< real_t, 12, 1 > FixedWingState
The 12 values of the state of a fixed wing aircraft, in this order: the position (north,...
Definition fixed_wing_dynamics.h:19
Eigen::Matrix< T, N, M, Eigen::DontAlign|(N==1 &&M !=1 ? Eigen::RowMajor :Eigen::ColMajor)> UnalignedMat
General fixed size matrix that Eigen does not align. Use it for a fixed size member of a class that i...
Definition bitsim_types.h:74
Eigen::Matrix3< real_t > RealMat3d
3×3 matrix of type double.
Definition bitsim_types.h:86
double real_t
real_t
Definition bitsim_types.h:20
Eigen::Vector3d RealColVec3d
3D column vector
Definition bitsim_types.h:137
What the pilot or the autopilot sets.
Definition fixed_wing_dynamics.h:47
real_t brake
of the main wheels, in [0, 1]
Definition fixed_wing_dynamics.h:52
real_t elevator
[rad]; positive is trailing edge down, which pitches the nose down
Definition fixed_wing_dynamics.h:48
real_t throttle
in [0, 1], up to FixedWingParameters::max_throttle
Definition fixed_wing_dynamics.h:51
real_t aileron
[rad]; positive rolls the aircraft right
Definition fixed_wing_dynamics.h:49
real_t rudder
[rad]; positive yaws the nose left, and steers the nose wheel left
Definition fixed_wing_dynamics.h:50
The forces and moments on the aircraft, in the body frame, and the air data they come from.
Definition fixed_wing_dynamics.h:140
real_t alpha
the angle of attack [rad]
Definition fixed_wing_dynamics.h:144
real_t beta
the sideslip angle [rad]
Definition fixed_wing_dynamics.h:145
real_t thrust
[N]
Definition fixed_wing_dynamics.h:146
RealColVec3d force
[N]
Definition fixed_wing_dynamics.h:141
real_t airspeed
[m/s]
Definition fixed_wing_dynamics.h:143
real_t ground_load
the sum of the wheels' normal forces [N]
Definition fixed_wing_dynamics.h:147
RealColVec3d moment
[N m]
Definition fixed_wing_dynamics.h:142
The aircraft: its mass, its geometry, its aerodynamic coefficients, its propeller and motor,...
Definition fixed_wing_dynamics.h:73
real_t Cm_de
Definition fixed_wing_dynamics.h:91
real_t c
the mean chord [m]
Definition fixed_wing_dynamics.h:84
real_t e
the Oswald efficiency of the wing
Definition fixed_wing_dynamics.h:86
real_t Cn0
Definition fixed_wing_dynamics.h:98
real_t nose_steering
nose wheel angle per rad of rudder
Definition fixed_wing_dynamics.h:121
real_t Cl_beta
Definition fixed_wing_dynamics.h:97
real_t stall_sharpness
how suddenly it stalls
Definition fixed_wing_dynamics.h:93
real_t max_rudder
Definition fixed_wing_dynamics.h:112
real_t CY_r
Definition fixed_wing_dynamics.h:96
real_t CL_de
Definition fixed_wing_dynamics.h:89
real_t Cl_da
Definition fixed_wing_dynamics.h:97
real_t CQ0
Definition fixed_wing_dynamics.h:107
real_t CT1
Definition fixed_wing_dynamics.h:106
real_t Cn_dr
Definition fixed_wing_dynamics.h:98
real_t CT0
Definition fixed_wing_dynamics.h:106
real_t motor_KV
[rpm/V]
Definition fixed_wing_dynamics.h:102
std::vector< LandingGearWheel > gear
Definition fixed_wing_dynamics.h:116
real_t Jx
[kg m^2]
Definition fixed_wing_dynamics.h:76
real_t aspect_ratio() const
Definition fixed_wing_dynamics.h:132
real_t Cn_r
Definition fixed_wing_dynamics.h:98
real_t Cm_alpha
Definition fixed_wing_dynamics.h:91
real_t mass
[kg]
Definition fixed_wing_dynamics.h:75
real_t Jz
[kg m^2]
Definition fixed_wing_dynamics.h:78
real_t Jxz
[kg m^2]
Definition fixed_wing_dynamics.h:79
real_t Cl_dr
Definition fixed_wing_dynamics.h:97
real_t CY_beta
Definition fixed_wing_dynamics.h:96
real_t CD0
Definition fixed_wing_dynamics.h:90
real_t CY0
Definition fixed_wing_dynamics.h:96
real_t motor_i0
the no-load current [A]
Definition fixed_wing_dynamics.h:104
real_t prop_diameter
[m]
Definition fixed_wing_dynamics.h:101
real_t CD_q
Definition fixed_wing_dynamics.h:90
real_t CD_de
Definition fixed_wing_dynamics.h:90
real_t rho
the density of the air [kg/m^3]
Definition fixed_wing_dynamics.h:85
real_t stall_alpha
the angle of attack at which the wing stalls [rad]
Definition fixed_wing_dynamics.h:92
real_t motor_R
[ohm]
Definition fixed_wing_dynamics.h:103
real_t CQ2
torque coefficient in it
Definition fixed_wing_dynamics.h:107
real_t CL_q
Definition fixed_wing_dynamics.h:89
real_t CY_dr
Definition fixed_wing_dynamics.h:96
real_t S
the wing area [m^2]
Definition fixed_wing_dynamics.h:82
real_t rolling_friction
Definition fixed_wing_dynamics.h:122
real_t battery_V
the voltage at full throttle [V]
Definition fixed_wing_dynamics.h:105
real_t Cl_p
Definition fixed_wing_dynamics.h:97
real_t max_aileron
Definition fixed_wing_dynamics.h:111
real_t Cm0
Definition fixed_wing_dynamics.h:91
real_t Cm_q
Definition fixed_wing_dynamics.h:91
real_t Cl0
Definition fixed_wing_dynamics.h:97
real_t CY_da
Definition fixed_wing_dynamics.h:96
real_t brake_friction
at full brake
Definition fixed_wing_dynamics.h:123
real_t side_friction
Definition fixed_wing_dynamics.h:124
real_t CL0
Definition fixed_wing_dynamics.h:89
real_t Cn_beta
Definition fixed_wing_dynamics.h:98
static FixedWingParameters aerosonde()
The Aerosonde of Beard and McLain, Small Unmanned Aircraft, 2nd edition, with a tricycle landing gear...
Definition fixed_wing_dynamics.h:130
real_t CY_p
Definition fixed_wing_dynamics.h:96
real_t max_elevator
Definition fixed_wing_dynamics.h:110
real_t b
the wing span [m]
Definition fixed_wing_dynamics.h:83
real_t Cl_r
Definition fixed_wing_dynamics.h:97
real_t CL_alpha
Definition fixed_wing_dynamics.h:89
real_t Cn_p
Definition fixed_wing_dynamics.h:98
real_t CQ1
Definition fixed_wing_dynamics.h:107
real_t Jy
[kg m^2]
Definition fixed_wing_dynamics.h:77
real_t CT2
thrust coefficient in the advance ratio
Definition fixed_wing_dynamics.h:106
real_t max_throttle
the throttle is in [0, max_throttle]
Definition fixed_wing_dynamics.h:113
real_t Cn_da
Definition fixed_wing_dynamics.h:98
A wheel of the landing gear: a spring and damper along the body z axis, that rolls along its heading ...
Definition fixed_wing_dynamics.h:60
bool brakes
the main wheels brake
Definition fixed_wing_dynamics.h:65
bool steers
the nose wheel turns with the rudder
Definition fixed_wing_dynamics.h:64
std::array< real_t, 3 > position
where it touches the ground, in the body frame [m]
Definition fixed_wing_dynamics.h:61
real_t stiffness
[N/m]
Definition fixed_wing_dynamics.h:62
real_t damping
[N s/m]
Definition fixed_wing_dynamics.h:63