Browse Source

AP_Baro: added averaging to PX4 baro driver

master
Andrew Tridgell 12 years ago
parent
commit
4fe7ad6267
  1. 23
      libraries/AP_Baro/AP_Baro_PX4.cpp
  2. 3
      libraries/AP_Baro/AP_Baro_PX4.h

23
libraries/AP_Baro/AP_Baro_PX4.cpp

@ -20,16 +20,19 @@ extern const AP_HAL::HAL& hal; @@ -20,16 +20,19 @@ extern const AP_HAL::HAL& hal;
// Public Methods //////////////////////////////////////////////////////////////
bool AP_Baro_PX4::init(void)
{
_baro_fd = open(BARO_DEVICE_PATH, O_RDONLY);
if (_baro_fd < 0) {
hal.scheduler->panic("Unable to open " BARO_DEVICE_PATH);
}
/* set the driver to poll at 150Hz */
ioctl(_baro_fd, SENSORIOCSPOLLRATE, 150);
// average over up to 10 samples
ioctl(_baro_fd, SENSORIOCSQUEUEDEPTH, 10);
if (_baro_fd == -1) {
_baro_fd = open(BARO_DEVICE_PATH, O_RDONLY);
if (_baro_fd < 0) {
hal.scheduler->panic("Unable to open " BARO_DEVICE_PATH);
}
/* set the driver to poll at 150Hz */
ioctl(_baro_fd, SENSORIOCSPOLLRATE, 150);
// average over up to 10 samples
ioctl(_baro_fd, SENSORIOCSQUEUEDEPTH, 10);
hal.console->printf("AP_Baro_PX4: init done fd=%d\n", _baro_fd);
}
return true;
}

3
libraries/AP_Baro/AP_Baro_PX4.h

@ -8,6 +8,9 @@ @@ -8,6 +8,9 @@
class AP_Baro_PX4 : public AP_Baro
{
public:
AP_Baro_PX4() : AP_Baro() {
_baro_fd = -1;
}
bool init();
uint8_t read();
float get_pressure();

Loading…
Cancel
Save