Path: blob/master/libraries/AP_Airspeed/AP_Airspeed_Backend.h
9743 views
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/14#pragma once1516/*17backend driver class for airspeed18*/1920#include "AP_Airspeed_config.h"2122#if AP_AIRSPEED_ENABLED2324#include <AP_Common/AP_Common.h>25#include <AP_HAL/AP_HAL_Boards.h>26#include <AP_HAL/Semaphores.h>27#include "AP_Airspeed.h"28#include <AP_MSP/msp_sensors.h>2930class AP_Airspeed_Backend {31public:32AP_Airspeed_Backend(AP_Airspeed &frontend, uint8_t instance);33virtual ~AP_Airspeed_Backend() {}3435// probe and initialise the sensor36virtual bool init(void) = 0;3738// return the current differential_pressure in Pascal39virtual bool get_differential_pressure(float &pressure) {return false;}4041// return the current temperature in degrees C, if available42virtual bool get_temperature(float &temperature) = 0;4344// true if sensor reads airspeed directly, not via pressure45virtual bool has_airspeed() {return false;}4647// return airspeed in m/s if available48virtual bool get_airspeed(float& airspeed) {return false;}4950virtual void handle_msp(const MSP::msp_airspeed_data_message_t &pkt) {}51#if AP_AIRSPEED_EXTERNAL_ENABLED52virtual void handle_external(const AP_ExternalAHRS::airspeed_data_message_t &pkt) {}53#endif5455#if AP_AIRSPEED_HYGROMETER_ENABLE56// optional hygrometer support57virtual bool get_hygrometer(uint32_t &last_sample_ms, float &temperature, float &humidity) { return false; }58#endif5960protected:61int8_t get_pin(void) const;62float get_psi_range(void) const;63uint8_t get_bus(void) const;64bool bus_is_configured(void) const;65uint8_t get_instance(void) const {66return instance;67}6869// see if voltage correction should be disabled70bool disable_voltage_correction(void) const {71return (frontend._options.get() & AP_Airspeed::OptionsMask::DISABLE_VOLTAGE_CORRECTION) != 0;72}7374AP_Airspeed::pitot_tube_order get_tube_order(void) const {75#ifndef HAL_BUILD_AP_PERIPH76return AP_Airspeed::pitot_tube_order(frontend.param[instance].tube_order.get());77#else78return AP_Airspeed::pitot_tube_order::PITOT_TUBE_ORDER_AUTO;79#endif80}8182// semaphore for access to shared frontend data83HAL_Semaphore sem;8485float get_airspeed_ratio(void) const {86return frontend.get_airspeed_ratio(instance);87}8889// some sensors use zero offsets90void set_use_zero_offset(void) {91frontend.state[instance].cal.state = AP_Airspeed::CalibrationState::NOT_REQUIRED_ZERO_OFFSET;92#ifndef HAL_BUILD_AP_PERIPH93frontend.param[instance].offset.set(0.0);94#endif95}9697// set use98void set_use(int8_t use) {99#ifndef HAL_BUILD_AP_PERIPH100frontend.param[instance].use.set(use);101#endif102}103104// set bus ID of this instance, for ARSPD_DEVID parameters105void set_bus_id(uint32_t id);106107enum class DevType {108SITL = 0x01,109MS4525 = 0x02,110MS5525 = 0x03,111DLVR = 0x04,112MSP = 0x05,113SDP3X = 0x06,114UAVCAN = 0x07,115ANALOG = 0x08,116NMEA = 0x09,117ASP5033 = 0x0A,118AUAV = 0x0B,119};120121private:122AP_Airspeed &frontend;123uint8_t instance;124};125126#endif // AP_AIRSPEED_ENABLED127128129