1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

altitude: allow altitude to be an optional module

This commit is contained in:
Stacey Sheldon 2012-01-14 15:04:49 -05:00
parent bae08fcad0
commit 717c1311e6
2 changed files with 41 additions and 27 deletions

View File

@ -37,6 +37,7 @@
*/ */
#include "openpilot.h" #include "openpilot.h"
#include "hwsettings.h"
#include "altitude.h" #include "altitude.h"
#include "baroaltitude.h" // object that will be updated by the module #include "baroaltitude.h" // object that will be updated by the module
#if defined(PIOS_INCLUDE_HCSR04) #if defined(PIOS_INCLUDE_HCSR04)
@ -60,6 +61,8 @@ static int32_t alt_ds_temp = 0;
static int32_t alt_ds_pres = 0; static int32_t alt_ds_pres = 0;
static int alt_ds_count = 0; static int alt_ds_count = 0;
static bool altitudeEnabled;
// Private functions // Private functions
static void altitudeTask(void *parameters); static void altitudeTask(void *parameters);
@ -69,17 +72,19 @@ static void altitudeTask(void *parameters);
*/ */
int32_t AltitudeStart() int32_t AltitudeStart()
{ {
BaroAltitudeInitialize();
#if defined(PIOS_INCLUDE_HCSR04)
SonarAltitudeInitialze();
#endif
// Start main task
xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle);
TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle);
return 0; if (altitudeEnabled) {
BaroAltitudeInitialize();
#if defined(PIOS_INCLUDE_HCSR04)
SonarAltitudeInitialze();
#endif
// Start main task
xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle);
TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle);
return 0;
}
return -1;
} }
/** /**
@ -89,10 +94,19 @@ int32_t AltitudeStart()
int32_t AltitudeInitialize() int32_t AltitudeInitialize()
{ {
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
HwSettingsOptionalModulesGet(optionalModules);
if (optionalModules[HWSETTINGS_OPTIONALMODULES_ALTITUDE] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
altitudeEnabled = 1;
} else {
altitudeEnabled = 0;
}
// init down-sampling data // init down-sampling data
alt_ds_temp = 0; alt_ds_temp = 0;
alt_ds_pres = 0; alt_ds_pres = 0;
alt_ds_count = 0; alt_ds_count = 0;
return 0; return 0;
} }
@ -163,23 +177,23 @@ static void altitudeTask(void *parameters)
alt_ds_pres += PIOS_BMP085_GetPressure(); alt_ds_pres += PIOS_BMP085_GetPressure();
if (++alt_ds_count >= alt_ds_size) if (++alt_ds_count >= alt_ds_size)
{ {
alt_ds_count = 0; alt_ds_count = 0;
// Convert from 1/10ths of degC to degC // Convert from 1/10ths of degC to degC
data.Temperature = alt_ds_temp / (10.0 * alt_ds_size); data.Temperature = alt_ds_temp / (10.0 * alt_ds_size);
alt_ds_temp = 0; alt_ds_temp = 0;
// Convert from Pa to kPa // Convert from Pa to kPa
data.Pressure = alt_ds_pres / (1000.0f * alt_ds_size); data.Pressure = alt_ds_pres / (1000.0f * alt_ds_size);
alt_ds_pres = 0; alt_ds_pres = 0;
// Compute the current altitude (all pressures in kPa) // Compute the current altitude (all pressures in kPa)
data.Altitude = 44330.0 * (1.0 - powf((data.Pressure / (BMP085_P0 / 1000.0)), (1.0 / 5.255))); data.Altitude = 44330.0 * (1.0 - powf((data.Pressure / (BMP085_P0 / 1000.0)), (1.0 / 5.255)));
// Update the AltitudeActual UAVObject // Update the AltitudeActual UAVObject
BaroAltitudeSet(&data); BaroAltitudeSet(&data);
} }
// Delay until it is time to read the next sample // Delay until it is time to read the next sample
vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD / portTICK_RATE_MS); vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD / portTICK_RATE_MS);

View File

@ -16,7 +16,7 @@
<field name="USB_HIDPort" units="function" type="enum" elements="1" options="USBTelemetry,Disabled" defaultvalue="USBTelemetry"/> <field name="USB_HIDPort" units="function" type="enum" elements="1" options="USBTelemetry,Disabled" defaultvalue="USBTelemetry"/>
<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" options="Disabled,Enabled" defaultvalue="Disabled"/> <field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge,Fault,Altitude" options="Disabled,Enabled" 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"/>