mirror of https://github.com/ArduPilot/ardupilot
AP_BattMonitor: move battery type enumeration out of parameters object
This commit is contained in:
parent
76e5ae9b41
commit
2e3ba2a4d2
|
@ -104,7 +104,7 @@ AP_BattMonitor::init()
|
|||
#ifdef HAL_BATT_MONITOR_DEFAULT
|
||||
if (_params[0]._type == 0) {
|
||||
// we can't use set_default() as the type is used as a flag for parameter conversion
|
||||
_params[0]._type.set((AP_BattMonitor_Params::BattMonitor_Type)HAL_BATT_MONITOR_DEFAULT);
|
||||
_params[0]._type.set(int8_t(HAL_BATT_MONITOR_DEFAULT));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -114,78 +114,78 @@ AP_BattMonitor::init()
|
|||
memset(&state[instance].cell_voltages, 0xFF, sizeof(cells));
|
||||
|
||||
switch (get_type(instance)) {
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_ANALOG_VOLTAGE_ONLY:
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_ANALOG_VOLTAGE_AND_CURRENT:
|
||||
case Type::ANALOG_VOLTAGE_ONLY:
|
||||
case Type::ANALOG_VOLTAGE_AND_CURRENT:
|
||||
drivers[instance] = new AP_BattMonitor_Analog(*this, state[instance], _params[instance]);
|
||||
break;
|
||||
#if HAL_BATTMON_SMBUS_ENABLE
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_SOLO:
|
||||
case Type::SOLO:
|
||||
_params[instance]._i2c_bus.set_default(AP_BATTMONITOR_SMBUS_BUS_INTERNAL);
|
||||
drivers[instance] = new AP_BattMonitor_SMBus_Solo(*this, state[instance], _params[instance],
|
||||
hal.i2c_mgr->get_device(_params[instance]._i2c_bus, AP_BATTMONITOR_SMBUS_I2C_ADDR,
|
||||
100000, true, 20));
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_SMBus_Generic:
|
||||
case Type::SMBus_Generic:
|
||||
_params[instance]._i2c_bus.set_default(AP_BATTMONITOR_SMBUS_BUS_EXTERNAL);
|
||||
drivers[instance] = new AP_BattMonitor_SMBus_Generic(*this, state[instance], _params[instance],
|
||||
hal.i2c_mgr->get_device(_params[instance]._i2c_bus, AP_BATTMONITOR_SMBUS_I2C_ADDR,
|
||||
100000, true, 20));
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_SUI3:
|
||||
case Type::SUI3:
|
||||
_params[instance]._i2c_bus.set_default(AP_BATTMONITOR_SMBUS_BUS_INTERNAL),
|
||||
drivers[instance] = new AP_BattMonitor_SMBus_SUI(*this, state[instance], _params[instance],
|
||||
hal.i2c_mgr->get_device(_params[instance]._i2c_bus, AP_BATTMONITOR_SMBUS_I2C_ADDR,
|
||||
100000, true, 20), 3);
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_SUI6:
|
||||
case Type::SUI6:
|
||||
_params[instance]._i2c_bus.set_default(AP_BATTMONITOR_SMBUS_BUS_INTERNAL),
|
||||
drivers[instance] = new AP_BattMonitor_SMBus_SUI(*this, state[instance], _params[instance],
|
||||
hal.i2c_mgr->get_device(_params[instance]._i2c_bus, AP_BATTMONITOR_SMBUS_I2C_ADDR,
|
||||
100000, true, 20), 6);
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_MAXELL:
|
||||
case Type::MAXELL:
|
||||
_params[instance]._i2c_bus.set_default(AP_BATTMONITOR_SMBUS_BUS_EXTERNAL);
|
||||
drivers[instance] = new AP_BattMonitor_SMBus_Maxell(*this, state[instance], _params[instance],
|
||||
hal.i2c_mgr->get_device(_params[instance]._i2c_bus, AP_BATTMONITOR_SMBUS_I2C_ADDR,
|
||||
100000, true, 20));
|
||||
break;
|
||||
#endif // HAL_BATTMON_SMBUS_ENABLE
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_BEBOP:
|
||||
case Type::BEBOP:
|
||||
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
|
||||
drivers[instance] = new AP_BattMonitor_Bebop(*this, state[instance], _params[instance]);
|
||||
#endif
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_UAVCAN_BatteryInfo:
|
||||
case Type::UAVCAN_BatteryInfo:
|
||||
#if HAL_WITH_UAVCAN
|
||||
drivers[instance] = new AP_BattMonitor_UAVCAN(*this, state[instance], AP_BattMonitor_UAVCAN::UAVCAN_BATTERY_INFO, _params[instance]);
|
||||
#endif
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_BLHeliESC:
|
||||
case Type::BLHeliESC:
|
||||
#ifdef HAVE_AP_BLHELI_SUPPORT
|
||||
drivers[instance] = new AP_BattMonitor_BLHeliESC(*this, state[instance], _params[instance]);
|
||||
#endif
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_Sum:
|
||||
case Type::Sum:
|
||||
drivers[instance] = new AP_BattMonitor_Sum(*this, state[instance], _params[instance], instance);
|
||||
break;
|
||||
#if HAL_BATTMON_FUEL_ENABLE
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_FuelFlow:
|
||||
case Type::FuelFlow:
|
||||
drivers[instance] = new AP_BattMonitor_FuelFlow(*this, state[instance], _params[instance]);
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_FuelLevel_PWM:
|
||||
case Type::FuelLevel_PWM:
|
||||
drivers[instance] = new AP_BattMonitor_FuelLevel_PWM(*this, state[instance], _params[instance]);
|
||||
break;
|
||||
#endif // HAL_BATTMON_FUEL_ENABLE
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_NeoDesign:
|
||||
case Type::NeoDesign:
|
||||
_params[instance]._i2c_bus.set_default(AP_BATTMONITOR_SMBUS_BUS_INTERNAL),
|
||||
drivers[instance] = new AP_BattMonitor_SMBus_NeoDesign(*this, state[instance], _params[instance],
|
||||
hal.i2c_mgr->get_device(_params[instance]._i2c_bus, AP_BATTMONITOR_SMBUS_I2C_ADDR,
|
||||
100000, true, 20));
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_Generator:
|
||||
case Type::Generator:
|
||||
drivers[instance] = new AP_BattMonitor_Generator(*this, state[instance], _params[instance]);
|
||||
break;
|
||||
case AP_BattMonitor_Params::BattMonitor_TYPE_NONE:
|
||||
case Type::NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ void
|
|||
AP_BattMonitor::read()
|
||||
{
|
||||
for (uint8_t i=0; i<_num_instances; i++) {
|
||||
if (drivers[i] != nullptr && _params[i].type() != AP_BattMonitor_Params::BattMonitor_TYPE_NONE) {
|
||||
if (drivers[i] != nullptr && get_type(i) != Type::NONE) {
|
||||
drivers[i]->read();
|
||||
drivers[i]->update_resistance_estimate();
|
||||
}
|
||||
|
|
|
@ -62,6 +62,26 @@ public:
|
|||
BatteryFailsafe_Critical
|
||||
};
|
||||
|
||||
// Battery monitor driver types
|
||||
enum class Type {
|
||||
NONE = 0,
|
||||
ANALOG_VOLTAGE_ONLY = 3,
|
||||
ANALOG_VOLTAGE_AND_CURRENT = 4,
|
||||
SOLO = 5,
|
||||
BEBOP = 6,
|
||||
SMBus_Generic = 7,
|
||||
UAVCAN_BatteryInfo = 8,
|
||||
BLHeliESC = 9,
|
||||
Sum = 10,
|
||||
FuelFlow = 11,
|
||||
FuelLevel_PWM = 12,
|
||||
SUI3 = 13,
|
||||
SUI6 = 14,
|
||||
NeoDesign = 15,
|
||||
MAXELL = 16,
|
||||
Generator = 17,
|
||||
};
|
||||
|
||||
FUNCTOR_TYPEDEF(battery_failsafe_handler_fn_t, void, const char *, const int8_t);
|
||||
|
||||
AP_BattMonitor(uint32_t log_battery_bit, battery_failsafe_handler_fn_t battery_failsafe_handler_fn, const int8_t *failsafe_priorities);
|
||||
|
@ -145,8 +165,10 @@ public:
|
|||
int8_t get_highest_failsafe_priority(void) const { return _highest_failsafe_priority; };
|
||||
|
||||
/// get_type - returns battery monitor type
|
||||
enum AP_BattMonitor_Params::BattMonitor_Type get_type() const { return get_type(AP_BATT_PRIMARY_INSTANCE); }
|
||||
enum AP_BattMonitor_Params::BattMonitor_Type get_type(uint8_t instance) const { return _params[instance].type(); }
|
||||
enum Type get_type() const { return get_type(AP_BATT_PRIMARY_INSTANCE); }
|
||||
enum Type get_type(uint8_t instance) const {
|
||||
return (Type)_params[instance]._type.get();
|
||||
}
|
||||
|
||||
/// true when (voltage * current) > watt_max
|
||||
bool overpower_detected() const;
|
||||
|
|
|
@ -57,5 +57,5 @@ AP_BattMonitor_Analog::read()
|
|||
/// return true if battery provides current info
|
||||
bool AP_BattMonitor_Analog::has_current() const
|
||||
{
|
||||
return (_params.type() == AP_BattMonitor_Params::BattMonitor_TYPE_ANALOG_VOLTAGE_AND_CURRENT);
|
||||
return ((AP_BattMonitor::Type)_params._type.get() == AP_BattMonitor::Type::ANALOG_VOLTAGE_AND_CURRENT);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const AP_Param::GroupInfo AP_BattMonitor_Params::var_info[] = {
|
|||
// @Values: 0:Disabled,3:Analog Voltage Only,4:Analog Voltage and Current,5:Solo,6:Bebop,7:SMBus-Generic,8:UAVCAN-BatteryInfo,9:BLHeli ESC,10:SumOfFollowing,11:FuelFlow,12:FuelLevelPWM,13:SMBUS-SUI3,14:SMBUS-SUI6,15:NeoDesign,16:SMBus-Maxell
|
||||
// @User: Standard
|
||||
// @RebootRequired: True
|
||||
AP_GROUPINFO_FLAGS("MONITOR", 1, AP_BattMonitor_Params, _type, BattMonitor_TYPE_NONE, AP_PARAM_FLAG_ENABLE),
|
||||
AP_GROUPINFO_FLAGS("MONITOR", 1, AP_BattMonitor_Params, _type, int8_t(AP_BattMonitor::Type::NONE), AP_PARAM_FLAG_ENABLE),
|
||||
|
||||
// @Param: VOLT_PIN
|
||||
// @DisplayName: Battery Voltage sensing pin
|
||||
|
|
|
@ -12,33 +12,12 @@ public:
|
|||
AP_BattMonitor_Params(const AP_BattMonitor_Params &other) = delete;
|
||||
AP_BattMonitor_Params &operator=(const AP_BattMonitor_Params&) = delete;
|
||||
|
||||
// Battery monitor driver types
|
||||
enum BattMonitor_Type {
|
||||
BattMonitor_TYPE_NONE = 0,
|
||||
BattMonitor_TYPE_ANALOG_VOLTAGE_ONLY = 3,
|
||||
BattMonitor_TYPE_ANALOG_VOLTAGE_AND_CURRENT = 4,
|
||||
BattMonitor_TYPE_SOLO = 5,
|
||||
BattMonitor_TYPE_BEBOP = 6,
|
||||
BattMonitor_TYPE_SMBus_Generic = 7,
|
||||
BattMonitor_TYPE_UAVCAN_BatteryInfo = 8,
|
||||
BattMonitor_TYPE_BLHeliESC = 9,
|
||||
BattMonitor_TYPE_Sum = 10,
|
||||
BattMonitor_TYPE_FuelFlow = 11,
|
||||
BattMonitor_TYPE_FuelLevel_PWM = 12,
|
||||
BattMonitor_TYPE_SUI3 = 13,
|
||||
BattMonitor_TYPE_SUI6 = 14,
|
||||
BattMonitor_TYPE_NeoDesign = 15,
|
||||
BattMonitor_TYPE_MAXELL = 16,
|
||||
BattMonitor_TYPE_Generator = 17,
|
||||
};
|
||||
|
||||
// low voltage sources (used for BATT_LOW_TYPE parameter)
|
||||
enum BattMonitor_LowVoltage_Source {
|
||||
BattMonitor_LowVoltageSource_Raw = 0,
|
||||
BattMonitor_LowVoltageSource_SagCompensated = 1
|
||||
};
|
||||
|
||||
BattMonitor_Type type(void) const { return (enum BattMonitor_Type)_type.get(); }
|
||||
BattMonitor_LowVoltage_Source failsafe_voltage_source(void) { return (enum BattMonitor_LowVoltage_Source)_failsafe_voltage_source.get(); }
|
||||
|
||||
AP_Int8 _type; /// 0=disabled, 3=voltage only, 4=voltage and current
|
||||
|
|
|
@ -51,7 +51,7 @@ AP_BattMonitor_UAVCAN* AP_BattMonitor_UAVCAN::get_uavcan_backend(AP_UAVCAN* ap_u
|
|||
}
|
||||
for (uint8_t i = 0; i < AP::battery()._num_instances; i++) {
|
||||
if (AP::battery().drivers[i] == nullptr ||
|
||||
AP::battery().get_type(i) != AP_BattMonitor_Params::BattMonitor_TYPE_UAVCAN_BatteryInfo) {
|
||||
AP::battery().get_type(i) != AP_BattMonitor::Type::UAVCAN_BatteryInfo) {
|
||||
continue;
|
||||
}
|
||||
AP_BattMonitor_UAVCAN* driver = (AP_BattMonitor_UAVCAN*)AP::battery().drivers[i];
|
||||
|
@ -62,7 +62,7 @@ AP_BattMonitor_UAVCAN* AP_BattMonitor_UAVCAN::get_uavcan_backend(AP_UAVCAN* ap_u
|
|||
// find empty uavcan driver
|
||||
for (uint8_t i = 0; i < AP::battery()._num_instances; i++) {
|
||||
if (AP::battery().drivers[i] != nullptr &&
|
||||
AP::battery().get_type(i) == AP_BattMonitor_Params::BattMonitor_TYPE_UAVCAN_BatteryInfo) {
|
||||
AP::battery().get_type(i) == AP_BattMonitor::Type::UAVCAN_BatteryInfo) {
|
||||
|
||||
AP_BattMonitor_UAVCAN* batmon = (AP_BattMonitor_UAVCAN*)AP::battery().drivers[i];
|
||||
batmon->_ap_uavcan = ap_uavcan;
|
||||
|
|
Loading…
Reference in New Issue