2012-04-17 15:54:05 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
|
|
|
* @{
|
|
|
|
* @addtogroup AirspeedModule Airspeed Module
|
2012-07-20 13:08:54 +02:00
|
|
|
* @brief Calculate airspeed from diverse sources and update @ref Airspeed "Airspeed UAV Object"
|
2012-04-17 15:54:05 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file airspeed.c
|
2012-07-20 13:08:54 +02:00
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @brief Airspeed module
|
2012-04-17 15:54:05 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-11-08 01:31:21 +01:00
|
|
|
* Output object: AirspeedSensor
|
2012-04-17 15:54:05 +02:00
|
|
|
*
|
2012-11-08 01:31:21 +01:00
|
|
|
* This module will periodically update the value of the AirspeedSensor object.
|
2012-04-17 15:54:05 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "openpilot.h"
|
2012-04-17 16:38:53 +02:00
|
|
|
#include "hwsettings.h"
|
2012-07-20 13:08:54 +02:00
|
|
|
#include "airspeedsettings.h"
|
2012-11-08 01:31:21 +01:00
|
|
|
#include "airspeedsensor.h" // object that will be updated by the module
|
2012-10-28 17:45:40 +01:00
|
|
|
#include "baro_airspeed_etasv3.h"
|
2012-11-08 01:31:21 +01:00
|
|
|
#include "baro_airspeed_mpxv.h"
|
2012-04-17 15:54:05 +02:00
|
|
|
|
|
|
|
// Private constants
|
2012-07-20 13:08:54 +02:00
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
#define STACK_SIZE_BYTES 500
|
2012-07-20 13:08:54 +02:00
|
|
|
|
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
#define TASK_PRIORITY (tskIDLE_PRIORITY+1)
|
2012-07-20 13:08:54 +02:00
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
// Private types
|
|
|
|
|
|
|
|
// Private variables
|
|
|
|
static xTaskHandle taskHandle;
|
2012-07-20 13:08:54 +02:00
|
|
|
static bool airspeedEnabled = false;
|
2012-11-08 01:31:21 +01:00
|
|
|
static AirspeedSettingsData airspeedSettings;
|
2012-07-20 13:08:54 +02:00
|
|
|
|
|
|
|
static int8_t airspeedADCPin=-1;
|
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
|
|
|
|
// Private functions
|
|
|
|
static void airspeedTask(void *parameters);
|
2012-07-20 13:08:54 +02:00
|
|
|
static void AirspeedSettingsUpdatedCb(UAVObjEvent * ev);
|
2012-04-17 15:54:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the module, called on startup
|
|
|
|
* \returns 0 on success or -1 if initialisation failed
|
|
|
|
*/
|
|
|
|
int32_t AirspeedStart()
|
|
|
|
{
|
2012-07-23 14:06:44 +02:00
|
|
|
|
2012-07-20 13:08:54 +02:00
|
|
|
//Check if module is enabled or not
|
2012-04-17 15:54:05 +02:00
|
|
|
if (airspeedEnabled == false) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-20 13:08:54 +02:00
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
// Start main task
|
|
|
|
xTaskCreate(airspeedTask, (signed char *)"Airspeed", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle);
|
2012-04-17 18:59:46 +02:00
|
|
|
TaskMonitorAdd(TASKINFO_RUNNING_AIRSPEED, taskHandle);
|
2012-04-17 15:54:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the module, called on startup
|
|
|
|
* \returns 0 on success or -1 if initialisation failed
|
|
|
|
*/
|
|
|
|
int32_t AirspeedInitialize()
|
|
|
|
{
|
2012-07-20 13:08:54 +02:00
|
|
|
#ifdef MODULE_AIRSPEED_BUILTIN
|
|
|
|
airspeedEnabled = true;
|
|
|
|
#else
|
|
|
|
|
|
|
|
HwSettingsInitialize();
|
|
|
|
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
|
|
|
|
HwSettingsOptionalModulesGet(optionalModules);
|
|
|
|
|
|
|
|
|
|
|
|
if (optionalModules[HWSETTINGS_OPTIONALMODULES_AIRSPEED] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
2012-04-17 15:54:05 +02:00
|
|
|
airspeedEnabled = true;
|
2012-07-20 13:08:54 +02:00
|
|
|
} else {
|
|
|
|
airspeedEnabled = false;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint8_t adcRouting[HWSETTINGS_ADCROUTING_NUMELEM];
|
|
|
|
HwSettingsADCRoutingGet(adcRouting);
|
|
|
|
|
|
|
|
//Determine if the barometric airspeed sensor is routed to an ADC pin
|
|
|
|
for (int i=0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
|
|
|
if (adcRouting[i] == HWSETTINGS_ADCROUTING_ANALOGAIRSPEED) {
|
|
|
|
airspeedADCPin = i;
|
2012-04-17 15:54:05 +02:00
|
|
|
}
|
2012-07-20 13:08:54 +02:00
|
|
|
}
|
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
AirspeedSensorInitialize();
|
2012-07-20 13:08:54 +02:00
|
|
|
AirspeedSettingsInitialize();
|
|
|
|
|
|
|
|
AirspeedSettingsConnectCallback(AirspeedSettingsUpdatedCb);
|
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MODULE_INITCALL(AirspeedInitialize, AirspeedStart)
|
2012-07-20 13:08:54 +02:00
|
|
|
|
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
/**
|
|
|
|
* Module thread, should not return.
|
|
|
|
*/
|
|
|
|
static void airspeedTask(void *parameters)
|
|
|
|
{
|
2012-07-20 13:08:54 +02:00
|
|
|
AirspeedSettingsUpdatedCb(AirspeedSettingsHandle());
|
2012-04-17 15:54:05 +02:00
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
AirspeedSensorData airspeedData;
|
|
|
|
AirspeedSensorGet(&airspeedData);
|
2012-07-20 13:08:54 +02:00
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
AirspeedSettingsUpdatedCb(NULL);
|
2012-07-20 13:08:54 +02:00
|
|
|
|
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
airspeedData.SensorConnected = AIRSPEEDSENSOR_SENSORCONNECTED_FALSE;
|
2012-04-17 15:54:05 +02:00
|
|
|
|
|
|
|
// Main task loop
|
2012-07-20 13:08:54 +02:00
|
|
|
portTickType lastSysTime = xTaskGetTickCount();
|
2012-04-17 15:54:05 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2012-11-08 01:31:21 +01:00
|
|
|
vTaskDelayUntil(&lastSysTime, airspeedSettings.SamplePeriod / portTICK_RATE_MS);
|
2012-07-20 13:08:54 +02:00
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
// Update the airspeed object
|
|
|
|
AirspeedSensorGet(&airspeedData);
|
2012-04-18 10:48:31 +02:00
|
|
|
|
2012-11-08 01:31:21 +01:00
|
|
|
switch (airspeedSettings.AirspeedSensorType) {
|
|
|
|
#if defined(PIOS_INCLUDE_MPXV)
|
|
|
|
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV7002:
|
|
|
|
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV5004:
|
|
|
|
//MPXV5004 and MPXV7002 sensors
|
|
|
|
baro_airspeedGetMPXV(&airspeedData, &airspeedSettings,airspeedADCPin);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if defined(PIOS_INCLUDE_ETASV3)
|
|
|
|
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3:
|
|
|
|
//Eagletree Airspeed v3
|
|
|
|
baro_airspeedGetETASV3(&airspeedData, &airspeedSettings);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
airspeedData.SensorConnected = AIRSPEEDSENSOR_SENSORCONNECTED_FALSE;
|
2012-07-20 13:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Set the UAVO
|
2012-11-08 01:31:21 +01:00
|
|
|
AirspeedSensorSet(&airspeedData);
|
2012-07-20 13:08:54 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-28 17:45:40 +01:00
|
|
|
|
2012-04-18 10:48:31 +02:00
|
|
|
|
2012-07-20 13:08:54 +02:00
|
|
|
static void AirspeedSettingsUpdatedCb(UAVObjEvent * ev)
|
|
|
|
{
|
2012-11-08 01:31:21 +01:00
|
|
|
AirspeedSettingsGet(&airspeedSettings);
|
2012-04-17 15:54:05 +02:00
|
|
|
|
|
|
|
}
|
2012-07-20 13:08:54 +02:00
|
|
|
|
|
|
|
|
2012-04-17 15:54:05 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|