mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 07:33:33 +08:00
move baro and magnetometer data out of sensor_combined
This commit is contained in:
@@ -349,7 +349,7 @@ MS5611::init()
|
||||
|
||||
if (autodetect) {
|
||||
if (_device_type == MS5611_DEVICE) {
|
||||
if (brp.altitude > 5300.f) {
|
||||
if (brp.pressure < 520.0f) {
|
||||
/* This is likely not this device, try again */
|
||||
_device_type = MS5607_DEVICE;
|
||||
_measure_phase = 0;
|
||||
@@ -358,8 +358,8 @@ MS5611::init()
|
||||
}
|
||||
|
||||
} else if (_device_type == MS5607_DEVICE) {
|
||||
if (brp.altitude > 5300.f) {
|
||||
/* Both devices returned very high altitude;
|
||||
if (brp.pressure < 520.0f) {
|
||||
/* Both devices returned a very low pressure;
|
||||
* have fun on Everest using MS5611 */
|
||||
_device_type = MS5611_DEVICE;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
|
||||
#include <uORB/topics/battery_status.h>
|
||||
#include <uORB/topics/sensor_combined.h>
|
||||
#include <uORB/topics/vehicle_air_data.h>
|
||||
#include <uORB/topics/vehicle_global_position.h>
|
||||
#include <uORB/topics/vehicle_gps_position.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
@@ -65,10 +66,12 @@ struct frsky_subscription_data_s {
|
||||
struct battery_status_s battery_status;
|
||||
struct vehicle_global_position_s global_pos;
|
||||
struct sensor_combined_s sensor_combined;
|
||||
struct vehicle_air_data_s airdata;
|
||||
struct vehicle_gps_position_s vehicle_gps_position;
|
||||
uint8_t current_flight_mode; // == vehicle_status.nav_state
|
||||
|
||||
int battery_status_sub;
|
||||
int vehicle_air_data_sub;
|
||||
int vehicle_global_position_sub;
|
||||
int sensor_sub;
|
||||
int vehicle_gps_position_sub;
|
||||
@@ -89,6 +92,7 @@ bool frsky_init()
|
||||
}
|
||||
|
||||
subscription_data->battery_status_sub = orb_subscribe(ORB_ID(battery_status));
|
||||
subscription_data->vehicle_air_data_sub = orb_subscribe(ORB_ID(vehicle_air_data));
|
||||
subscription_data->vehicle_global_position_sub = orb_subscribe(ORB_ID(vehicle_global_position));
|
||||
subscription_data->sensor_sub = orb_subscribe(ORB_ID(sensor_combined));
|
||||
subscription_data->vehicle_gps_position_sub = orb_subscribe(ORB_ID(vehicle_gps_position));
|
||||
@@ -168,6 +172,12 @@ void frsky_update_topics()
|
||||
orb_copy(ORB_ID(sensor_combined), subs->sensor_sub, &subs->sensor_combined);
|
||||
}
|
||||
|
||||
orb_check(subs->vehicle_air_data_sub, &updated);
|
||||
|
||||
if (updated) {
|
||||
orb_copy(ORB_ID(vehicle_air_data), subs->vehicle_air_data_sub, &subs->airdata);
|
||||
}
|
||||
|
||||
/* get a local copy of the vehicle status */
|
||||
orb_check(subs->vehicle_status_sub, &updated);
|
||||
|
||||
@@ -212,10 +222,8 @@ void frsky_send_frame1(int uart)
|
||||
frsky_send_data(uart, FRSKY_ID_ACCEL_Y, roundf(subs->sensor_combined.accelerometer_m_s2[1] * 1000.0f));
|
||||
frsky_send_data(uart, FRSKY_ID_ACCEL_Z, roundf(subs->sensor_combined.accelerometer_m_s2[2] * 1000.0f));
|
||||
|
||||
frsky_send_data(uart, FRSKY_ID_BARO_ALT_BP,
|
||||
subs->sensor_combined.baro_alt_meter);
|
||||
frsky_send_data(uart, FRSKY_ID_BARO_ALT_AP,
|
||||
roundf(frac(subs->sensor_combined.baro_alt_meter) * 100.0f));
|
||||
frsky_send_data(uart, FRSKY_ID_BARO_ALT_BP, subs->airdata.baro_alt_meter);
|
||||
frsky_send_data(uart, FRSKY_ID_BARO_ALT_AP, roundf(frac(subs->airdata.baro_alt_meter) * 100.0f));
|
||||
|
||||
frsky_send_data(uart, FRSKY_ID_VFAS,
|
||||
roundf(subs->battery_status.voltage_v * 10.0f));
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
#include <systemlib/err.h>
|
||||
#include <termios.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <uORB/topics/sensor_combined.h>
|
||||
#include <uORB/topics/vehicle_air_data.h>
|
||||
#include <math.h> // NAN
|
||||
|
||||
#include "sPort_data.h"
|
||||
@@ -319,11 +319,9 @@ static int frsky_telemetry_thread_main(int argc, char *argv[])
|
||||
|
||||
PX4_INFO("sending FrSky SmartPort telemetry");
|
||||
|
||||
struct sensor_combined_s sensor_combined = {};
|
||||
|
||||
float filtered_alt = NAN;
|
||||
float last_baro_alt = 0.f;
|
||||
int sensor_sub = orb_subscribe(ORB_ID(sensor_combined));
|
||||
int airdata_sub = orb_subscribe(ORB_ID(vehicle_air_data));
|
||||
|
||||
uint32_t lastBATV_ms = 0;
|
||||
uint32_t lastCUR_ms = 0;
|
||||
@@ -364,17 +362,18 @@ static int frsky_telemetry_thread_main(int argc, char *argv[])
|
||||
/* get a local copy of the current sensor values
|
||||
* in order to apply a lowpass filter to baro pressure.
|
||||
*/
|
||||
bool sensor_updated;
|
||||
orb_check(sensor_sub, &sensor_updated);
|
||||
bool sensor_updated = false;
|
||||
orb_check(airdata_sub, &sensor_updated);
|
||||
|
||||
if (sensor_updated) {
|
||||
orb_copy(ORB_ID(sensor_combined), sensor_sub, &sensor_combined);
|
||||
struct vehicle_air_data_s airdata;
|
||||
orb_copy(ORB_ID(vehicle_air_data), airdata_sub, &airdata);
|
||||
|
||||
if (isnan(filtered_alt)) {
|
||||
filtered_alt = sensor_combined.baro_alt_meter;
|
||||
filtered_alt = airdata.baro_alt_meter;
|
||||
|
||||
} else {
|
||||
filtered_alt = .05f * sensor_combined.baro_alt_meter + .95f * filtered_alt;
|
||||
filtered_alt = .05f * airdata.baro_alt_meter + .95f * filtered_alt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
|
||||
#include <uORB/topics/battery_status.h>
|
||||
#include <uORB/topics/sensor_combined.h>
|
||||
#include <uORB/topics/vehicle_air_data.h>
|
||||
#include <uORB/topics/vehicle_global_position.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
@@ -69,12 +70,14 @@ struct s_port_subscription_data_s {
|
||||
int battery_status_sub;
|
||||
int vehicle_status_sub;
|
||||
int gps_position_sub;
|
||||
int vehicle_air_data_sub;
|
||||
|
||||
struct sensor_combined_s sensor_combined;
|
||||
struct vehicle_global_position_s global_pos;
|
||||
struct vehicle_local_position_s local_pos;
|
||||
struct battery_status_s battery_status;
|
||||
struct vehicle_status_s vehicle_status;
|
||||
struct vehicle_air_data_s vehicle_air_data;
|
||||
struct vehicle_gps_position_s gps_position;
|
||||
};
|
||||
|
||||
@@ -92,13 +95,13 @@ bool sPort_init()
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
s_port_subscription_data->sensor_sub = orb_subscribe(ORB_ID(sensor_combined));
|
||||
s_port_subscription_data->global_position_sub = orb_subscribe(ORB_ID(vehicle_global_position));
|
||||
s_port_subscription_data->local_position_sub = orb_subscribe(ORB_ID(vehicle_local_position));
|
||||
s_port_subscription_data->battery_status_sub = orb_subscribe(ORB_ID(battery_status));
|
||||
s_port_subscription_data->vehicle_status_sub = orb_subscribe(ORB_ID(vehicle_status));
|
||||
s_port_subscription_data->gps_position_sub = orb_subscribe(ORB_ID(vehicle_gps_position));
|
||||
s_port_subscription_data->vehicle_air_data_sub = orb_subscribe(ORB_ID(vehicle_air_data));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -112,6 +115,7 @@ void sPort_deinit()
|
||||
orb_unsubscribe(s_port_subscription_data->battery_status_sub);
|
||||
orb_unsubscribe(s_port_subscription_data->vehicle_status_sub);
|
||||
orb_unsubscribe(s_port_subscription_data->gps_position_sub);
|
||||
orb_unsubscribe(s_port_subscription_data->vehicle_air_data_sub);
|
||||
free(s_port_subscription_data);
|
||||
s_port_subscription_data = NULL;
|
||||
}
|
||||
@@ -164,6 +168,13 @@ void sPort_update_topics()
|
||||
orb_copy(ORB_ID(vehicle_gps_position), subs->gps_position_sub, &subs->gps_position);
|
||||
}
|
||||
|
||||
/* get a local copy of the gps position data */
|
||||
orb_check(subs->vehicle_air_data_sub, &updated);
|
||||
|
||||
if (updated) {
|
||||
orb_copy(ORB_ID(vehicle_air_data), subs->vehicle_air_data_sub, &subs->vehicle_air_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +265,7 @@ void sPort_send_CUR(int uart)
|
||||
void sPort_send_ALT(int uart)
|
||||
{
|
||||
/* send data */
|
||||
uint32_t alt = (int)(100 * s_port_subscription_data->sensor_combined.baro_alt_meter);
|
||||
uint32_t alt = (int)(100 * s_port_subscription_data->vehicle_air_data.baro_alt_meter);
|
||||
sPort_send_data(uart, SMARTPORT_ID_ALT, alt);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include <uORB/topics/battery_status.h>
|
||||
#include <uORB/topics/esc_status.h>
|
||||
#include <uORB/topics/home_position.h>
|
||||
#include <uORB/topics/sensor_combined.h>
|
||||
#include <uORB/topics/vehicle_air_data.h>
|
||||
#include <uORB/topics/vehicle_gps_position.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
@@ -59,7 +59,7 @@
|
||||
static int _battery_sub = -1;
|
||||
static int _gps_sub = -1;
|
||||
static int _home_sub = -1;
|
||||
static int _sensor_sub = -1;
|
||||
static int _airdata_sub = -1;
|
||||
static int _airspeed_sub = -1;
|
||||
static int _esc_sub = -1;
|
||||
|
||||
@@ -75,7 +75,7 @@ init_sub_messages(void)
|
||||
_battery_sub = orb_subscribe(ORB_ID(battery_status));
|
||||
_gps_sub = orb_subscribe(ORB_ID(vehicle_gps_position));
|
||||
_home_sub = orb_subscribe(ORB_ID(home_position));
|
||||
_sensor_sub = orb_subscribe(ORB_ID(sensor_combined));
|
||||
_airdata_sub = orb_subscribe(ORB_ID(vehicle_air_data));
|
||||
_airspeed_sub = orb_subscribe(ORB_ID(airspeed));
|
||||
_esc_sub = orb_subscribe(ORB_ID(esc_status));
|
||||
}
|
||||
@@ -132,9 +132,8 @@ void
|
||||
build_eam_response(uint8_t *buffer, size_t *size)
|
||||
{
|
||||
/* get a local copy of the current sensor values */
|
||||
struct sensor_combined_s raw;
|
||||
memset(&raw, 0, sizeof(raw));
|
||||
orb_copy(ORB_ID(sensor_combined), _sensor_sub, &raw);
|
||||
vehicle_air_data_s airdata = {};
|
||||
orb_copy(ORB_ID(vehicle_air_data), _airdata_sub, &airdata);
|
||||
|
||||
/* get a local copy of the battery data */
|
||||
struct battery_status_s battery;
|
||||
@@ -149,12 +148,12 @@ build_eam_response(uint8_t *buffer, size_t *size)
|
||||
msg.eam_sensor_id = EAM_SENSOR_ID;
|
||||
msg.sensor_text_id = EAM_SENSOR_TEXT_ID;
|
||||
|
||||
msg.temperature1 = (uint8_t)(raw.baro_temp_celcius + 20);
|
||||
msg.temperature1 = (uint8_t)(airdata.baro_temp_celcius + 20);
|
||||
msg.temperature2 = msg.temperature1 - BOARD_TEMP_OFFSET_DEG;
|
||||
|
||||
msg.main_voltage_L = (uint8_t)(battery.voltage_v * 10);
|
||||
|
||||
uint16_t alt = (uint16_t)(raw.baro_alt_meter + 500);
|
||||
uint16_t alt = (uint16_t)(airdata.baro_alt_meter + 500);
|
||||
msg.altitude_L = (uint8_t)alt & 0xff;
|
||||
msg.altitude_H = (uint8_t)(alt >> 8) & 0xff;
|
||||
|
||||
@@ -209,11 +208,6 @@ build_gam_response(uint8_t *buffer, size_t *size)
|
||||
void
|
||||
build_gps_response(uint8_t *buffer, size_t *size)
|
||||
{
|
||||
/* get a local copy of the current sensor values */
|
||||
struct sensor_combined_s raw;
|
||||
memset(&raw, 0, sizeof(raw));
|
||||
orb_copy(ORB_ID(sensor_combined), _sensor_sub, &raw);
|
||||
|
||||
/* get a local copy of the battery data */
|
||||
struct vehicle_gps_position_s gps;
|
||||
memset(&gps, 0, sizeof(gps));
|
||||
|
||||
Reference in New Issue
Block a user