40 #include "physical_constants.h"
44 #include "modulesettings.h"
45 #include "gpsvelocity.h"
46 #include "airspeedsettings.h"
48 #include "homelocation.h"
49 #include "baroairspeed.h"
50 #include "airspeedactual.h"
51 #include "attitudeactual.h"
52 #include "positionactual.h"
59 #if defined (PIOS_INCLUDE_GPS)
60 #define GPS_AIRSPEED_PRESENT
63 #if defined (PIOS_INCLUDE_MPXV5004) || defined (PIOS_INCLUDE_MPXV7002) || defined (PIOS_INCLUDE_ETASV3) || defined(PIOS_INCLUDE_ADC)
64 #define BARO_AIRSPEED_PRESENT
67 #if defined (GPS_AIRSPEED_PRESENT) && defined (BARO_AIRSPEED_PRESENT)
68 #define STACK_SIZE_BYTES 700
69 #elif defined (GPS_AIRSPEED_PRESENT)
70 #define STACK_SIZE_BYTES 600
71 #elif defined (BARO_AIRSPEED_PRESENT)
72 #define STACK_SIZE_BYTES 550
74 #define STACK_SIZE_BYTES 0
75 #define NO_AIRSPEED_SENSOR_PRESENT
78 #define TASK_PRIORITY PIOS_THREAD_PRIO_LOW
80 #define SAMPLING_DELAY_MS_FALLTHROUGH 50 //Fallthrough update at 20Hz. The fallthrough runs faster than the GPS to ensure that we don't miss GPS updates because we're slightly out of sync
82 #define GPS_AIRSPEED_BIAS_KP 0.01f //Needs to be settable in a UAVO
83 #define GPS_AIRSPEED_BIAS_KI 0.01f //Needs to be settable in a UAVO
84 #define GPS_AIRSPEED_TIME_CONSTANT_MS 500.0f //Needs to be settable in a UAVO
86 #define BARO_TEMPERATURE_OFFSET 5
99 #ifdef BARO_AIRSPEED_PRESENT
100 static int8_t airspeedADCPin = -1;
113 #if defined (NO_AIRSPEED_SENSOR_PRESENT)
132 AirspeedSettingsGet(&settings);
138 #if defined(PIOS_INCLUDE_MPXV7002)
143 #if defined(PIOS_INCLUDE_MPXV5004)
156 if (AirspeedSettingsInitialize() == -1) {
161 #ifdef MODULE_Airspeed_BUILTIN
164 uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM];
165 ModuleSettingsAdminStateGet(module_state);
166 if (module_state[MODULESETTINGS_ADMINSTATE_AIRSPEED] == MODULESETTINGS_ADMINSTATE_ENABLED) {
176 if (BaroAirspeedInitialize() == -1) {
181 if (AirspeedActualInitialize() == -1) {
186 #ifdef BARO_AIRSPEED_PRESENT
188 AirspeedSettingsAnalogPinGet((uint8_t *) &airspeedADCPin);
189 if (airspeedADCPin == AIRSPEEDSETTINGS_ANALOGPIN_NONE)
202 BaroAirspeedData airspeedData;
203 AirspeedActualData airspeedActualData;
205 #ifdef BARO_AIRSPEED_PRESENT
206 float airspeedErrInt = 0;
208 #ifdef GPS_AIRSPEED_PRESENT
211 float airspeed_tas_baro = 0;
217 #ifdef GPS_AIRSPEED_PRESENT
231 BaroAirspeedGet(&airspeedData);
233 airspeedData.BaroConnected = BAROAIRSPEED_BAROCONNECTED_FALSE;
242 #ifdef BARO_AIRSPEED_PRESENT
248 int16_t groundTemperature_10;
249 float groundTemperature;
250 float positionActual_Down;
252 PositionActualDownGet(&positionActual_Down);
253 HomeLocationGroundTemperatureGet(&groundTemperature_10);
254 groundTemperature = groundTemperature_10/10;
260 #ifdef GPS_AIRSPEED_PRESENT
263 cas2tas(airspeedData.CalibratedAirspeed, -positionActual_Down,
267 airspeedData.TrueAirspeed =
268 cas2tas(airspeedData.CalibratedAirspeed, -positionActual_Down,
274 airspeedData.BaroConnected = BAROAIRSPEED_BAROCONNECTED_FALSE;
275 airspeedData.SensorValue = 12345;
281 #ifdef GPS_AIRSPEED_PRESENT
282 float v_air_GPS = -1.0f;
287 #ifdef BARO_AIRSPEED_PRESENT
288 float delT = (lastSysTime - lastLoopTime) / 1000.0
f;
290 if ( ((lastSysTime - lastGPSTime) > 1000 ||
airspeedSensorType==AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_GPSONLY)
304 airspeedData.GPSAirspeed = v_air_GPS;
306 #ifdef BARO_AIRSPEED_PRESENT
307 if (airspeedData.BaroConnected==BAROAIRSPEED_BAROCONNECTED_TRUE) {
309 float airspeedErr = v_air_GPS - airspeed_tas_baro;
310 airspeedErrInt += airspeedErr * delT;
313 airspeedErrInt = airspeedErrInt >
315 airspeedErrInt = airspeedErrInt <
332 airspeedData.TrueAirspeed = v_air_GPS*(alpha) + airspeedData.TrueAirspeed*(1.0f-alpha);
335 int16_t groundTemperature_10;
336 float groundTemperature;
337 float positionActual_Down;
339 PositionActualDownGet(&positionActual_Down);
340 HomeLocationGroundTemperatureGet(&groundTemperature_10);
341 groundTemperature = groundTemperature_10/10;
347 airspeedData.CalibratedAirspeed =
tas2cas(airspeedData.TrueAirspeed, -positionActual_Down, &air_STP);
350 #ifdef BARO_AIRSPEED_PRESENT
351 else if (airspeedData.BaroConnected==BAROAIRSPEED_BAROCONNECTED_TRUE) {
354 airspeedData.TrueAirspeed = airspeed_tas_baro*(alpha) + airspeedData.TrueAirspeed*(1.0f-alpha);
359 airspeedActualData.TrueAirspeed = airspeedData.TrueAirspeed;
360 airspeedActualData.CalibratedAirspeed = airspeedData.CalibratedAirspeed;
361 BaroAirspeedSet(&airspeedData);
362 AirspeedActualSet(&airspeedActualData);
366 #ifdef BARO_AIRSPEED_PRESENT
370 switch (airspeedSensorType) {
371 case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV7002:
372 case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV5004:
373 case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_RAWANALOG:
376 case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3:
381 baroAirspeedData->BaroConnected = BAROAIRSPEED_BAROCONNECTED_FALSE;
float cas2tas(float CAS, float altitude, struct AirParameters *air)
cas2tas calculate TAS from CAS and altitude. http://en.wikipedia.org/wiki/Airspeed ...
struct AirParameters initialize_air_structure()
initialize_air_structure Initializes the structure with standard-temperature-pressure values ...
uint32_t PIOS_Thread_Systime(void)
int32_t gps_airspeedInitialize()
#define BARO_TEMPERATURE_OFFSET
MODULE_INITCALL(AirspeedInitialize, AirspeedStart)
static bool module_enabled
float air_temperature_at_surface
Read airspeed from analog sensor.
void UAVObjCbSetFlag(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
static struct pios_thread * taskHandle
#define GPS_AIRSPEED_TIME_CONSTANT_MS
void PIOS_MPXV5004_UpdateCalibration(uint16_t zeroPoint)
Calculate airspeed using GPS.
static uint8_t airspeedSensorType
Airspeed module, reads temperature and pressure from BMP085.
void baro_airspeedGetETASV3(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
float tas2cas(float TAS, float altitude, struct AirParameters *air)
tas2cas calculate CAS from TAS and altitude. http://en.wikipedia.org/wiki/Airspeed ...
static volatile FlightStatsSettingsData settings
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
void PIOS_MPXV7002_UpdateCalibration(uint16_t zeroPoint)
static float tasFilterTau
static void airspeedTask(void *parameters)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
#define SAMPLING_DELAY_MS_FALLTHROUGH
void baro_airspeedGetAnalog(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
Header for Coordinate conversions library in coordinate_conversions.c.
static uint16_t gpsSamplePeriod_ms
Includes PiOS and core architecture components.
int32_t AirspeedInitialize()
static void doSettingsUpdate()
volatile bool settingsUpdated
static uint32_t lastSysTime
void gps_airspeedGet(float *v_air_GPS)
void baro_airspeedGet(BaroAirspeedData *baroAirspeedData, uint32_t *lastSysTime, uint8_t airspeedSensorType, int8_t airspeedADCPin)
#define GPS_AIRSPEED_BIAS_KI
#define GPS_AIRSPEED_BIAS_KP