mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 14:53:33 +08:00
add IMU_GYRO_RATEMAX to optionally limit gyro control publication rate
This commit is contained in:
@@ -123,12 +123,26 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
|
||||
// Filtered values
|
||||
const matrix::Vector3f val_filtered{_filter.apply(val_calibrated)};
|
||||
|
||||
|
||||
// publish control data (filtered gyro) immediately
|
||||
bool publish_control = true;
|
||||
sensor_gyro_control_s &control = _sensor_gyro_control_pub.get();
|
||||
control.timestamp_sample = timestamp;
|
||||
val_filtered.copyTo(control.xyz);
|
||||
control.timestamp = hrt_absolute_time();
|
||||
_sensor_gyro_control_pub.update(); // publish
|
||||
|
||||
if (_param_imu_gyro_rate_max.get() > 0) {
|
||||
const uint64_t interval = 1e6f / _param_imu_gyro_rate_max.get();
|
||||
|
||||
if (hrt_elapsed_time(&control.timestamp_sample) < interval) {
|
||||
publish_control = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (publish_control) {
|
||||
control.timestamp_sample = timestamp;
|
||||
val_filtered.copyTo(control.xyz);
|
||||
control.timestamp = hrt_absolute_time();
|
||||
_sensor_gyro_control_pub.update(); // publish
|
||||
}
|
||||
|
||||
|
||||
// Integrated values
|
||||
matrix::Vector3f integrated_value;
|
||||
|
||||
@@ -85,7 +85,8 @@ private:
|
||||
unsigned _sample_rate{1000};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::IMU_GYRO_CUTOFF>) _param_imu_gyro_cutoff
|
||||
(ParamFloat<px4::params::IMU_GYRO_CUTOFF>) _param_imu_gyro_cutoff,
|
||||
(ParamInt<px4::params::IMU_GYRO_RATEMAX>) _param_imu_gyro_rate_max
|
||||
)
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user