AP_BattMonitor: add backend for generator supply

This commit is contained in:
Peter Barker 2019-11-29 10:04:33 +11:00 committed by Randy Mackay
parent fce9046dcf
commit 8e708a0a32
5 changed files with 67 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include "AP_BattMonitor_Sum.h"
#include "AP_BattMonitor_FuelFlow.h"
#include "AP_BattMonitor_FuelLevel_PWM.h"
#include "AP_BattMonitor_Generator.h"
#include <AP_HAL/AP_HAL.h>
@ -181,6 +182,9 @@ AP_BattMonitor::init()
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:
drivers[instance] = new AP_BattMonitor_Generator(*this, state[instance], _params[instance]);
break;
case AP_BattMonitor_Params::BattMonitor_TYPE_NONE:
default:
break;

View File

@ -37,6 +37,7 @@ class AP_BattMonitor_SMBus_Solo;
class AP_BattMonitor_SMBus_Generic;
class AP_BattMonitor_SMBus_Maxell;
class AP_BattMonitor_UAVCAN;
class AP_BattMonitor_Generator;
class AP_BattMonitor
{
@ -50,6 +51,7 @@ class AP_BattMonitor
friend class AP_BattMonitor_Sum;
friend class AP_BattMonitor_FuelFlow;
friend class AP_BattMonitor_FuelLevel_PWM;
friend class AP_BattMonitor_Generator;
public:

View File

@ -0,0 +1,38 @@
#include <AP_HAL/AP_HAL.h>
#include <AP_Common/AP_Common.h>
#include <AP_Math/AP_Math.h>
#include "AP_BattMonitor.h"
#include "AP_BattMonitor_Generator.h"
extern const AP_HAL::HAL& hal;
// read - read the voltage and current
void AP_BattMonitor_Generator::read()
{
_state.healthy = false;
#if GENERATOR_ENABLED
AP_Generator_RichenPower *generator = AP::generator();
// healthy if we can find a generator
if (generator == nullptr) {
return;
}
// get voltage
if (!generator->voltage(_state.voltage)) {
return;
}
// get current
if (!generator->current(_state.current_amps)) {
return;
}
if (!generator->healthy()) {
return;
}
_state.healthy = true;
#endif
}

View File

@ -0,0 +1,22 @@
#pragma once
#include "AP_BattMonitor.h"
#include "AP_BattMonitor_Backend.h"
#include <AP_Generator/AP_Generator_RichenPower.h>
class AP_BattMonitor_Generator : public AP_BattMonitor_Backend
{
public:
using AP_BattMonitor_Backend::AP_BattMonitor_Backend;
/// Read the battery voltage and current. Should be called at 10hz
void read() override;
/// returns true if battery monitor provides current info
bool has_current() const override { return true; }
void init(void) override {}
};

View File

@ -29,6 +29,7 @@ public:
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)