fw_parameters.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Pavel Vechersky, ASL, ETH Zurich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ROTORS_GAZEBO_PLUGINS_FW_PARAMETERS_H_
18 #define ROTORS_GAZEBO_PLUGINS_FW_PARAMETERS_H_
19 
20 #include <Eigen/Dense>
21 #include <yaml-cpp/yaml.h>
22 
23 namespace gazebo {
24 
25 // Forward declaration.
26 struct ControlSurface;
27 
28 // Default vehicle parameters (Techpod model)
29 static constexpr double kDefaultWingSpan = 2.59;
30 static constexpr double kDefaultWingSurface = 0.47;
31 static constexpr double kDefaultChordLength = 0.18;
32 static constexpr double kDefaultThrustInclination = 0.0;
33 
34 // Default aerodynamic parameter values (Techpod model)
35 static constexpr double kDefaultAlphaMax = 0.27;
36 static constexpr double kDefaultAlphaMin = -0.27;
37 
38 static const Eigen::Vector3d kDefaultCDragAlpha =
39  Eigen::Vector3d(0.1360, -0.6737, 5.4546);
40 static const Eigen::Vector3d kDefaultCDragBeta =
41  Eigen::Vector3d(0.0195, 0.0, -0.3842);
42 static const Eigen::Vector3d kDefaultCDragDeltaAil =
43  Eigen::Vector3d(0.0195, 1.4205e-4, 7.5037e-6);
44 static const Eigen::Vector3d kDefaultCDragDeltaFlp =
45  Eigen::Vector3d(0.0195, 2.7395e-4, 1.23e-5);
46 
47 static const Eigen::Vector2d kDefaultCSideForceBeta =
48  Eigen::Vector2d(0.0, -0.3073);
49 
50 static const Eigen::Vector4d kDefaultCLiftAlpha =
51  Eigen::Vector4d(0.2127, 10.8060, -46.8324, 60.6017);
52 static const Eigen::Vector2d kDefaultCLiftDeltaAil =
53  Eigen::Vector2d(0.3304, 0.0048);
54 static const Eigen::Vector2d kDefaultCLiftDeltaFlp =
55  Eigen::Vector2d(0.3304, 0.0073);
56 
57 static const Eigen::Vector2d kDefaultCRollMomentBeta =
58  Eigen::Vector2d(0.0, -0.0154);
59 static const Eigen::Vector2d kDefaultCRollMomentP =
60  Eigen::Vector2d(0.0, -0.1647);
61 static const Eigen::Vector2d kDefaultCRollMomentR =
62  Eigen::Vector2d(0.0, 0.0117);
63 static const Eigen::Vector2d kDefaultCRollMomentDeltaAil =
64  Eigen::Vector2d(0.0, 0.0570);
65 static const Eigen::Vector2d kDefaultCRollMomentDeltaFlp =
66  Eigen::Vector2d(0.0, 0.001);
67 
68 static const Eigen::Vector2d kDefaultCPitchMomentAlpha =
69  Eigen::Vector2d(0.0435, -2.9690);
70 static const Eigen::Vector2d kDefaultCPitchMomentQ =
71  Eigen::Vector2d(-0.1173, -106.1541);
72 static const Eigen::Vector2d kDefaultCPitchMomentDeltaElv =
73  Eigen::Vector2d(-0.1173, -6.1308);
74 
75 static const Eigen::Vector2d kDefaultCYawMomentBeta =
76  Eigen::Vector2d(0.0, 0.0430);
77 static const Eigen::Vector2d kDefaultCYawMomentR =
78  Eigen::Vector2d(0.0, -0.0827);
79 static const Eigen::Vector2d kDefaultCYawMomentDeltaRud =
80  Eigen::Vector2d(0.0, 0.06);
81 
82 static const Eigen::Vector3d kDefaultCThrust =
83  Eigen::Vector3d(0.0, 14.7217, 0.0);
84 
85 // Default values for fixed-wing controls (Techpod model)
86 static constexpr double kDefaultControlSurfaceDeflectionMin =
87  -20.0 * M_PI / 180.0;
88 static constexpr double kDefaultControlSurfaceDeflectionMax =
89  20.0 * M_PI / 180.0;
90 
91 static constexpr int kDefaultAileronLeftChannel = 4;
92 static constexpr int kDefaultAileronRightChannel = 0;
93 static constexpr int kDefaultElevatorChannel = 1;
94 static constexpr int kDefaultFlapChannel = 2;
95 static constexpr int kDefaultRudderChannel = 3;
96 static constexpr int kDefaultThrottleChannel = 5;
97 
100 inline void YAMLReadControlSurface(const YAML::Node& node,
101  const std::string& name,
102  ControlSurface& surface);
103 
106 template <typename Derived>
107 inline void YAMLReadEigenVector(const YAML::Node& node,
108  const std::string& name,
109  Eigen::MatrixBase<Derived>& value);
110 
112 template <typename T>
113 inline void YAMLReadParam(const YAML::Node& node,
114  const std::string& name,
115  T& value);
116 
118 #define READ_CONTROL_SURFACE(node, item) \
119  YAMLReadControlSurface(node, #item, item);
120 #define READ_EIGEN_VECTOR(node, item) YAMLReadEigenVector(node, #item, item);
121 #define READ_PARAM(node, item) YAMLReadParam(node, #item, item);
122 
124  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
125 
127  : alpha_max(kDefaultAlphaMax),
128  alpha_min(kDefaultAlphaMin),
129  c_drag_alpha(kDefaultCDragAlpha),
130  c_drag_beta(kDefaultCDragBeta),
131  c_drag_delta_ail(kDefaultCDragDeltaAil),
132  c_drag_delta_flp(kDefaultCDragDeltaFlp),
133  c_side_force_beta(kDefaultCSideForceBeta),
134  c_lift_alpha(kDefaultCLiftAlpha),
135  c_lift_delta_ail(kDefaultCLiftDeltaAil),
136  c_lift_delta_flp(kDefaultCLiftDeltaFlp),
137  c_roll_moment_beta(kDefaultCRollMomentBeta),
138  c_roll_moment_p(kDefaultCRollMomentP),
139  c_roll_moment_r(kDefaultCRollMomentR),
140  c_roll_moment_delta_ail(kDefaultCRollMomentDeltaAil),
141  c_roll_moment_delta_flp(kDefaultCRollMomentDeltaFlp),
142  c_pitch_moment_alpha(kDefaultCPitchMomentAlpha),
143  c_pitch_moment_q(kDefaultCPitchMomentQ),
144  c_pitch_moment_delta_elv(kDefaultCPitchMomentDeltaElv),
145  c_yaw_moment_beta(kDefaultCYawMomentBeta),
146  c_yaw_moment_r(kDefaultCYawMomentR),
147  c_yaw_moment_delta_rud(kDefaultCYawMomentDeltaRud),
148  c_thrust(kDefaultCThrust) {}
149 
150  double alpha_max;
151  double alpha_min;
152 
153  Eigen::Vector3d c_drag_alpha;
154  Eigen::Vector3d c_drag_beta;
155  Eigen::Vector3d c_drag_delta_ail;
156  Eigen::Vector3d c_drag_delta_flp;
157 
158  Eigen::Vector2d c_side_force_beta;
159 
160  Eigen::Vector4d c_lift_alpha;
161  Eigen::Vector2d c_lift_delta_ail;
162  Eigen::Vector2d c_lift_delta_flp;
163 
164  Eigen::Vector2d c_roll_moment_beta;
165  Eigen::Vector2d c_roll_moment_p;
166  Eigen::Vector2d c_roll_moment_r;
167  Eigen::Vector2d c_roll_moment_delta_ail;
168  Eigen::Vector2d c_roll_moment_delta_flp;
169 
170  Eigen::Vector2d c_pitch_moment_alpha;
171  Eigen::Vector2d c_pitch_moment_q;
172  Eigen::Vector2d c_pitch_moment_delta_elv;
173 
174  Eigen::Vector2d c_yaw_moment_beta;
175  Eigen::Vector2d c_yaw_moment_r;
176  Eigen::Vector2d c_yaw_moment_delta_rud;
177 
178  Eigen::Vector3d c_thrust;
179 
180  void LoadAeroParamsYAML(const std::string& yaml_path) {
181  const YAML::Node node = YAML::LoadFile(yaml_path);
182 
183  READ_PARAM(node, alpha_max);
184  READ_PARAM(node, alpha_min);
185 
186  READ_EIGEN_VECTOR(node, c_drag_alpha);
187  READ_EIGEN_VECTOR(node, c_drag_beta);
188  READ_EIGEN_VECTOR(node, c_drag_delta_ail);
189  READ_EIGEN_VECTOR(node, c_drag_delta_flp);
190 
191  READ_EIGEN_VECTOR(node, c_side_force_beta);
192 
193  READ_EIGEN_VECTOR(node, c_lift_alpha);
194  READ_EIGEN_VECTOR(node, c_lift_delta_ail);
195  READ_EIGEN_VECTOR(node, c_lift_delta_flp);
196 
197  READ_EIGEN_VECTOR(node, c_roll_moment_beta);
198  READ_EIGEN_VECTOR(node, c_roll_moment_p);
199  READ_EIGEN_VECTOR(node, c_roll_moment_r);
200  READ_EIGEN_VECTOR(node, c_roll_moment_delta_ail);
201  READ_EIGEN_VECTOR(node, c_roll_moment_delta_flp);
202 
203  READ_EIGEN_VECTOR(node, c_pitch_moment_alpha);
204  READ_EIGEN_VECTOR(node, c_pitch_moment_q);
205  READ_EIGEN_VECTOR(node, c_pitch_moment_delta_elv);
206 
207  READ_EIGEN_VECTOR(node, c_yaw_moment_beta);
208  READ_EIGEN_VECTOR(node, c_yaw_moment_r);
209  READ_EIGEN_VECTOR(node, c_yaw_moment_delta_rud);
210 
211  READ_EIGEN_VECTOR(node, c_thrust);
212  }
213 };
214 
216  ControlSurface(int cs_channel,
217  double defl_min = kDefaultControlSurfaceDeflectionMin,
218  double defl_max = kDefaultControlSurfaceDeflectionMax)
219  : channel(cs_channel),
220  deflection_min(defl_min),
221  deflection_max(defl_max) {}
222 
223  int channel;
224 
227 
228  void LoadControlSurfaceNode(const YAML::Node& node) {
229  READ_PARAM(node, channel);
230  READ_PARAM(node, deflection_min);
231  READ_PARAM(node, deflection_max);
232  }
233 };
234 
237  : wing_span(kDefaultWingSpan),
238  wing_surface(kDefaultWingSurface),
239  chord_length(kDefaultChordLength),
240  thrust_inclination(kDefaultThrustInclination),
241  throttle_channel(kDefaultThrottleChannel),
242  aileron_left(kDefaultAileronLeftChannel),
243  aileron_right(kDefaultAileronRightChannel),
244  elevator(kDefaultElevatorChannel),
245  flap(kDefaultFlapChannel),
246  rudder(kDefaultRudderChannel) {}
247 
248  double wing_span;
249  double wing_surface;
250  double chord_length;
252 
254 
260 
261  void LoadVehicleParamsYAML(const std::string& yaml_path) {
262  const YAML::Node node = YAML::LoadFile(yaml_path);
263 
264  READ_PARAM(node, wing_span);
265  READ_PARAM(node, wing_surface);
266  READ_PARAM(node, chord_length);
267  READ_PARAM(node, thrust_inclination);
268 
269  READ_PARAM(node, throttle_channel);
270 
271  READ_CONTROL_SURFACE(node, aileron_left);
272  READ_CONTROL_SURFACE(node, aileron_right);
273  READ_CONTROL_SURFACE(node, elevator);
274  READ_CONTROL_SURFACE(node, flap);
275  READ_CONTROL_SURFACE(node, rudder);
276  }
277 };
278 
279 inline void YAMLReadControlSurface(const YAML::Node& node,
280  const std::string& name,
281  ControlSurface& surface) {
282  const YAML::Node surface_node = node[name];
283  surface.LoadControlSurfaceNode(surface_node);
284 }
285 
286 template <typename Derived>
287 inline void YAMLReadEigenVector(const YAML::Node& node,
288  const std::string& name,
289  Eigen::MatrixBase<Derived>& value) {
290  std::vector<typename Derived::RealScalar> vec =
291  node[name].as<std::vector<typename Derived::RealScalar>>();
292  assert(vec.size() == Derived::SizeAtCompileTime);
293  value = Eigen::Map<Derived>(&vec[0], vec.size());
294 }
295 
296 template <typename T>
297 inline void YAMLReadParam(const YAML::Node& node,
298  const std::string& name,
299  T& value) {
300  value = node[name].as<T>();
301 }
302 
303 }
304 
305 #endif /* ROTORS_GAZEBO_PLUGINS_FW_PARAMETERS_H_ */
static const Eigen::Vector2d kDefaultCPitchMomentAlpha
Definition: fw_parameters.h:68
void LoadVehicleParamsYAML(const std::string &yaml_path)
void YAMLReadControlSurface(const YAML::Node &node, const std::string &name, ControlSurface &surface)
Wrapper function for extracting control surface parameters from a YAML node.
Eigen::Vector2d c_roll_moment_delta_flp
EIGEN_MAKE_ALIGNED_OPERATOR_NEW FWAerodynamicParameters()
static const Eigen::Vector4d kDefaultCLiftAlpha
Definition: fw_parameters.h:50
static const Eigen::Vector2d kDefaultCRollMomentBeta
Definition: fw_parameters.h:57
static constexpr double kDefaultAlphaMin
Definition: fw_parameters.h:36
static constexpr int kDefaultElevatorChannel
Definition: fw_parameters.h:93
void YAMLReadParam(const YAML::Node &node, const std::string &name, T &value)
This function reads a parameter from a YAML node.
static const Eigen::Vector2d kDefaultCRollMomentP
Definition: fw_parameters.h:59
static const Eigen::Vector3d kDefaultCThrust
Definition: fw_parameters.h:82
static constexpr int kDefaultAileronLeftChannel
Definition: fw_parameters.h:91
static constexpr double kDefaultControlSurfaceDeflectionMin
Definition: fw_parameters.h:86
#define READ_CONTROL_SURFACE(node, item)
Macros to reduce copies of names.
#define M_PI
static const Eigen::Vector3d kDefaultCDragBeta
Definition: fw_parameters.h:40
static constexpr double kDefaultControlSurfaceDeflectionMax
Definition: fw_parameters.h:88
static constexpr double kDefaultWingSurface
Definition: fw_parameters.h:30
static constexpr double kDefaultThrustInclination
Definition: fw_parameters.h:32
#define READ_PARAM(node, item)
static const Eigen::Vector3d kDefaultCDragDeltaAil
Definition: fw_parameters.h:42
static constexpr double kDefaultChordLength
Definition: fw_parameters.h:31
static const Eigen::Vector2d kDefaultCPitchMomentQ
Definition: fw_parameters.h:70
static constexpr int kDefaultRudderChannel
Definition: fw_parameters.h:95
static const Eigen::Vector2d kDefaultCRollMomentDeltaFlp
Definition: fw_parameters.h:65
Eigen::Vector2d c_roll_moment_delta_ail
static constexpr double kDefaultWingSpan
Definition: fw_parameters.h:29
Eigen::Vector2d c_pitch_moment_delta_elv
static const Eigen::Vector2d kDefaultCLiftDeltaAil
Definition: fw_parameters.h:52
static constexpr int kDefaultAileronRightChannel
Definition: fw_parameters.h:92
static const Eigen::Vector2d kDefaultCYawMomentR
Definition: fw_parameters.h:77
static const Eigen::Vector2d kDefaultCPitchMomentDeltaElv
Definition: fw_parameters.h:72
void LoadControlSurfaceNode(const YAML::Node &node)
void LoadAeroParamsYAML(const std::string &yaml_path)
static const Eigen::Vector2d kDefaultCLiftDeltaFlp
Definition: fw_parameters.h:54
static constexpr int kDefaultFlapChannel
Definition: fw_parameters.h:94
static constexpr int kDefaultThrottleChannel
Definition: fw_parameters.h:96
static const Eigen::Vector2d kDefaultCYawMomentDeltaRud
Definition: fw_parameters.h:79
void YAMLReadEigenVector(const YAML::Node &node, const std::string &name, Eigen::MatrixBase< Derived > &value)
This function reads a vector from a YAML node and converts it into a vector of type Eigen...
static const Eigen::Vector2d kDefaultCSideForceBeta
Definition: fw_parameters.h:47
#define READ_EIGEN_VECTOR(node, item)
Eigen::Vector2d c_yaw_moment_delta_rud
static constexpr double kDefaultAlphaMax
Definition: fw_parameters.h:35
static const Eigen::Vector2d kDefaultCRollMomentDeltaAil
Definition: fw_parameters.h:63
static const Eigen::Vector3d kDefaultCDragAlpha
Definition: fw_parameters.h:38
Eigen::Vector2d c_pitch_moment_alpha
static const Eigen::Vector2d kDefaultCRollMomentR
Definition: fw_parameters.h:61
ControlSurface(int cs_channel, double defl_min=kDefaultControlSurfaceDeflectionMin, double defl_max=kDefaultControlSurfaceDeflectionMax)
static const Eigen::Vector3d kDefaultCDragDeltaFlp
Definition: fw_parameters.h:44
static const Eigen::Vector2d kDefaultCYawMomentBeta
Definition: fw_parameters.h:75


rotors_gazebo_plugins
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:39:03