mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 06:51:35 +08:00
sensors: no temperature compensation in HITL
Temperature compensation is not supported in HITL. Therefore, don't try and fail. This basically removes the confusing error message that we get in HITL.
This commit is contained in:
@@ -95,6 +95,7 @@
|
|||||||
|
|
||||||
using namespace DriverFramework;
|
using namespace DriverFramework;
|
||||||
using namespace sensors;
|
using namespace sensors;
|
||||||
|
using namespace time_literals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analog layout:
|
* Analog layout:
|
||||||
@@ -584,13 +585,11 @@ Sensors::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
sensor_combined_s raw = {};
|
sensor_combined_s raw = {};
|
||||||
|
sensor_preflight_s preflt = {};
|
||||||
vehicle_air_data_s airdata = {};
|
vehicle_air_data_s airdata = {};
|
||||||
vehicle_magnetometer_s magnetometer = {};
|
vehicle_magnetometer_s magnetometer = {};
|
||||||
|
|
||||||
struct sensor_preflight_s preflt = {};
|
|
||||||
|
|
||||||
_rc_update.init();
|
_rc_update.init();
|
||||||
|
|
||||||
_voted_sensors_update.init(raw);
|
_voted_sensors_update.init(raw);
|
||||||
|
|
||||||
/* (re)load params and calibration */
|
/* (re)load params and calibration */
|
||||||
@@ -600,11 +599,8 @@ Sensors::run()
|
|||||||
* do subscriptions
|
* do subscriptions
|
||||||
*/
|
*/
|
||||||
_diff_pres_sub = orb_subscribe(ORB_ID(differential_pressure));
|
_diff_pres_sub = orb_subscribe(ORB_ID(differential_pressure));
|
||||||
|
|
||||||
_vcontrol_mode_sub = orb_subscribe(ORB_ID(vehicle_control_mode));
|
_vcontrol_mode_sub = orb_subscribe(ORB_ID(vehicle_control_mode));
|
||||||
|
|
||||||
_params_sub = orb_subscribe(ORB_ID(parameter_update));
|
_params_sub = orb_subscribe(ORB_ID(parameter_update));
|
||||||
|
|
||||||
_actuator_ctrl_0_sub = orb_subscribe(ORB_ID(actuator_controls_0));
|
_actuator_ctrl_0_sub = orb_subscribe(ORB_ID(actuator_controls_0));
|
||||||
|
|
||||||
/* get a set of initial values */
|
/* get a set of initial values */
|
||||||
@@ -614,18 +610,10 @@ Sensors::run()
|
|||||||
|
|
||||||
_rc_update.rc_parameter_map_poll(_parameter_handles, true /* forced */);
|
_rc_update.rc_parameter_map_poll(_parameter_handles, true /* forced */);
|
||||||
|
|
||||||
/* advertise the sensor_preflight topic and make the initial publication */
|
|
||||||
preflt.accel_inconsistency_m_s_s = 0.0f;
|
|
||||||
|
|
||||||
preflt.gyro_inconsistency_rad_s = 0.0f;
|
|
||||||
|
|
||||||
preflt.mag_inconsistency_ga = 0.0f;
|
|
||||||
|
|
||||||
_sensor_preflight = orb_advertise(ORB_ID(sensor_preflight), &preflt);
|
_sensor_preflight = orb_advertise(ORB_ID(sensor_preflight), &preflt);
|
||||||
|
|
||||||
/* wakeup source */
|
/* wakeup source */
|
||||||
px4_pollfd_struct_t poll_fds = {};
|
px4_pollfd_struct_t poll_fds = {};
|
||||||
|
|
||||||
poll_fds.events = POLLIN;
|
poll_fds.events = POLLIN;
|
||||||
|
|
||||||
uint64_t last_config_update = hrt_absolute_time();
|
uint64_t last_config_update = hrt_absolute_time();
|
||||||
@@ -704,7 +692,7 @@ Sensors::run()
|
|||||||
/* keep adding sensors as long as we are not armed,
|
/* keep adding sensors as long as we are not armed,
|
||||||
* when not adding sensors poll for param updates
|
* when not adding sensors poll for param updates
|
||||||
*/
|
*/
|
||||||
if (!_armed && hrt_elapsed_time(&last_config_update) > 500 * 1000) {
|
if (!_armed && hrt_elapsed_time(&last_config_update) > 500_ms) {
|
||||||
_voted_sensors_update.initialize_sensors();
|
_voted_sensors_update.initialize_sensors();
|
||||||
last_config_update = hrt_absolute_time();
|
last_config_update = hrt_absolute_time();
|
||||||
|
|
||||||
@@ -846,7 +834,7 @@ Sensors *Sensors::instantiate(int argc, char *argv[])
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Sensors(hil_enabled);;
|
return new Sensors(hil_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sensors_main(int argc, char *argv[])
|
int sensors_main(int argc, char *argv[])
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ int TemperatureCompensation::initialize_parameter_handles(ParameterHandles ¶
|
|||||||
return PX4_OK;
|
return PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TemperatureCompensation::parameters_update()
|
int TemperatureCompensation::parameters_update(bool hil_enabled)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
@@ -163,7 +163,12 @@ int TemperatureCompensation::parameters_update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* rate gyro calibration parameters */
|
/* rate gyro calibration parameters */
|
||||||
param_get(parameter_handles.gyro_tc_enable, &(_parameters.gyro_tc_enable));
|
if (!hil_enabled) {
|
||||||
|
param_get(parameter_handles.gyro_tc_enable, &_parameters.gyro_tc_enable);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_parameters.gyro_tc_enable = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (_parameters.gyro_tc_enable == 1) {
|
if (_parameters.gyro_tc_enable == 1) {
|
||||||
for (unsigned j = 0; j < GYRO_COUNT_MAX; j++) {
|
for (unsigned j = 0; j < GYRO_COUNT_MAX; j++) {
|
||||||
@@ -196,7 +201,12 @@ int TemperatureCompensation::parameters_update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* accelerometer calibration parameters */
|
/* accelerometer calibration parameters */
|
||||||
param_get(parameter_handles.accel_tc_enable, &(_parameters.accel_tc_enable));
|
if (!hil_enabled) {
|
||||||
|
param_get(parameter_handles.accel_tc_enable, &_parameters.accel_tc_enable);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_parameters.accel_tc_enable = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (_parameters.accel_tc_enable == 1) {
|
if (_parameters.accel_tc_enable == 1) {
|
||||||
for (unsigned j = 0; j < ACCEL_COUNT_MAX; j++) {
|
for (unsigned j = 0; j < ACCEL_COUNT_MAX; j++) {
|
||||||
@@ -229,7 +239,12 @@ int TemperatureCompensation::parameters_update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* barometer calibration parameters */
|
/* barometer calibration parameters */
|
||||||
param_get(parameter_handles.baro_tc_enable, &(_parameters.baro_tc_enable));
|
if (!hil_enabled) {
|
||||||
|
param_get(parameter_handles.baro_tc_enable, &_parameters.baro_tc_enable);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_parameters.baro_tc_enable = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (_parameters.baro_tc_enable == 1) {
|
if (_parameters.baro_tc_enable == 1) {
|
||||||
for (unsigned j = 0; j < BARO_COUNT_MAX; j++) {
|
for (unsigned j = 0; j < BARO_COUNT_MAX; j++) {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class TemperatureCompensation
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/** (re)load the parameters. Make sure to call this on startup as well */
|
/** (re)load the parameters. Make sure to call this on startup as well */
|
||||||
int parameters_update();
|
int parameters_update(bool hil_enabled = false);
|
||||||
|
|
||||||
/** supply information which device_id matches a specific uORB topic_instance
|
/** supply information which device_id matches a specific uORB topic_instance
|
||||||
* (needed if a system has multiple sensors of the same type)
|
* (needed if a system has multiple sensors of the same type)
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ void VotedSensorsUpdate::parameters_update()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* temperature compensation */
|
/* temperature compensation */
|
||||||
_temperature_compensation.parameters_update();
|
_temperature_compensation.parameters_update(_hil_enabled);
|
||||||
|
|
||||||
/* gyro */
|
/* gyro */
|
||||||
for (int topic_instance = 0; topic_instance < GYRO_COUNT_MAX; ++topic_instance) {
|
for (int topic_instance = 0; topic_instance < GYRO_COUNT_MAX; ++topic_instance) {
|
||||||
@@ -602,11 +602,9 @@ void VotedSensorsUpdate::accel_poll(struct sensor_combined_s &raw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle temperature compensation
|
// handle temperature compensation
|
||||||
if (!_hil_enabled) {
|
if (_temperature_compensation.apply_corrections_accel(uorb_index, accel_data, accel_report.temperature,
|
||||||
if (_temperature_compensation.apply_corrections_accel(uorb_index, accel_data, accel_report.temperature,
|
offsets[uorb_index], scales[uorb_index]) == 2) {
|
||||||
offsets[uorb_index], scales[uorb_index]) == 2) {
|
_corrections_changed = true;
|
||||||
_corrections_changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate corrected measurements from sensor to body frame
|
// rotate corrected measurements from sensor to body frame
|
||||||
@@ -711,11 +709,9 @@ void VotedSensorsUpdate::gyro_poll(struct sensor_combined_s &raw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle temperature compensation
|
// handle temperature compensation
|
||||||
if (!_hil_enabled) {
|
if (_temperature_compensation.apply_corrections_gyro(uorb_index, gyro_rate, gyro_report.temperature,
|
||||||
if (_temperature_compensation.apply_corrections_gyro(uorb_index, gyro_rate, gyro_report.temperature,
|
offsets[uorb_index], scales[uorb_index]) == 2) {
|
||||||
offsets[uorb_index], scales[uorb_index]) == 2) {
|
_corrections_changed = true;
|
||||||
_corrections_changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate corrected measurements from sensor to body frame
|
// rotate corrected measurements from sensor to body frame
|
||||||
@@ -829,11 +825,9 @@ void VotedSensorsUpdate::baro_poll(vehicle_air_data_s &airdata)
|
|||||||
float corrected_pressure = 100.0f * baro_report.pressure;
|
float corrected_pressure = 100.0f * baro_report.pressure;
|
||||||
|
|
||||||
// handle temperature compensation
|
// handle temperature compensation
|
||||||
if (!_hil_enabled) {
|
if (_temperature_compensation.apply_corrections_baro(uorb_index, corrected_pressure, baro_report.temperature,
|
||||||
if (_temperature_compensation.apply_corrections_baro(uorb_index, corrected_pressure, baro_report.temperature,
|
offsets[uorb_index], scales[uorb_index]) == 2) {
|
||||||
offsets[uorb_index], scales[uorb_index]) == 2) {
|
_corrections_changed = true;
|
||||||
_corrections_changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// First publication with data
|
// First publication with data
|
||||||
@@ -1080,7 +1074,7 @@ void VotedSensorsUpdate::sensors_poll(sensor_combined_s &raw, vehicle_air_data_s
|
|||||||
baro_poll(airdata);
|
baro_poll(airdata);
|
||||||
|
|
||||||
// publish sensor corrections if necessary
|
// publish sensor corrections if necessary
|
||||||
if (!_hil_enabled && _corrections_changed) {
|
if (_corrections_changed) {
|
||||||
_corrections.timestamp = hrt_absolute_time();
|
_corrections.timestamp = hrt_absolute_time();
|
||||||
|
|
||||||
if (_sensor_correction_pub == nullptr) {
|
if (_sensor_correction_pub == nullptr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user