diff --git a/flight/Modules/Airspeed/revolution/airspeed.c b/flight/Modules/Airspeed/revolution/airspeed.c new file mode 100644 index 000000000..14831ea08 --- /dev/null +++ b/flight/Modules/Airspeed/revolution/airspeed.c @@ -0,0 +1,145 @@ +/** + ****************************************************************************** + * @addtogroup OpenPilotModules OpenPilot Modules + * @{ + * @addtogroup AirspeedModule Airspeed Module + * @brief Communicate with BMP085 and update @ref BaroAirspeed "BaroAirspeed UAV Object" + * @{ + * + * @file airspeed.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed module, handles temperature and pressure readings from BMP085 + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * Output object: BaroAirspeed + * + * This module will periodically update the value of the BaroAirspeed object. + * + */ + +#include "openpilot.h" +#include "airspeed.h" +#include "baroairspeed.h" // object that will be updated by the module +#if defined(PIOS_INCLUDE_HCSR04) +#include "sonarairspeed.h" // object that will be updated by the module +#endif + +// Private constants +#define STACK_SIZE_BYTES 500 +#define TASK_PRIORITY (tskIDLE_PRIORITY+1) + +// Private types + +// Private variables +static xTaskHandle taskHandle; + +// Private functions +static void airspeedTask(void *parameters); + + +static bool airspeedEnabled = false; + +/** + * Initialise the module, called on startup + * \returns 0 on success or -1 if initialisation failed + */ +int32_t AirspeedStart() +{ + + if (airspeedEnabled == false) { + return -1; + } + // Start main task + xTaskCreate(airspeedTask, (signed char *)"Airspeed", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); + TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle); + + return 0; +} + +/** + * Initialise the module, called on startup + * \returns 0 on success or -1 if initialisation failed + */ +int32_t AirspeedInitialize() +{ + #ifdef MODULE_AIRSPEED_BUILTIN + airspeedEnabled = true; + #else + + HwSettingsInitialize(); + uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; + HwSettingsOptionalModulesGet(optionalModules); + + if (optionalModules[HWSETTINGS_OPTIONALMODULES_AIRSPEED] == HWSETTINGS_OPTIONALMODULES_ENABLED) { + airspeedEnabled = true; + } else { + airspeedEnabled = false; + return -1; + } + #endif + + BaroAirspeedInitialize(); + + return 0; +} +MODULE_INITCALL(AirspeedInitialize, AirspeedStart) +/** + * Module thread, should not return. + */ +static void airspeedTask(void *parameters) +{ + BaroAirspeedData data; + + // TODO: Check the pressure sensor and set a warning if it fails test + + // Main task loop + while (1) + { + float temp, press; + + // Update the temperature data + PIOS_MS5611_StartADC(TemperatureConv); + vTaskDelay(PIOS_MS5611_GetDelay()); + PIOS_MS5611_ReadADC(); + + // Update the pressure data + PIOS_MS5611_StartADC(PressureConv); + vTaskDelay(PIOS_MS5611_GetDelay()); + PIOS_MS5611_ReadADC(); + + + temp = PIOS_MS5611_GetTemperature(); + press = PIOS_MS5611_GetPressure(); + + data.Temperature = temp; + data.Pressure = press; + data.Airspeed = 44330.0f * (1.0f - powf(data.Pressure / MS5611_P0, (1.0f / 5.255f))); + + // Update the AirspeedActual UAVObject + BaroAirspeedSet(&data); + } +} + +/** + * @} + * @} + */ diff --git a/flight/Modules/Airspeed/revolution/inc/airspeed.h b/flight/Modules/Airspeed/revolution/inc/airspeed.h new file mode 100644 index 000000000..c1bd9c8a7 --- /dev/null +++ b/flight/Modules/Airspeed/revolution/inc/airspeed.h @@ -0,0 +1,41 @@ +/** + ****************************************************************************** + * @addtogroup OpenPilotModules OpenPilot Modules + * @{ + * @addtogroup AirspeedModule Airspeed Module + * @brief Communicate with EagleTree Airspeed Sensor and update @ref BaroAirspeed "BaroAirspeed UAV Object" + * @{ + * + * @file airspeed.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed module, reads temperature and pressure from BMP085 + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef AIRSPEED_H +#define AIRSPEED_H + +int32_t AirspeedInitialize(); + +#endif // AIRSPEED_H + +/** + * @} + * @} + */ diff --git a/shared/uavobjectdefinition/baroairspeed.xml b/shared/uavobjectdefinition/baroairspeed.xml new file mode 100644 index 000000000..c83095a23 --- /dev/null +++ b/shared/uavobjectdefinition/baroairspeed.xml @@ -0,0 +1,12 @@ + + + The raw data from the dynamic pressure sensor with pressure, temperature and airspeed. + + + + + + + + + diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 490699196..45b6cac71 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -19,7 +19,7 @@ - +