ardupilot/libraries/AP_Baro/AP_Baro_BMP085_hil.cpp

72 lines
1.6 KiB
C++
Raw Normal View History

/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
2011-10-13 11:22:03 -03:00
#include <FastSerial.h>
#include <AP_Baro.h>
#include "AP_Baro_BMP085_hil.h"
2011-10-13 11:22:03 -03:00
// Constructors ////////////////////////////////////////////////////////////////
AP_Baro_BMP085_HIL::AP_Baro_BMP085_HIL()
2011-10-13 11:22:03 -03:00
{
}
// Public Methods //////////////////////////////////////////////////////////////
bool AP_Baro_BMP085_HIL::init(AP_PeriodicProcess * scheduler)
2011-10-13 11:22:03 -03:00
{
BMP085_State=1;
return true;
2011-10-13 11:22:03 -03:00
}
// Read the sensor. This is a state machine
// We read one time Temperature (state = 1) and then 4 times Pressure (states 2-5)
2011-12-11 00:30:24 -04:00
uint8_t AP_Baro_BMP085_HIL::read()
2011-10-13 11:22:03 -03:00
{
uint8_t result = 0;
if (_count != 0) {
result = 1;
Press = _pressure_sum / _count;
Temp = _temperature_sum / _count;
_pressure_samples = _count;
_count = 0;
_pressure_sum = 0;
_temperature_sum = 0;
2011-10-13 11:22:03 -03:00
}
return result;
2011-10-13 11:22:03 -03:00
}
void AP_Baro_BMP085_HIL::setHIL(float _Temp, float _Press)
2011-10-13 11:22:03 -03:00
{
_count++;
_pressure_sum += _Press;
_temperature_sum += _Temp;
if (_count == 128) {
// we have summed 128 values. This only happens
// when we stop reading the barometer for a long time
// (more than 1.2 seconds)
_count = 64;
_pressure_sum /= 2;
_temperature_sum /= 2;
}
healthy = true;
_last_update = millis();
2011-10-13 11:22:03 -03:00
}
2011-12-11 00:30:24 -04:00
int32_t AP_Baro_BMP085_HIL::get_pressure() {
return Press;
}
int16_t AP_Baro_BMP085_HIL::get_temperature() {
return Temp;
}
int32_t AP_Baro_BMP085_HIL::get_raw_pressure() {
return Press;
}
int32_t AP_Baro_BMP085_HIL::get_raw_temp() {
return Temp;
}