Hey all,
Still working on optimizing my loop time. Running into some code segments from the library:
/** get current angular velocity (rad/s) */
inline float Sensor::getVelocity() {
// calculate sample time
float Ts = (angle_prev_ts - vel_angle_prev_ts)*1e-6f;
if (Ts < 0.0f) { // handle micros() overflow - we need to reset vel_angle_prev_ts
vel_angle_prev = angle_prev;
vel_full_rotations = full_rotations;
vel_angle_prev_ts = angle_prev_ts;
return velocity;
}
Here’s a bit to catch overflows in the microsecond timers. The timestamps are defined as longs however:
long angle_prev_ts=0; // timestamp of last call to getAngle, used for velocity
long vel_angle_prev_ts=0; // last velocity calculation timestamp
If these would be defined as uint32_t’s, like the microsecond timer, the overflow would correct itself through unsigned integer math. That would be a nicer solution, right?