mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
Improved battery module to fully support regeneration. Fixed bug in builtin battery module. Improved ADC routing names.
This commit is contained in:
parent
0a34b786a9
commit
cfb8e72679
@ -78,32 +78,39 @@ static void onTimer(UAVObjEvent* ev);
|
|||||||
int32_t BatteryInitialize(void)
|
int32_t BatteryInitialize(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
#ifdef MODULE_BATTERY_BUILTIN
|
#ifdef MODULE_BATTERY_BUILTIN
|
||||||
batteryEnabled = true;
|
batteryEnabled = true;
|
||||||
#else
|
#else
|
||||||
HwSettingsInitialize();
|
HwSettingsInitialize();
|
||||||
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
|
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
|
||||||
uint8_t adcRouting[HWSETTINGS_ADCROUTING_NUMELEM];
|
|
||||||
|
|
||||||
HwSettingsOptionalModulesGet(optionalModules);
|
HwSettingsOptionalModulesGet(optionalModules);
|
||||||
HwSettingsADCRoutingGet(adcRouting);
|
|
||||||
|
|
||||||
//Determine if the battery sensors are routed to ADC pins
|
if ((optionalModules[HWSETTINGS_OPTIONALMODULES_BATTERY] == HWSETTINGS_OPTIONALMODULES_ENABLED))
|
||||||
for (int i=0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
|
||||||
if (adcRouting[i] == HWSETTINGS_ADCROUTING_VOLTAGE) {
|
|
||||||
voltageADCPin = i;
|
|
||||||
}
|
|
||||||
if (adcRouting[i] == HWSETTINGS_ADCROUTING_CURRENT) {
|
|
||||||
currentADCPin = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((optionalModules[HWSETTINGS_OPTIONALMODULES_BATTERY] == HWSETTINGS_OPTIONALMODULES_ENABLED) && (voltageADCPin >=0 || currentADCPin >=0))
|
|
||||||
batteryEnabled = true;
|
batteryEnabled = true;
|
||||||
else
|
else
|
||||||
batteryEnabled = false;
|
batteryEnabled = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint8_t adcRouting[HWSETTINGS_ADCROUTING_NUMELEM];
|
||||||
|
HwSettingsADCRoutingGet(adcRouting);
|
||||||
|
|
||||||
|
//Determine if the battery sensors are routed to ADC pins
|
||||||
|
for (int i=0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
||||||
|
if (adcRouting[i] == HWSETTINGS_ADCROUTING_BATTERYVOLTAGE) {
|
||||||
|
voltageADCPin = i;
|
||||||
|
}
|
||||||
|
if (adcRouting[i] == HWSETTINGS_ADCROUTING_BATTERYCURRENT) {
|
||||||
|
currentADCPin = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Don't enable module if no ADC pins are routed to the sensors
|
||||||
|
if (voltageADCPin <0 && currentADCPin <0)
|
||||||
|
batteryEnabled = false;
|
||||||
|
|
||||||
|
//Start module
|
||||||
if (batteryEnabled) {
|
if (batteryEnabled) {
|
||||||
FlightBatteryStateInitialize();
|
FlightBatteryStateInitialize();
|
||||||
FlightBatterySettingsInitialize();
|
FlightBatterySettingsInitialize();
|
||||||
@ -133,6 +140,10 @@ static void onTimer(UAVObjEvent* ev)
|
|||||||
if (voltageADCPin >=0) {
|
if (voltageADCPin >=0) {
|
||||||
flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(voltageADCPin)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_VOLTAGEFACTOR]; //in Volts
|
flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(voltageADCPin)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_VOLTAGEFACTOR]; //in Volts
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
flightBatteryData.Voltage=1234; //Dummy placeholder value. This is in case we get another source of battery current which is not from the ADC
|
||||||
|
}
|
||||||
|
|
||||||
if (currentADCPin >=0) {
|
if (currentADCPin >=0) {
|
||||||
flightBatteryData.Current = ((float)PIOS_ADC_PinGet(currentADCPin)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; //in Amps
|
flightBatteryData.Current = ((float)PIOS_ADC_PinGet(currentADCPin)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; //in Amps
|
||||||
if (flightBatteryData.Current > flightBatteryData.PeakCurrent)
|
if (flightBatteryData.Current > flightBatteryData.PeakCurrent)
|
||||||
@ -158,7 +169,10 @@ static void onTimer(UAVObjEvent* ev)
|
|||||||
// if (flightBatteryData.ConsumedEnergy<0) flightBatteryData.ConsumedEnergy=0.0f;
|
// if (flightBatteryData.ConsumedEnergy<0) flightBatteryData.ConsumedEnergy=0.0f;
|
||||||
|
|
||||||
energyRemaining = batterySettings.Capacity - flightBatteryData.ConsumedEnergy; // in mAh
|
energyRemaining = batterySettings.Capacity - flightBatteryData.ConsumedEnergy; // in mAh
|
||||||
flightBatteryData.EstimatedFlightTime = ((energyRemaining / (flightBatteryData.AvgCurrent*1000.0f))*3600.0f);//in Sec
|
if (flightBatteryData.AvgCurrent > 0)
|
||||||
|
flightBatteryData.EstimatedFlightTime = (energyRemaining / (flightBatteryData.AvgCurrent*1000.0f))*3600.0f;//in Sec
|
||||||
|
else
|
||||||
|
flightBatteryData.EstimatedFlightTime = 9999;
|
||||||
|
|
||||||
//generate alarms where needed...
|
//generate alarms where needed...
|
||||||
if ((flightBatteryData.Voltage<=0) && (flightBatteryData.Current<=0))
|
if ((flightBatteryData.Voltage<=0) && (flightBatteryData.Current<=0))
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,Disabled" defaultvalue="Disabled"/>
|
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,Disabled" defaultvalue="Disabled"/>
|
||||||
|
|
||||||
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge,Fault,Altitude,Airspeed,TxPID,VtolPathFollower,FixedWingPathFollower,Battery,Overo" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge,Fault,Altitude,Airspeed,TxPID,VtolPathFollower,FixedWingPathFollower,Battery,Overo" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
||||||
<field name="ADCRouting" units="" type="enum" elementnames="ADC0,ADC1,ADC2,ADC3" options="Disabled,Voltage,Current,Airspeed,Generic" defaultvalue="Disabled"/>
|
<field name="ADCRouting" units="" type="enum" elementnames="ADC0,ADC1,ADC2,ADC3" options="Disabled,BatteryVoltage,BatteryCurrent,AnalogAirspeed,Generic" defaultvalue="Disabled"/>
|
||||||
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
|
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||||
|
|
||||||
<access gcs="readwrite" flight="readwrite"/>
|
<access gcs="readwrite" flight="readwrite"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user