Line data Source code
1 : #pragma once 2 : 3 : #include "AP_Generator_config.h" 4 : 5 : #if HAL_GENERATOR_ENABLED 6 : 7 : #include <AP_Param/AP_Param.h> 8 : #include <AP_BattMonitor/AP_BattMonitor.h> 9 : 10 : class AP_Generator_Backend; 11 : class AP_Generator_Cortex; 12 : class AP_Generator_IE_650_800; 13 : class AP_Generator_IE_2400; 14 : class AP_Generator_RichenPower; 15 : 16 : class AP_Generator 17 : { 18 : friend class AP_Generator_Cortex; 19 : friend class AP_Generator_Backend; 20 : friend class AP_Generator_IE_650_800; 21 : friend class AP_Generator_IE_2400; 22 : friend class AP_Generator_RichenPower; 23 : friend class AP_Generator_Loweheiser; 24 : 25 : public: 26 : // Constructor 27 : AP_Generator(); 28 : 29 : // Do not allow copies 30 : CLASS_NO_COPY(AP_Generator); 31 : 32 : static AP_Generator* get_singleton(); 33 : 34 : void init(void); 35 : void update(void); 36 : 37 : bool pre_arm_check(char *failmsg, uint8_t failmsg_len) const; 38 : 39 : AP_BattMonitor::Failsafe update_failsafes(void); 40 : 41 : // Helpers to retrieve measurements 42 11507 : float get_voltage(void) const { return _voltage; } 43 11507 : float get_current(void) const { return _current; } 44 : // get_fuel_remaining returns fuel remaining as a scale 0-1 45 6971 : float get_fuel_remaining(void) const { return _fuel_remaining; } 46 : float get_fuel_remaining_l(void) const { return _fuel_remaining_l; } 47 18889 : float get_batt_consumed(void) const { return _consumed_mah; } 48 0 : uint16_t get_rpm(void) const { return _rpm; } 49 : 50 : // Helpers to see if backend has a measurement 51 52456 : bool has_current() const { return _has_current; } 52 33075 : bool has_consumed_energy() const { return _has_consumed_energy; } 53 38613 : bool has_fuel_remaining() const { return _has_fuel_remaining; } 54 : bool has_fuel_remaining_l() const { return _has_fuel_remaining_l; } 55 : 56 : // method to reset the amount of energy remaining in a generator. 57 : // This typically means someone has refueled the vehicle without 58 : // powering it off, and is indicating that the fuel tank is full. 59 : bool reset_consumed_energy(); 60 : 61 : // healthy() returns true if the generator is not present, or it is 62 : // present, providing telemetry and not indicating any errors. 63 34907 : bool healthy(void) const { return _healthy; } 64 : 65 : // Generator controls must return true if present in generator type 66 : bool stop(void); 67 : bool idle(void); 68 : bool run(void); 69 : 70 : void send_generator_status(const class GCS_MAVLINK &channel); 71 : 72 : #if AP_GENERATOR_LOWEHEISER_ENABLED 73 : // a getter to explicitly get a Loweheiser backend if it exists. 74 : // Used to pass mavlink messages directly to it until we need that 75 : // on the generator interface itself, and for the 76 : // AP_EFI_Loweheiser object to get the generator backend. 77 : class AP_Generator_Loweheiser *get_loweheiser(); 78 : #endif 79 : 80 : // Parameter block 81 : static const struct AP_Param::GroupInfo var_info[]; 82 : static const struct AP_Param::GroupInfo *backend_var_info; 83 : 84 : // bits which can be set in _options to modify generator behaviour: 85 : enum class Option { 86 : INHIBIT_MAINTENANCE_WARNINGS = 0, 87 : }; 88 : 89 917 : bool option_set(Option opt) const { 90 917 : return (_options & 1U<<uint32_t(opt)) != 0; 91 : } 92 : 93 : private: 94 : 95 : // Pointer to chosen driver 96 : AP_Generator_Backend* _driver_ptr; 97 : 98 : // Parameters 99 : AP_Int8 _type; // Select which generator to use 100 : AP_Int32 _options; // Select which generator to use 101 : 102 : enum class Type { 103 : GEN_DISABLED = 0, 104 : #if AP_GENERATOR_IE_650_800_ENABLED 105 : IE_650_800 = 1, 106 : #endif 107 : #if AP_GENERATOR_IE_2400_ENABLED 108 : IE_2400 = 2, 109 : #endif 110 : #if AP_GENERATOR_RICHENPOWER_ENABLED 111 : RICHENPOWER = 3, 112 : #endif 113 : #if AP_GENERATOR_LOWEHEISER_ENABLED 114 : LOWEHEISER = 4, 115 : #endif // AP_GENERATOR_LOWEHEISER_ENABLED 116 : #if AP_GENERATOR_CORTEX_ENABLED 117 : CORTEX = 5, 118 : #endif // AP_GENERATOR_CORTEX_ENABLED 119 : }; 120 : 121 : // Helper to get param and cast to GenType 122 : Type type(void) const; 123 : 124 : // Front end variables 125 : float _voltage; 126 : float _current; 127 : float _fuel_remaining; // 0-1 128 : float _fuel_remaining_l; 129 : bool _has_fuel_remaining; 130 : bool _has_fuel_remaining_l; 131 : float _consumed_mah; 132 : uint16_t _rpm; 133 : bool _healthy; 134 : bool _has_current; 135 : bool _has_consumed_energy; 136 : 137 : static AP_Generator *_singleton; 138 : 139 : }; 140 : 141 : namespace AP { 142 : AP_Generator *generator(); 143 : }; 144 : #endif