We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5e274ad commit b12be53Copy full SHA for b12be53
src/common/base_classes/Sensor.cpp
@@ -18,7 +18,12 @@ void Sensor::update() {
18
float Sensor::getVelocity() {
19
// calculate sample time
20
float Ts = (angle_prev_ts - vel_angle_prev_ts)*1e-6;
21
- // TODO handle overflow - we do need to reset vel_angle_prev_ts
+ if (Ts < 0.0f) { // handle micros() overflow - we need to reset vel_angle_prev_ts
22
+ vel_angle_prev = angle_prev;
23
+ vel_full_rotations = full_rotations;
24
+ vel_angle_prev_ts = angle_prev_ts;
25
+ return velocity;
26
+ }
27
if (Ts < min_elapsed_time) return velocity; // don't update velocity if deltaT is too small
28
29
velocity = ( (float)(full_rotations - vel_full_rotations)*_2PI + (angle_prev - vel_angle_prev) ) / Ts;
0 commit comments