Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent overflow of dt in Integrator class #24202

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions msg/VehicleImu.msg
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ uint32 gyro_device_id # Gyroscope unique device ID for the sensor that
float32[3] delta_angle # delta angle about the FRD body frame XYZ-axis in rad over the integration time frame (delta_angle_dt)
float32[3] delta_velocity # delta velocity in the FRD body frame XYZ-axis in m/s over the integration time frame (delta_velocity_dt)

uint16 delta_angle_dt # integration period in microseconds
uint16 delta_velocity_dt # integration period in microseconds
uint32 delta_angle_dt # integration period in microseconds
uint32 delta_velocity_dt # integration period in microseconds

uint8 CLIPPING_X = 1
uint8 CLIPPING_Y = 2
Expand Down
6 changes: 3 additions & 3 deletions src/modules/sensors/Integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Integrator
~Integrator() = default;

static constexpr float DT_MIN{1e-6f}; // 1 microsecond
static constexpr float DT_MAX{static_cast<float>(UINT16_MAX) * 1e-6f};
static constexpr float DT_MAX{static_cast<float>(UINT32_MAX) * 1e-6f};

/**
* Put an item into the integral.
Expand Down Expand Up @@ -111,7 +111,7 @@ class Integrator
* @param integral_dt Get the dt in us of the current integration.
* @return true if integral valid
*/
bool reset(matrix::Vector3f &integral, uint16_t &integral_dt)
bool reset(matrix::Vector3f &integral, uint32_t &integral_dt)
{
if (integral_ready()) {
integral = _alpha;
Expand Down Expand Up @@ -200,7 +200,7 @@ class IntegratorConing : public Integrator
* @param integral_dt Get the dt in us of the current integration.
* @return true if integral valid
*/
bool reset(matrix::Vector3f &integral, uint16_t &integral_dt)
bool reset(matrix::Vector3f &integral, uint32_t &integral_dt)
{
if (Integrator::reset(integral, integral_dt)) {
// apply coning corrections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void VehicleOpticalFlow::Run()
}

Vector3f delta_angle{NAN, NAN, NAN};
uint16_t delta_angle_dt;
uint32_t delta_angle_dt;

if (_gyro_integrator.reset(delta_angle, delta_angle_dt)) {
_delta_angle += delta_angle;
Expand Down
Loading