2012-07-15 22:21:20 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*
|
2012-08-17 03:08:43 -03:00
|
|
|
* APM_Airspeed.cpp - airspeed (pitot) driver
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*/
|
2012-07-15 22:21:20 -03:00
|
|
|
|
|
|
|
#include <FastSerial.h>
|
|
|
|
#include <AP_Common.h>
|
|
|
|
#include <AP_Airspeed.h>
|
|
|
|
#include <LowPassFilter.h>
|
|
|
|
|
|
|
|
// table of user settable parameters
|
|
|
|
const AP_Param::GroupInfo AP_Airspeed::var_info[] PROGMEM = {
|
|
|
|
|
2012-07-16 10:48:47 -03:00
|
|
|
// @Param: ENABLE
|
2012-07-15 22:21:20 -03:00
|
|
|
// @DisplayName: Airspeed enable
|
|
|
|
// @Description: enable airspeed sensor
|
|
|
|
// @Values: 0:Disable,1:Enable
|
2012-08-06 22:02:14 -03:00
|
|
|
AP_GROUPINFO("ENABLE", 0, AP_Airspeed, _enable, 1),
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2012-07-16 10:48:47 -03:00
|
|
|
// @Param: USE
|
2012-07-15 22:21:20 -03:00
|
|
|
// @DisplayName: Airspeed use
|
|
|
|
// @Description: use airspeed for flight control
|
2012-08-17 21:22:51 -03:00
|
|
|
// @Values: 1:Use,0:Don't Use
|
2012-08-06 22:02:14 -03:00
|
|
|
AP_GROUPINFO("USE", 1, AP_Airspeed, _use, 0),
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2012-07-16 10:48:47 -03:00
|
|
|
// @Param: OFFSET
|
2012-07-15 22:21:20 -03:00
|
|
|
// @DisplayName: Airspeed offset
|
|
|
|
// @Description: Airspeed calibration offset
|
|
|
|
// @Increment: 0.1
|
2012-08-06 22:02:14 -03:00
|
|
|
AP_GROUPINFO("OFFSET", 2, AP_Airspeed, _offset, 0),
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2012-07-16 10:48:47 -03:00
|
|
|
// @Param: RATIO
|
2012-07-15 22:21:20 -03:00
|
|
|
// @DisplayName: Airspeed ratio
|
|
|
|
// @Description: Airspeed calibration ratio
|
|
|
|
// @Increment: 0.1
|
2012-08-08 03:36:41 -03:00
|
|
|
AP_GROUPINFO("RATIO", 3, AP_Airspeed, _ratio, 1.9936),
|
2012-07-15 22:21:20 -03:00
|
|
|
|
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
|
|
|
// calibrate the airspeed. This must be called at least once before
|
|
|
|
// the get_airspeed() interface can be used
|
|
|
|
void AP_Airspeed::calibrate(void (*callback)(unsigned long t))
|
|
|
|
{
|
2012-08-17 03:08:43 -03:00
|
|
|
float sum = 0;
|
|
|
|
uint8_t c;
|
|
|
|
if (!_enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_source->read();
|
|
|
|
for (c = 0; c < 10; c++) {
|
|
|
|
callback(100);
|
|
|
|
sum += _source->read();
|
|
|
|
}
|
|
|
|
_airspeed_raw = sum/c;
|
|
|
|
_offset.set_and_save(_airspeed_raw);
|
|
|
|
_airspeed = 0;
|
2012-07-15 22:21:20 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// read the airspeed sensor
|
|
|
|
void AP_Airspeed::read(void)
|
|
|
|
{
|
2012-08-17 03:08:43 -03:00
|
|
|
float airspeed_pressure;
|
|
|
|
if (!_enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_airspeed_raw = _source->read();
|
|
|
|
airspeed_pressure = max((_airspeed_raw - _offset), 0);
|
|
|
|
_airspeed = sqrt(airspeed_pressure * _ratio);
|
2012-07-15 22:21:20 -03:00
|
|
|
}
|