Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/AP_Periph/airspeed.cpp
Views: 1798
#include "AP_Periph.h"12#ifdef HAL_PERIPH_ENABLE_AIRSPEED34/*5airspeed support6*/78#include <dronecan_msgs.h>910#ifndef AP_PERIPH_PROBE_CONTINUOUS11#define AP_PERIPH_PROBE_CONTINUOUS 012#endif1314/*15update CAN airspeed16*/17void AP_Periph_FW::can_airspeed_update(void)18{19if (!airspeed.enabled()) {20return;21}22#if AP_PERIPH_PROBE_CONTINUOUS23if (option_is_set(PeriphOptions::PROBE_CONTINUOUS) && !hal.util->get_soft_armed() && !airspeed.healthy()) {24uint32_t now = AP_HAL::millis();25static uint32_t last_probe_ms;26if (now - last_probe_ms >= 1000) {27last_probe_ms = now;28airspeed.allocate();29}30}31#endif32uint32_t now = AP_HAL::millis();33if (now - last_airspeed_update_ms < 50) {34// max 20Hz data35return;36}37last_airspeed_update_ms = now;38airspeed.update();39if (!airspeed.healthy()) {40// don't send any data41return;42}43const float press = airspeed.get_corrected_pressure();44float temp;45if (!airspeed.get_temperature(temp)) {46temp = nanf("");47} else {48temp = C_TO_KELVIN(temp);49}5051uavcan_equipment_air_data_RawAirData pkt {};5253// unfilled elements are NaN54pkt.static_pressure = nanf("");55pkt.static_pressure_sensor_temperature = nanf("");56pkt.differential_pressure_sensor_temperature = nanf("");57pkt.pitot_temperature = nanf("");5859// populate the elements we have60pkt.differential_pressure = press;61pkt.static_air_temperature = temp;6263// if a Pitot tube temperature sensor is available, use it64#if AP_TEMPERATURE_SENSOR_ENABLED65for (uint8_t i=0; i<temperature_sensor.num_instances(); i++) {66float temp_pitot;67if (temperature_sensor.get_source(i) == AP_TemperatureSensor_Params::Source::Pitot_tube && temperature_sensor.get_temperature(temp_pitot, i)) {68pkt.pitot_temperature = C_TO_KELVIN(temp_pitot);69break;70}71}72#endif7374uint8_t buffer[UAVCAN_EQUIPMENT_AIR_DATA_RAWAIRDATA_MAX_SIZE];75uint16_t total_size = uavcan_equipment_air_data_RawAirData_encode(&pkt, buffer, !periph.canfdout());7677canard_broadcast(UAVCAN_EQUIPMENT_AIR_DATA_RAWAIRDATA_SIGNATURE,78UAVCAN_EQUIPMENT_AIR_DATA_RAWAIRDATA_ID,79CANARD_TRANSFER_PRIORITY_LOW,80&buffer[0],81total_size);82}8384#endif // HAL_PERIPH_ENABLE_AIRSPEED858687