| 1 | // flight.hxx -- define shared flight model parameters |
| 2 | // |
| 3 | // Written by Curtis Olson, started May 1997. |
| 4 | // |
| 5 | // SPDX-FileCopyrightText: (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt |
| 6 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | /* Required get_() |
| 11 | |
| 12 | `FGInterface::get_Longitude ()' |
| 13 | `FGInterface::get_Latitude ()' |
| 14 | `FGInterface::get_Altitude ()' |
| 15 | `FGInterface::get_Phi ()' |
| 16 | `FGInterface::get_Theta ()' |
| 17 | `FGInterface::get_Psi ()' |
| 18 | `FGInterface::get_V_equiv_kts ()' |
| 19 | |
| 20 | `FGInterface::get_V_north ()' |
| 21 | `FGInterface::get_V_east ()' |
| 22 | `FGInterface::get_V_down ()' |
| 23 | |
| 24 | `FGInterface::get_P_Body ()' |
| 25 | `FGInterface::get_Q_Body ()' |
| 26 | `FGInterface::get_R_Body ()' |
| 27 | |
| 28 | `FGInterface::get_Gamma_vert_rad ()' |
| 29 | `FGInterface::get_Climb_Rate ()' |
| 30 | `FGInterface::get_Alpha ()' |
| 31 | `FGInterface::get_Beta ()' |
| 32 | |
| 33 | `FGInterface::get_Runway_altitude ()' |
| 34 | |
| 35 | `FGInterface::get_Lon_geocentric ()' |
| 36 | `FGInterface::get_Lat_geocentric ()' |
| 37 | `FGInterface::get_Sea_level_radius ()' |
| 38 | `FGInterface::get_Earth_position_angle ()' |
| 39 | |
| 40 | `FGInterface::get_Latitude_dot()' |
| 41 | `FGInterface::get_Longitude_dot()' |
| 42 | `FGInterface::get_Radius_dot()' |
| 43 | |
| 44 | `FGInterface::get_Dx_cg ()' |
| 45 | `FGInterface::get_Dy_cg ()' |
| 46 | `FGInterface::get_Dz_cg ()' |
| 47 | |
| 48 | `FGInterface::get_Radius_to_vehicle ()' |
| 49 | |
| 50 | */ |
| 51 | |
| 52 | |
| 53 | #include <cmath> |
| 54 | #include <functional> |
| 55 | |
| 56 | #include <FDM/AIWake/AIWakeGroup.hxx> |
| 57 | #include <FDM/groundcache.hxx> |
| 58 | #include <FDM/groundreactions.hxx> |
| 59 | #include <simgear/compiler.h> |
| 60 | #include <simgear/constants.h> |
| 61 | #include <simgear/props/tiedpropertylist.hxx> |
| 62 | #include <simgear/structure/subsystem_mgr.hxx> |
| 63 | |
| 64 | namespace simgear { |
| 65 | class BVHMaterial; |
| 66 | } |
| 67 | |
| 68 | class SGIOChannel; |
| 69 | class FGAIAircraft; |
| 70 | |
| 71 | |
| 72 | // This is based heavily on LaRCsim/ls_generic.h |
| 73 | class FGInterface : public SGSubsystem |
| 74 | { |
| 75 | private: |
| 76 | // Has the init() method been called. This is used to delay |
| 77 | // initialization until scenery can be loaded and we know the true |
| 78 | // ground elevation. |
| 79 | bool inited = false; |
| 80 | |
| 81 | // Have we bound to the property system |
| 82 | bool bound = false; |
| 83 | |
| 84 | // periodic update management variable. This is a scheme to run |
| 85 | // the fdm with a fixed delta-t. We control how many iteration of |
| 86 | // the fdm to run with the fixed dt based on the elapsed time from |
| 87 | // the last update. This allows us to maintain sync with the real |
| 88 | // time clock, even though each frame could take a random amount |
| 89 | // of time. Since "dt" is unlikely to divide evenly into the |
| 90 | // elapse time, we keep track of the remainder and add it into the |
| 91 | // next elapsed time. This yields a small amount of temporal |
| 92 | // jitter ( < dt ) but in practice seems to work well. |
| 93 | |
| 94 | /** |
| 95 | * encapsulate primary flight state. This is packaged so it can be |
| 96 | * (unfortunately) sent directly over the wire by the 'native' FDM |
| 97 | * protocol. |
| 98 | */ |
| 99 | struct FlightState { |
| 100 | // CG position w.r.t. ref. point |
| 101 | SGVec3d d_cg_rp_body_v; |
| 102 | |
| 103 | // Accelerations |
| 104 | SGVec3d v_dot_local_v; |
| 105 | SGVec3d v_dot_body_v; |
| 106 | SGVec3d a_cg_body_v; |
| 107 | SGVec3d a_pilot_body_v; |
| 108 | SGVec3d n_cg_body_v; |
| 109 | SGVec3d omega_dot_body_v; |
| 110 | |
| 111 | // Velocities |
| 112 | SGVec3d v_local_v; |
| 113 | SGVec3d v_local_rel_ground_v; // V rel w.r.t. earth surface |
| 114 | SGVec3d v_local_airmass_v; // velocity of airmass (steady winds) |
| 115 | SGVec3d v_body_v; // ECEF velocities in body axis |
| 116 | |
| 117 | SGVec3d omega_body_v; // Angular B rates |
| 118 | SGVec3d euler_rates_v; |
| 119 | SGVec3d geocentric_rates_v; // Geocentric linear velocities |
| 120 | |
| 121 | // Positions |
| 122 | SGGeod geodetic_position_v; |
| 123 | SGVec3d cartesian_position_v; |
| 124 | SGGeoc geocentric_position_v; |
| 125 | SGVec3d euler_angles_v; |
| 126 | |
| 127 | // Normal Load Factor |
| 128 | double nlf; |
| 129 | |
| 130 | // Velocities |
| 131 | double v_rel_wind, v_true_kts; |
| 132 | double v_ground_speed, v_equiv_kts; |
| 133 | double v_calibrated_kts; |
| 134 | |
| 135 | // Miscellaneious Quantities |
| 136 | double alpha, beta; // in radians |
| 137 | double gamma_vert_rad; // Flight path angles |
| 138 | double density, mach_number; |
| 139 | double static_pressure, total_pressure; |
| 140 | double dynamic_pressure; |
| 141 | double static_temperature, total_temperature; |
| 142 | double sea_level_radius, earth_position_angle; |
| 143 | double runway_altitude; |
| 144 | double climb_rate; // in feet per second |
| 145 | double altitude_agl; |
| 146 | double track; |
| 147 | double path; |
| 148 | }; |
| 149 | |
| 150 | FlightState _state; |
| 151 | |
| 152 | simgear::TiedPropertyList _tiedProperties; |
| 153 | |
| 154 | // the ground cache object itself. |
| 155 | FGGroundCache ground_cache; |
| 156 | |
| 157 | GroundReactions _groundReactions; |
| 158 | AIWakeGroup wake_group; |
| 159 | |
| 160 | void set_A_X_pilot(double x) |
| 161 | { |
| 162 | _set_Accels_Pilot_Body(x, _state.a_pilot_body_v[1], _state.a_pilot_body_v[2]); |
| 163 | } |
| 164 | |
| 165 | void set_A_Y_pilot(double y) |
| 166 | { |
| 167 | _set_Accels_Pilot_Body(_state.a_pilot_body_v[0], y, _state.a_pilot_body_v[2]); |
| 168 | } |
| 169 | |
| 170 | void set_A_Z_pilot(double z) |
| 171 | { |
| 172 | _set_Accels_Pilot_Body(_state.a_pilot_body_v[0], _state.a_pilot_body_v[1], z); |
| 173 | } |
| 174 | |
| 175 | protected: |
| 176 | int _calc_multiloop(double dt); |
| 177 | |
| 178 | |
| 179 | // deliberately not virtual so that |
| 180 | // FGInterface constructor will call |
| 181 | // the right version |
| 182 | void _setup(); |
| 183 | |
| 184 | void _busdump(void); |
| 185 | void _updatePositionM(const SGVec3d& cartPos); |
| 186 | void _updatePositionFt(const SGVec3d& cartPos) |
| 187 | { |
| 188 | _updatePositionM(SG_FEET_TO_METER * cartPos); |
| 189 | } |
| 190 | void _updatePosition(const SGGeod& geod); |
| 191 | void _updatePosition(const SGGeoc& geoc); |
| 192 | |
| 193 | void _updateGeodeticPosition(double lat, double lon, double alt); |
| 194 | void _updateGeocentricPosition(double lat_geoc, double lon, double alt); |
| 195 | void _update_ground_elev_at_pos(void); |
| 196 | |
| 197 | inline void _set_CG_Position(double dx, double dy, double dz) |
| 198 | { |
| 199 | _state.d_cg_rp_body_v[0] = dx; |
| 200 | _state.d_cg_rp_body_v[1] = dy; |
| 201 | _state.d_cg_rp_body_v[2] = dz; |
| 202 | } |
| 203 | inline void _set_Accels_Local(double north, double east, double down) |
| 204 | { |
| 205 | _state.v_dot_local_v[0] = north; |
| 206 | _state.v_dot_local_v[1] = east; |
| 207 | _state.v_dot_local_v[2] = down; |
| 208 | } |
| 209 | inline void _set_Accels_Body(double u, double v, double w) |
| 210 | { |
| 211 | _state.v_dot_body_v[0] = u; |
| 212 | _state.v_dot_body_v[1] = v; |
| 213 | _state.v_dot_body_v[2] = w; |
| 214 | } |
| 215 | inline void _set_Accels_CG_Body(double x, double y, double z) |
| 216 | { |
| 217 | _state.a_cg_body_v[0] = x; |
| 218 | _state.a_cg_body_v[1] = y; |
| 219 | _state.a_cg_body_v[2] = z; |
| 220 | } |
| 221 | inline void _set_Accels_Pilot_Body(double x, double y, double z) |
| 222 | { |
| 223 | _state.a_pilot_body_v[0] = x; |
| 224 | _state.a_pilot_body_v[1] = y; |
| 225 | _state.a_pilot_body_v[2] = z; |
| 226 | } |
| 227 | inline void _set_Accels_CG_Body_N(double x, double y, double z) |
| 228 | { |
| 229 | _state.n_cg_body_v[0] = x; |
| 230 | _state.n_cg_body_v[1] = y; |
| 231 | _state.n_cg_body_v[2] = z; |
| 232 | } |
| 233 | void _set_Nlf(double n) { _state.nlf = n; } |
| 234 | inline void _set_Velocities_Local(double north, double east, double down) |
| 235 | { |
| 236 | _state.v_local_v[0] = north; |
| 237 | _state.v_local_v[1] = east; |
| 238 | _state.v_local_v[2] = down; |
| 239 | } |
| 240 | inline void _set_Velocities_Ground(double north, double east, double down) |
| 241 | { |
| 242 | _state.v_local_rel_ground_v[0] = north; |
| 243 | _state.v_local_rel_ground_v[1] = east; |
| 244 | _state.v_local_rel_ground_v[2] = down; |
| 245 | } |
| 246 | inline void _set_Velocities_Local_Airmass(double north, double east, |
| 247 | double down) |
| 248 | { |
| 249 | _state.v_local_airmass_v[0] = north; |
| 250 | _state.v_local_airmass_v[1] = east; |
| 251 | _state.v_local_airmass_v[2] = down; |
| 252 | } |
| 253 | inline void _set_Velocities_Body(double u, double v, double w) |
| 254 | { |
| 255 | _state.v_body_v[0] = u; |
| 256 | _state.v_body_v[1] = v; |
| 257 | _state.v_body_v[2] = w; |
| 258 | } |
| 259 | inline void _set_V_rel_wind(double vt) { _state.v_rel_wind = vt; } |
| 260 | inline void _set_V_ground_speed(double v) { _state.v_ground_speed = v; } |
| 261 | inline void _set_V_equiv_kts(double kts) { _state.v_equiv_kts = kts; } |
| 262 | inline void _set_V_calibrated_kts(double kts) { _state.v_calibrated_kts = kts; } |
| 263 | inline void _set_Omega_Body(double p, double q, double r) |
| 264 | { |
| 265 | _state.omega_body_v[0] = p; |
| 266 | _state.omega_body_v[1] = q; |
| 267 | _state.omega_body_v[2] = r; |
| 268 | } |
| 269 | inline void _set_Euler_Rates(double phi, double theta, double psi) |
| 270 | { |
| 271 | _state.euler_rates_v[0] = phi; |
| 272 | _state.euler_rates_v[1] = theta; |
| 273 | _state.euler_rates_v[2] = psi; |
| 274 | } |
| 275 | |
| 276 | void set_Phi_dot_degps(double x) |
| 277 | { |
| 278 | _state.euler_rates_v[0] = x * SGD_DEGREES_TO_RADIANS; |
| 279 | } |
| 280 | |
| 281 | void set_Theta_dot_degps(double x) |
| 282 | { |
| 283 | _state.euler_rates_v[1] = x * SGD_DEGREES_TO_RADIANS; |
| 284 | } |
| 285 | |
| 286 | void set_Psi_dot_degps(double x) |
| 287 | { |
| 288 | _state.euler_rates_v[2] = x * SGD_DEGREES_TO_RADIANS; |
| 289 | } |
| 290 | |
| 291 | inline void _set_Geocentric_Rates(double lat, double lon, double rad) |
| 292 | { |
| 293 | _state.geocentric_rates_v[0] = lat; |
| 294 | _state.geocentric_rates_v[1] = lon; |
| 295 | _state.geocentric_rates_v[2] = rad; |
| 296 | } |
| 297 | inline void _set_Geocentric_Position(double lat, double lon, double rad) |
| 298 | { |
| 299 | _state.geocentric_position_v.setLatitudeRad(lat); |
| 300 | _state.geocentric_position_v.setLongitudeRad(lon); |
| 301 | _state.geocentric_position_v.setRadiusFt(rad); |
| 302 | } |
| 303 | /* Don't call _set_L[at|ong]itude() directly, use _set_Geodetic_Position() instead. |
| 304 | These methods can't update the track. |
| 305 | * |
| 306 | inline void _set_Latitude(double lat) { |
| 307 | geodetic_position_v.setLatitudeRad(lat); |
| 308 | } |
| 309 | inline void _set_Longitude(double lon) { |
| 310 | geodetic_position_v.setLongitudeRad(lon); |
| 311 | } |
| 312 | */ |
| 313 | inline void _set_Altitude(double altitude) |
| 314 | { |
| 315 | _state.geodetic_position_v.setElevationFt(altitude); |
| 316 | } |
| 317 | inline void _set_Altitude_AGL(double agl) |
| 318 | { |
| 319 | _state.altitude_agl = agl; |
| 320 | } |
| 321 | inline void _set_Geodetic_Position(double lat, double lon) |
| 322 | { |
| 323 | _set_Geodetic_Position(lat, lon, _state.geodetic_position_v.getElevationFt()); |
| 324 | } |
| 325 | void _set_Geodetic_Position(double lat, double lon, double alt); |
| 326 | |
| 327 | void _set_Euler_Angles(double phi, double theta, double psi); |
| 328 | |
| 329 | // FIXME, for compatibility with JSBSim |
| 330 | inline void _set_T_Local_to_Body(int i, int j, double value) {} |
| 331 | inline void _set_Alpha(double a) { _state.alpha = a; } |
| 332 | inline void _set_Beta(double b) { _state.beta = b; } |
| 333 | |
| 334 | inline void set_Alpha_deg(double a) { _state.alpha = a * SGD_DEGREES_TO_RADIANS; } |
| 335 | |
| 336 | inline void _set_Gamma_vert_rad(double gv) { _state.gamma_vert_rad = gv; } |
| 337 | inline void _set_Density(double d) { _state.density = d; } |
| 338 | inline void _set_Mach_number(double m) { _state.mach_number = m; } |
| 339 | inline void _set_Static_pressure(double sp) { _state.static_pressure = sp; } |
| 340 | inline void _set_Static_temperature(double t) { _state.static_temperature = t; } |
| 341 | inline void _set_Total_temperature(double tat) { _state.total_temperature = tat; } //JW |
| 342 | inline void _set_Sea_level_radius(double r) { _state.sea_level_radius = r; } |
| 343 | inline void _set_Earth_position_angle(double a) { _state.earth_position_angle = a; } |
| 344 | inline void _set_Runway_altitude(double alt) { _state.runway_altitude = alt; } |
| 345 | inline void _set_Climb_Rate(double rate) { _state.climb_rate = rate; } |
| 346 | |
| 347 | public: |
| 348 | FGInterface(); |
| 349 | FGInterface(double dt); |
| 350 | virtual ~FGInterface(); |
| 351 | |
| 352 | // Subsystem API. |
| 353 | void bind() override; |
| 354 | void init() override; |
| 355 | void unbind() override; |
| 356 | void update(double dt) override; |
| 357 | |
| 358 | virtual bool ToggleDataLogging(bool state) { return false; } |
| 359 | virtual bool ToggleDataLogging(void) { return false; } |
| 360 | |
| 361 | bool readState(SGIOChannel* io); |
| 362 | bool writeState(SGIOChannel* io); |
| 363 | |
| 364 | // Define the various supported flight models (many not yet implemented) |
| 365 | enum { |
| 366 | // Magic Carpet mode |
| 367 | FG_MAGICCARPET = 0, |
| 368 | |
| 369 | // The NASA LaRCsim (Navion) flight model |
| 370 | FG_LARCSIM = 1, |
| 371 | |
| 372 | // Jon S. Berndt's new FDM written from the ground up in C++ |
| 373 | FG_JSBSIM = 2, |
| 374 | |
| 375 | // Christian's hot air balloon simulation |
| 376 | FG_BALLOONSIM = 3, |
| 377 | |
| 378 | // Aeronautical DEvelopment AGEncy, Bangalore India |
| 379 | FG_ADA = 4, |
| 380 | |
| 381 | // The following aren't implemented but are here to spark |
| 382 | // thoughts and discussions, and maybe even action. |
| 383 | FG_ACM = 5, |
| 384 | FG_SUPER_SONIC = 6, |
| 385 | FG_HELICOPTER = 7, |
| 386 | FG_AUTOGYRO = 8, |
| 387 | FG_PARACHUTE = 9, |
| 388 | |
| 389 | // Driven externally via a serial port, net, file, etc. |
| 390 | FG_EXTERNAL = 10 |
| 391 | }; |
| 392 | |
| 393 | // initialization |
| 394 | inline bool get_inited() const { return inited; } |
| 395 | inline void set_inited(bool value) { inited = value; } |
| 396 | |
| 397 | inline bool get_bound() const { return bound; } |
| 398 | |
| 399 | //perform initializion that is common to all FDM's |
| 400 | void common_init(); |
| 401 | |
| 402 | // Makes possibly multiple calls of fn() with pairs of property paths that |
| 403 | // are associated in the FDM. Default implementation does nothing. Used by |
| 404 | // the Highlight subsystem. |
| 405 | virtual void property_associations( |
| 406 | std::function<void(const std::string& from, const std::string& to)> fn); |
| 407 | |
| 408 | // Positions |
| 409 | virtual void set_Latitude(double lat); // geocentric |
| 410 | virtual void set_Longitude(double lon); |
| 411 | virtual void set_Altitude(double alt); // triggers re-calc of AGL altitude |
| 412 | virtual void set_AltitudeAGL(double altagl); // and vice-versa |
| 413 | virtual void set_Latitude_deg(double lat) |
| 414 | { |
| 415 | set_Latitude(lat * SGD_DEGREES_TO_RADIANS); |
| 416 | } |
| 417 | virtual void set_Longitude_deg(double lon) |
| 418 | { |
| 419 | set_Longitude(lon * SGD_DEGREES_TO_RADIANS); |
| 420 | } |
| 421 | |
| 422 | // Speeds -- setting any of these will trigger a re-calc of the rest |
| 423 | virtual void set_V_calibrated_kts(double vc); |
| 424 | virtual void set_Mach_number(double mach); |
| 425 | virtual void set_Velocities_Local(double north, double east, double down); |
| 426 | inline void set_V_north(double north) |
| 427 | { |
| 428 | set_Velocities_Local(north, _state.v_local_v[1], _state.v_local_v[2]); |
| 429 | } |
| 430 | inline void set_V_east(double east) |
| 431 | { |
| 432 | set_Velocities_Local(_state.v_local_v[0], east, _state.v_local_v[2]); |
| 433 | } |
| 434 | inline void set_V_down(double down) |
| 435 | { |
| 436 | set_Velocities_Local(_state.v_local_v[0], _state.v_local_v[1], down); |
| 437 | } |
| 438 | virtual void set_Velocities_Body(double u, double v, double w); |
| 439 | virtual void set_uBody(double uBody) |
| 440 | { |
| 441 | set_Velocities_Body(uBody, _state.v_body_v[1], _state.v_body_v[2]); |
| 442 | } |
| 443 | virtual void set_vBody(double vBody) |
| 444 | { |
| 445 | set_Velocities_Body(_state.v_body_v[0], vBody, _state.v_body_v[2]); |
| 446 | } |
| 447 | virtual void set_wBody(double wBody) |
| 448 | { |
| 449 | set_Velocities_Body(_state.v_body_v[0], _state.v_body_v[1], wBody); |
| 450 | } |
| 451 | |
| 452 | // Euler angles |
| 453 | virtual void set_Euler_Angles(double phi, double theta, double psi); |
| 454 | virtual void set_Phi(double phi) |
| 455 | { |
| 456 | set_Euler_Angles(phi, get_Theta(), get_Psi()); |
| 457 | } |
| 458 | virtual void set_Theta(double theta) |
| 459 | { |
| 460 | set_Euler_Angles(get_Phi(), theta, get_Psi()); |
| 461 | } |
| 462 | virtual void set_Psi(double psi) |
| 463 | { |
| 464 | set_Euler_Angles(get_Phi(), get_Theta(), psi); |
| 465 | } |
| 466 | virtual void set_Phi_deg(double phi) |
| 467 | { |
| 468 | set_Phi(phi * SGD_DEGREES_TO_RADIANS); |
| 469 | } |
| 470 | virtual void set_Theta_deg(double theta) |
| 471 | { |
| 472 | set_Theta(theta * SGD_DEGREES_TO_RADIANS); |
| 473 | } |
| 474 | virtual void set_Psi_deg(double psi) |
| 475 | { |
| 476 | set_Psi(psi * SGD_DEGREES_TO_RADIANS); |
| 477 | } |
| 478 | |
| 479 | // Flight Path |
| 480 | virtual void set_Climb_Rate(double roc); |
| 481 | virtual void set_Gamma_vert_rad(double gamma); |
| 482 | |
| 483 | // Earth |
| 484 | |
| 485 | virtual void set_Static_pressure(double p); |
| 486 | virtual void set_Static_temperature(double T); |
| 487 | virtual void set_Density(double rho); |
| 488 | |
| 489 | virtual void set_Velocities_Local_Airmass(double wnorth, |
| 490 | double weast, |
| 491 | double wdown); |
| 492 | |
| 493 | // ========== Mass properties and geometry values ========== |
| 494 | |
| 495 | // CG position w.r.t. ref. point |
| 496 | inline double get_Dx_cg() const { return _state.d_cg_rp_body_v[0]; } |
| 497 | inline double get_Dy_cg() const { return _state.d_cg_rp_body_v[1]; } |
| 498 | inline double get_Dz_cg() const { return _state.d_cg_rp_body_v[2]; } |
| 499 | |
| 500 | // ========== Accelerations ========== |
| 501 | |
| 502 | inline double get_V_dot_north() const { return _state.v_dot_local_v[0]; } |
| 503 | inline double get_V_dot_east() const { return _state.v_dot_local_v[1]; } |
| 504 | inline double get_V_dot_down() const { return _state.v_dot_local_v[2]; } |
| 505 | |
| 506 | inline double get_U_dot_body() const { return _state.v_dot_body_v[0]; } |
| 507 | inline double get_V_dot_body() const { return _state.v_dot_body_v[1]; } |
| 508 | inline double get_W_dot_body() const { return _state.v_dot_body_v[2]; } |
| 509 | |
| 510 | inline double get_A_X_cg() const { return _state.a_cg_body_v[0]; } |
| 511 | inline double get_A_Y_cg() const { return _state.a_cg_body_v[1]; } |
| 512 | inline double get_A_Z_cg() const { return _state.a_cg_body_v[2]; } |
| 513 | |
| 514 | inline double get_A_X_pilot() const { return _state.a_pilot_body_v[0]; } |
| 515 | inline double get_A_Y_pilot() const { return _state.a_pilot_body_v[1]; } |
| 516 | inline double get_A_Z_pilot() const { return _state.a_pilot_body_v[2]; } |
| 517 | |
| 518 | inline double get_N_X_cg() const { return _state.n_cg_body_v[0]; } |
| 519 | inline double get_N_Y_cg() const { return _state.n_cg_body_v[1]; } |
| 520 | inline double get_N_Z_cg() const { return _state.n_cg_body_v[2]; } |
| 521 | |
| 522 | inline double get_Nlf(void) const { return _state.nlf; } |
| 523 | |
| 524 | // ========== Velocities ========== |
| 525 | |
| 526 | inline double get_V_north() const { return _state.v_local_v[0]; } |
| 527 | inline double get_V_east() const { return _state.v_local_v[1]; } |
| 528 | inline double get_V_down() const { return _state.v_local_v[2]; } |
| 529 | inline double get_uBody() const { return _state.v_body_v[0]; } |
| 530 | inline double get_vBody() const { return _state.v_body_v[1]; } |
| 531 | inline double get_wBody() const { return _state.v_body_v[2]; } |
| 532 | |
| 533 | // Please dont comment these out. fdm=ada uses these (see |
| 534 | // cockpit.cxx) ---> |
| 535 | inline double get_V_north_rel_ground() const |
| 536 | { |
| 537 | return _state.v_local_rel_ground_v[0]; |
| 538 | } |
| 539 | inline double get_V_east_rel_ground() const |
| 540 | { |
| 541 | return _state.v_local_rel_ground_v[1]; |
| 542 | } |
| 543 | inline double get_V_down_rel_ground() const |
| 544 | { |
| 545 | return _state.v_local_rel_ground_v[2]; |
| 546 | } |
| 547 | // <--- fdm=ada uses these (see cockpit.cxx) |
| 548 | |
| 549 | inline double get_V_north_airmass() const { return _state.v_local_airmass_v[0]; } |
| 550 | inline double get_V_east_airmass() const { return _state.v_local_airmass_v[1]; } |
| 551 | inline double get_V_down_airmass() const { return _state.v_local_airmass_v[2]; } |
| 552 | |
| 553 | inline double get_U_body() const { return _state.v_body_v[0]; } |
| 554 | inline double get_V_body() const { return _state.v_body_v[1]; } |
| 555 | inline double get_W_body() const { return _state.v_body_v[2]; } |
| 556 | |
| 557 | inline double get_V_rel_wind() const { return _state.v_rel_wind; } |
| 558 | |
| 559 | inline double get_V_true_kts() const { return _state.v_true_kts; } |
| 560 | |
| 561 | inline double get_V_ground_speed() const { return _state.v_ground_speed; } |
| 562 | inline double get_V_ground_speed_kt() const { return _state.v_ground_speed * SG_FEET_TO_METER * 3600 * SG_METER_TO_NM; } |
| 563 | inline void set_V_ground_speed_kt(double ground_speed) { _state.v_ground_speed = ground_speed / (SG_FEET_TO_METER * 3600 * SG_METER_TO_NM); } |
| 564 | |
| 565 | inline double get_V_equiv_kts() const { return _state.v_equiv_kts; } |
| 566 | |
| 567 | inline double get_V_calibrated_kts() const { return _state.v_calibrated_kts; } |
| 568 | |
| 569 | inline double get_P_body() const { return _state.omega_body_v[0]; } |
| 570 | inline double get_Q_body() const { return _state.omega_body_v[1]; } |
| 571 | inline double get_R_body() const { return _state.omega_body_v[2]; } |
| 572 | |
| 573 | inline double get_Phi_dot() const { return _state.euler_rates_v[0]; } |
| 574 | inline double get_Theta_dot() const { return _state.euler_rates_v[1]; } |
| 575 | inline double get_Psi_dot() const { return _state.euler_rates_v[2]; } |
| 576 | inline double get_Phi_dot_degps() const { return _state.euler_rates_v[0] * SGD_RADIANS_TO_DEGREES; } |
| 577 | inline double get_Theta_dot_degps() const { return _state.euler_rates_v[1] * SGD_RADIANS_TO_DEGREES; } |
| 578 | inline double get_Psi_dot_degps() const { return _state.euler_rates_v[2] * SGD_RADIANS_TO_DEGREES; } |
| 579 | |
| 580 | inline double get_Latitude_dot() const { return _state.geocentric_rates_v[0]; } |
| 581 | inline double get_Longitude_dot() const { return _state.geocentric_rates_v[1]; } |
| 582 | inline double get_Radius_dot() const { return _state.geocentric_rates_v[2]; } |
| 583 | |
| 584 | // ========== Positions ========== |
| 585 | |
| 586 | inline double get_Lat_geocentric() const |
| 587 | { |
| 588 | return _state.geocentric_position_v.getLatitudeRad(); |
| 589 | } |
| 590 | inline double get_Lon_geocentric() const |
| 591 | { |
| 592 | return _state.geocentric_position_v.getLongitudeRad(); |
| 593 | } |
| 594 | inline double get_Radius_to_vehicle() const |
| 595 | { |
| 596 | return _state.geocentric_position_v.getRadiusFt(); |
| 597 | } |
| 598 | |
| 599 | const SGGeod& getPosition() const { return _state.geodetic_position_v; } |
| 600 | const SGGeoc& getGeocPosition() const { return _state.geocentric_position_v; } |
| 601 | const SGVec3d& getCartPosition() const { return _state.cartesian_position_v; } |
| 602 | |
| 603 | inline double get_Latitude() const |
| 604 | { |
| 605 | return _state.geodetic_position_v.getLatitudeRad(); |
| 606 | } |
| 607 | inline double get_Longitude() const |
| 608 | { |
| 609 | return _state.geodetic_position_v.getLongitudeRad(); |
| 610 | } |
| 611 | inline double get_Altitude() const |
| 612 | { |
| 613 | return _state.geodetic_position_v.getElevationFt(); |
| 614 | } |
| 615 | inline double get_Altitude_AGL(void) const { return _state.altitude_agl; } |
| 616 | inline double get_Track(void) const { return _state.track; } |
| 617 | inline double get_Path(void) const { return _state.path; } |
| 618 | |
| 619 | inline double get_Latitude_deg() const |
| 620 | { |
| 621 | return _state.geodetic_position_v.getLatitudeDeg(); |
| 622 | } |
| 623 | inline double get_Longitude_deg() const |
| 624 | { |
| 625 | return _state.geodetic_position_v.getLongitudeDeg(); |
| 626 | } |
| 627 | |
| 628 | inline double get_Phi() const { return _state.euler_angles_v[0]; } |
| 629 | inline double get_Theta() const { return _state.euler_angles_v[1]; } |
| 630 | inline double get_Psi() const { return _state.euler_angles_v[2]; } |
| 631 | inline double get_Phi_deg() const { return get_Phi() * SGD_RADIANS_TO_DEGREES; } |
| 632 | inline double get_Theta_deg() const { return get_Theta() * SGD_RADIANS_TO_DEGREES; } |
| 633 | inline double get_Psi_deg() const { return get_Psi() * SGD_RADIANS_TO_DEGREES; } |
| 634 | |
| 635 | |
| 636 | // ========== Miscellaneous quantities ========== |
| 637 | |
| 638 | inline double get_Alpha() const { return _state.alpha; } |
| 639 | inline double get_Alpha_deg() const { return _state.alpha * SGD_RADIANS_TO_DEGREES; } |
| 640 | inline double get_Beta() const { return _state.beta; } |
| 641 | inline double get_Beta_deg() const { return _state.beta * SGD_RADIANS_TO_DEGREES; } |
| 642 | inline double get_Gamma_vert_rad() const { return _state.gamma_vert_rad; } |
| 643 | |
| 644 | inline double get_Density() const { return _state.density; } |
| 645 | inline double get_Mach_number() const { return _state.mach_number; } |
| 646 | |
| 647 | inline double get_Static_pressure() const { return _state.static_pressure; } |
| 648 | inline double get_Total_pressure() const { return _state.total_pressure; } |
| 649 | inline double get_Dynamic_pressure() const { return _state.dynamic_pressure; } |
| 650 | |
| 651 | inline double get_Static_temperature() const { return _state.static_temperature; } |
| 652 | inline double get_Total_temperature() const { return _state.total_temperature; } |
| 653 | |
| 654 | inline double get_Sea_level_radius() const { return _state.sea_level_radius; } |
| 655 | inline double get_Earth_position_angle() const |
| 656 | { |
| 657 | return _state.earth_position_angle; |
| 658 | } |
| 659 | |
| 660 | inline double get_Runway_altitude() const { return _state.runway_altitude; } |
| 661 | inline double get_Runway_altitude_m() const { return SG_FEET_TO_METER * _state.runway_altitude; } |
| 662 | |
| 663 | inline double get_Climb_Rate() const { return _state.climb_rate; } |
| 664 | |
| 665 | // Note that currently this is the "same" value runway altitude... |
| 666 | inline double get_ground_elev_ft() const { return _state.runway_altitude; } |
| 667 | |
| 668 | |
| 669 | ////////////////////////////////////////////////////////////////////////// |
| 670 | // Ground handling routines |
| 671 | ////////////////////////////////////////////////////////////////////////// |
| 672 | |
| 673 | // Prepare the ground cache for the wgs84 position pt_*. |
| 674 | // That is take all vertices in the ball with radius rad around the |
| 675 | // position given by the pt_* and store them in a local scene graph. |
| 676 | bool prepare_ground_cache_m(double startSimTime, double endSimTime, |
| 677 | const double pt[3], double rad); |
| 678 | bool prepare_ground_cache_ft(double startSimTime, double endSimTime, |
| 679 | const double pt[3], double rad); |
| 680 | |
| 681 | |
| 682 | // Returns true if the cache is valid. |
| 683 | // Also the reference time, point and radius values where the cache |
| 684 | // is valid for are returned. |
| 685 | bool is_valid_m(double* ref_time, double pt[3], double* rad); |
| 686 | bool is_valid_ft(double* ref_time, double pt[3], double* rad); |
| 687 | |
| 688 | // Return the nearest catapult to the given point |
| 689 | // pt in wgs84 coordinates. |
| 690 | double get_cat_m(double t, const double pt[3], |
| 691 | double end[2][3], double vel[2][3]); |
| 692 | double get_cat_ft(double t, const double pt[3], |
| 693 | double end[2][3], double vel[2][3]); |
| 694 | |
| 695 | |
| 696 | // Return the orientation and position matrix and the linear and angular |
| 697 | // velocity of that local coordinate systems origin for a given time and |
| 698 | // body id. The velocities are in the wgs84 frame at the bodys origin. |
| 699 | bool get_body_m(double t, simgear::BVHNode::Id id, double bodyToWorld[16], |
| 700 | double linearVel[3], double angularVel[3]); |
| 701 | |
| 702 | |
| 703 | // Return the altitude above ground below the wgs84 point pt |
| 704 | // Search for the nearest triangle to pt in downward direction. |
| 705 | // Return ground properties. The velocities are in the wgs84 frame at the |
| 706 | // contact point. |
| 707 | bool get_agl_m(double t, const double pt[3], double max_altoff, |
| 708 | double contact[3], double normal[3], double linearVel[3], |
| 709 | double angularVel[3], simgear::BVHMaterial const*& material, |
| 710 | simgear::BVHNode::Id& id); |
| 711 | bool get_agl_ft(double t, const double pt[3], double max_altoff, |
| 712 | double contact[3], double normal[3], double linearVel[3], |
| 713 | double angularVel[3], simgear::BVHMaterial const*& material, |
| 714 | simgear::BVHNode::Id& id); |
| 715 | double get_groundlevel_m(double lat, double lon, double alt); |
| 716 | double get_groundlevel_m(const SGGeod& geod); |
| 717 | |
| 718 | |
| 719 | // Return the nearest point in any direction to the point pt with a maximum |
| 720 | // distance maxDist. The velocities are in the wgs84 frame at the query |
| 721 | // position pt. |
| 722 | bool get_nearest_m(double t, const double pt[3], double maxDist, |
| 723 | double contact[3], double normal[3], double linearVel[3], |
| 724 | double angularVel[3], simgear::BVHMaterial const*& material, |
| 725 | simgear::BVHNode::Id& id); |
| 726 | bool get_nearest_ft(double t, const double pt[3], double maxDist, |
| 727 | double contact[3], double normal[3], double linearVel[3], |
| 728 | double angularVel[3], simgear::BVHMaterial const*& material, |
| 729 | simgear::BVHNode::Id& id); |
| 730 | |
| 731 | |
| 732 | // Return 1 if the hook intersects with a wire. |
| 733 | // That test is done by checking if the quad spanned by the points pt* |
| 734 | // intersects with the line representing the wire. |
| 735 | // If the wire is caught, the cache will trace this wires endpoints until |
| 736 | // the FDM calls release_wire(). |
| 737 | bool caught_wire_m(double t, const double pt[4][3]); |
| 738 | bool caught_wire_ft(double t, const double pt[4][3]); |
| 739 | |
| 740 | // Return the location and speed of the wire endpoints. |
| 741 | bool get_wire_ends_m(double t, double end[2][3], double vel[2][3]); |
| 742 | bool get_wire_ends_ft(double t, double end[2][3], double vel[2][3]); |
| 743 | |
| 744 | // Tell the cache code that it does no longer need to care for |
| 745 | // the wire end position. |
| 746 | void release_wire(void); |
| 747 | |
| 748 | // Ground reactions |
| 749 | bool updateGroundReactions(simgear::BVHMaterial const*& material) |
| 750 | { |
| 751 | return _groundReactions.update(material); |
| 752 | } |
| 753 | inline void setHeading(float h) { _groundReactions.setHeading(h); } |
| 754 | inline void setPosition(double pt[3]) |
| 755 | { |
| 756 | _groundReactions.setPosition(pt); |
| 757 | } |
| 758 | inline float getPressure() { return _groundReactions.getPressure(); } |
| 759 | inline float getBumpiness() { return _groundReactions.getBumpiness(); } |
| 760 | inline float getGroundDisplacement() |
| 761 | { |
| 762 | return _groundReactions.getGroundDisplacement(); |
| 763 | } |
| 764 | inline float getStaticFrictionFactor() |
| 765 | { |
| 766 | return _groundReactions.getStaticFrictionFactor(); |
| 767 | } |
| 768 | inline float getRolingFrictionFactor() |
| 769 | { |
| 770 | return _groundReactions.getRolingFrictionFactor(); |
| 771 | } |
| 772 | inline bool getSolid() { return _groundReactions.getSolid(); } |
| 773 | |
| 774 | |
| 775 | // Manages the AI wake computations. |
| 776 | void add_ai_wake(FGAIAircraft* ai) { wake_group.AddAI(ai); } |
| 777 | void reset_wake_group(void) { wake_group.gc(); } |
| 778 | const AIWakeGroup& get_wake_group(void) { return wake_group; } |
| 779 | }; |