mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Changes to FlightBatterySettings as discussed in forums
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3047 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
ef1dcf6939
commit
d270f7e987
@ -48,13 +48,12 @@
|
||||
#include "openpilot.h"
|
||||
|
||||
#include "flightbatterystate.h"
|
||||
#include "batterysettings.h"
|
||||
#include "flightbatterysettings.h"
|
||||
|
||||
//
|
||||
// Configuration
|
||||
//
|
||||
#define SAMPLE_PERIOD_MS 500
|
||||
#define POWER_SENSOR_VERSION 2
|
||||
|
||||
//#define ENABLE_DEBUG_MSG
|
||||
|
||||
@ -107,44 +106,24 @@ static void onTimer(UAVObjEvent* ev)
|
||||
AlarmsSet(SYSTEMALARMS_ALARM_BATTERY, SYSTEMALARMS_ALARM_ERROR);
|
||||
|
||||
|
||||
#if (POWER_SENSOR_VERSION == 1)
|
||||
// TODO: Compare with floating point calculations
|
||||
uint cnt = 0;
|
||||
uint32_t mAs = 0;
|
||||
uint32_t mV, mA;
|
||||
|
||||
mV = PIOS_ADC_PinGet(2) * 1257 / 100;
|
||||
mA = (PIOS_ADC_PinGet(1) - 28) * 4871 / 100;
|
||||
mAs += mA * SAMPLE_PERIOD_MS / 1000; // FIXME: Use real time between samples
|
||||
|
||||
DEBUG_MSG("%03d %06d => %06dmV %06d => %06dmA %06dmAh\n", cnt, PIOS_ADC_PinGet(2), mV, PIOS_ADC_PinGet(1), mA, mAs / 3600);
|
||||
|
||||
cnt++;
|
||||
|
||||
flightBatteryData.Voltage = (float)mV / 1000;
|
||||
flightBatteryData.Current = (float)mA / 1000;
|
||||
flightBatteryData.ConsumedEnergy = mAs / 3600;
|
||||
FlightBatteryStateSet(&flightBatteryData);
|
||||
|
||||
#endif
|
||||
#if (POWER_SENSOR_VERSION == 2)
|
||||
portTickType thisSysTime;
|
||||
BatterySettingsData batterySettings;
|
||||
FlightBatterySettingsData batterySettings;
|
||||
static float dT = SAMPLE_PERIOD_MS / 1000;
|
||||
float Bob;
|
||||
float energyRemaining;
|
||||
|
||||
|
||||
// Check how long since last update
|
||||
thisSysTime = xTaskGetTickCount();
|
||||
if(thisSysTime > lastSysTime) // reuse dt in case of wraparound
|
||||
dT = (float)(thisSysTime - lastSysTime) / (float)(portTICK_RATE_MS * 1000.0f);
|
||||
//lastSysTime = thisSysTime;
|
||||
|
||||
BatterySettingsGet(&batterySettings);
|
||||
FlightBatterySettingsGet(&batterySettings);
|
||||
|
||||
//calculate the battery parameters
|
||||
flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(2)) * 0.008065 * batterySettings.Calibrations[BATTERYSETTINGS_CALIBRATIONS_VOLTAGE]; //in Volts
|
||||
flightBatteryData.Current = ((float)PIOS_ADC_PinGet(1)) * 0.016113 * batterySettings.Calibrations[BATTERYSETTINGS_CALIBRATIONS_CURRENT]; //in Amps
|
||||
flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(2)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_VOLTAGEFACTOR]; //in Volts
|
||||
flightBatteryData.Current = ((float)PIOS_ADC_PinGet(1)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; //in Amps
|
||||
Bob =dT; // FIXME: something funky happens if I don't do this... Andrew
|
||||
flightBatteryData.ConsumedEnergy += (flightBatteryData.Current * 1000.0 * dT / 3600.0) ;//in mAh
|
||||
|
||||
@ -156,7 +135,7 @@ Bob =dT; // FIXME: something funky happens if I don't do this... Andrew
|
||||
if (flightBatteryData.PeakCurrent<0)flightBatteryData.PeakCurrent=0.0;
|
||||
if (flightBatteryData.ConsumedEnergy<0)flightBatteryData.ConsumedEnergy=0.0;
|
||||
|
||||
energyRemaining = batterySettings.BatteryCapacity - flightBatteryData.ConsumedEnergy; // in mAh
|
||||
energyRemaining = batterySettings.Capacity - flightBatteryData.ConsumedEnergy; // in mAh
|
||||
flightBatteryData.EstimatedFlightTime = ((energyRemaining / (flightBatteryData.AvgCurrent*1000.0))*3600.0);//in Sec
|
||||
|
||||
//generate alarms where needed...
|
||||
@ -172,14 +151,15 @@ Bob =dT; // FIXME: something funky happens if I don't do this... Andrew
|
||||
else AlarmsClear(SYSTEMALARMS_ALARM_FLIGHTTIME);
|
||||
|
||||
// FIXME: should make the battery voltage detection dependent on battery type.
|
||||
if ((flightBatteryData.Voltage < batterySettings.BatteryVoltage * 0.75)||(flightBatteryData.Current > batterySettings.BatteryCapacity * 0.85))AlarmsSet(SYSTEMALARMS_ALARM_BATTERY, SYSTEMALARMS_ALARM_CRITICAL);
|
||||
else if ((flightBatteryData.Voltage < batterySettings.BatteryVoltage * 0.85)||(flightBatteryData.Current > batterySettings.BatteryCapacity * 0.95))AlarmsSet(SYSTEMALARMS_ALARM_BATTERY, SYSTEMALARMS_ALARM_WARNING);
|
||||
if (flightBatteryData.Voltage < batterySettings.VoltageThresholds[FLIGHTBATTERYSETTINGS_VOLTAGETHRESHOLDS_ALARM])
|
||||
AlarmsSet(SYSTEMALARMS_ALARM_BATTERY, SYSTEMALARMS_ALARM_CRITICAL);
|
||||
else if (flightBatteryData.Voltage < batterySettings.VoltageThresholds[FLIGHTBATTERYSETTINGS_VOLTAGETHRESHOLDS_WARNING])
|
||||
AlarmsSet(SYSTEMALARMS_ALARM_BATTERY, SYSTEMALARMS_ALARM_WARNING);
|
||||
else AlarmsClear(SYSTEMALARMS_ALARM_BATTERY);
|
||||
}
|
||||
lastSysTime = thisSysTime;
|
||||
|
||||
FlightBatteryStateSet(&flightBatteryData);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,16 @@
|
||||
<xml>
|
||||
<object name="BatterySettings" singleinstance="true" settings="true">
|
||||
<description>Battery configuration information.</description>
|
||||
<field name="BatteryVoltage" units="V" type="float" elements="1" defaultvalue="11.1"/>
|
||||
<field name="BatteryCapacity" units="mAh" type="uint32" elements="1" defaultvalue="2200"/>
|
||||
<field name="BatteryType" units="" type="enum" elements="1" options="LiPo,A123,LiCo,LiFeSO4,None" defaultvalue="LiPo"/>
|
||||
<field name="Calibrations" units="" type="float" elementnames="Voltage,Current" defaultvalue="1.0"/>
|
||||
<object name="FlightBatterySettings" singleinstance="true" settings="true">
|
||||
<description>Flight Battery configuration.</description>
|
||||
|
||||
<field name="Type" units="" type="enum" elements="1" options="LiPo,A123,LiCo,LiFeSO4,None" defaultvalue="LiPo"/>
|
||||
<field name="NbCells" units="" type="uint8" elements="1" defaultvalue="3"/>
|
||||
<field name="Capacity" units="mAh" type="uint32" elements="1" defaultvalue="2200"/>
|
||||
|
||||
<field name="VoltageThresholds" units="V" type="float" elementnames="Warning, Alarm" defaultvalue="9.8, 9.2"/>
|
||||
|
||||
<field name="SensorType" units="" type="enum" elements="1" options="None" defaultvalue="None"/>
|
||||
<field name="SensorCalibrations" units="" type="float" elementnames="VoltageFactor, CurrentFactor" defaultvalue="1.0, 1.0"/>
|
||||
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
|
||||
<telemetryflight acked="true" updatemode="onchange" period="0"/>
|
||||
|
Loading…
Reference in New Issue
Block a user