| 1 | /* |
| 2 | * SPDX-FileName: heading_indicator_dg.hxx |
| 3 | * SPDX-FileComment: a Directional Gyro (DG) compass. |
| 4 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | * SPDX-FileContributor: Written by Vivian Meazza, started 2005. |
| 6 | * SPDX-FileContributor: Enhanced by Benedikt Hallinger, 2023 |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | |
| 12 | #include <Instrumentation/AbstractInstrument.hxx> |
| 13 | |
| 14 | #include "gyro.hxx" |
| 15 | |
| 16 | |
| 17 | /** |
| 18 | * Model an electrically- or vacuum powered heading indicator. |
| 19 | * |
| 20 | * Input properties: |
| 21 | * |
| 22 | * /instrumentation/"name"/serviceable |
| 23 | * /instrumentation/"name"/spin |
| 24 | * /instrumentation/"name"/offset-deg |
| 25 | * /orientation/heading-deg |
| 26 | * /position/latitude-deg |
| 27 | * /velocities/east-relground-fps |
| 28 | * /systems/electrical/outputs/DG |
| 29 | * /systems/vacuum/suction-inhg (optionally) |
| 30 | * |
| 31 | * Output properties: |
| 32 | * |
| 33 | * /instrumentation/"name"/indicated-heading-deg |
| 34 | * /instrumentation/"name"/drift-per-hour-deg |
| 35 | * /instrumentation/"name"/transport-wander-per-hour-deg |
| 36 | * |
| 37 | * |
| 38 | * Configuration: |
| 39 | * |
| 40 | * name |
| 41 | * number |
| 42 | * new-default-power-path: use /systems/electrical/outputs/"name"[ number ] instead of |
| 43 | * /systems/electrical/outputs/DG as the default power |
| 44 | * supply path (not used when power-supply is set) |
| 45 | * heading-source If given, heading is taken from this node (default: "/orientation/heading-deg") |
| 46 | * power-supply |
| 47 | * minimum-supply-volts |
| 48 | * suction If given, gyro is vacuum driven from the property given |
| 49 | * gyro/spin-up-sec If given, seconds to spin up until power-norm (from 0->100%) |
| 50 | * gyro/spin-down-sec If given, seconds the gyro will loose spin without power (from 100%->0) |
| 51 | * |
| 52 | * These are optional and also configurable at runtime below instruments limits subtree: |
| 53 | * minimum-vacuum Default 5.0 inHG |
| 54 | * gyro/minimum-spin-norm Default 0.9 (0.0 to 1.0) |
| 55 | * limits/yaw-rate-source Default: "/orientation/yaw-rate-degps" |
| 56 | * limits/yaw-error-factor Default 0.033 (set to 0 to disable yaw-error influence) |
| 57 | * limits/yaw-limit-rate Default 5.0 |
| 58 | * limits/g-node Path to g-node; default "/accelerations/pilot-g" |
| 59 | * limits/g-filter-time Default 10.0 (set to 0 to disable); time for g low-pass filter (to filter out spikes due to caluclation artifacts) |
| 60 | * limits/g-error-factor Default 0.033 (set to 0 to disable g-error influence) |
| 61 | * limits/g-limit-lower Default -0.5 |
| 62 | * limits/g-limit-upper Default 1.5 |
| 63 | * limits/g-limit-tumble-factor Default 1.5 (150% above specified g-limits in g-limit-lower/g-limit-upper) |
| 64 | * |
| 65 | * These are just for changing at runtime: |
| 66 | * latitude-nut-setting Default 0° latitude (equator; negative=southern hemisphere), to be set by aircraft code |
| 67 | */ |
| 68 | class HeadingIndicatorDG : public AbstractInstrument |
| 69 | { |
| 70 | public: |
| 71 | HeadingIndicatorDG ( SGPropertyNode *node ); |
| 72 | HeadingIndicatorDG (); |
| 73 | virtual ~HeadingIndicatorDG (); |
| 74 | |
| 75 | // Subsystem API. |
| 76 | void init() override; |
| 77 | void reinit() override; |
| 78 | void update(double dt) override; |
| 79 | |
| 80 | // Subsystem identification. |
| 81 | static const char* staticSubsystemClassId() { return "heading-indicator-dg"; }; |
| 82 | |
| 83 | private: |
| 84 | Gyro _gyro; |
| 85 | double _last_heading_deg, _last_indicated_heading_dg; |
| 86 | |
| 87 | std::string _powerSupplyPath; |
| 88 | std::string _suctionPath; |
| 89 | std::string _gnodePath; |
| 90 | std::string _heading_in_nodePath; |
| 91 | std::string _yaw_rate_nodePath; |
| 92 | bool _vacuumDriven = false; |
| 93 | |
| 94 | SGPropertyNode_ptr _limits_node; |
| 95 | double _minVacuum = 4.0; // inHg |
| 96 | SGPropertyNode_ptr _minVacuum_node; |
| 97 | |
| 98 | double _gyro_lag, _gyro_spin_up, _gyro_spin_down; |
| 99 | double _minSpin, _yaw_error_factor, _g_error_factor, |
| 100 | _yaw_limit_rate, _last_g, _g_filtertime, _g_limit_lower, _g_limit_upper, _g_limit_tumble; |
| 101 | SGPropertyNode_ptr _minSpin_node, _yaw_error_factor_node, _g_error_factor_node, |
| 102 | _yaw_limit_rate_node, _g_limit_lower_node, _g_limit_upper_node; |
| 103 | |
| 104 | SGPropertyNode_ptr _offset_node; |
| 105 | SGPropertyNode_ptr _heading_in_node; |
| 106 | SGPropertyNode_ptr _serviceable_node; |
| 107 | SGPropertyNode_ptr _heading_out_node; |
| 108 | SGPropertyNode_ptr _drift_ph_out_node; |
| 109 | SGPropertyNode_ptr _transp_wander_out_node; |
| 110 | SGPropertyNode_ptr _we_speed_node; |
| 111 | SGPropertyNode_ptr _lat_nut_node; |
| 112 | SGPropertyNode_ptr _caged_node; |
| 113 | SGPropertyNode_ptr _tumble_node, _tumble_flag_node, _g_limit_tumble_node; |
| 114 | SGPropertyNode_ptr _electrical_node; |
| 115 | SGPropertyNode_ptr _error_node; |
| 116 | SGPropertyNode_ptr _nav1_error_node; |
| 117 | SGPropertyNode_ptr _align_node; |
| 118 | SGPropertyNode_ptr _yaw_rate_node; |
| 119 | SGPropertyNode_ptr _heading_bug_error_node; |
| 120 | SGPropertyNode_ptr _g_node, _g_filtertime_node; |
| 121 | SGPropertyNode_ptr _spin_node, _gyro_spin_up_node, _gyro_spin_down_node; |
| 122 | SGPropertyNode_ptr _suction_node; |
| 123 | }; |