File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ void MagneticSensorI2C::init(){
2929
3030 // I2C communication begin
3131 Wire.begin ();
32-
32+
3333 // velocity calculation init
3434 angle_prev = 0 ;
3535 velocity_calc_timestamp = _micros ();
@@ -66,7 +66,8 @@ float MagneticSensorI2C::getAngle(){
6666// Shaft velocity calculation
6767float MagneticSensorI2C::getVelocity (){
6868 // calculate sample time
69- float Ts = (_micros () - velocity_calc_timestamp)*1e-6 ;
69+ unsigned long now_us = _micros ();
70+ float Ts = (now_us - velocity_calc_timestamp)*1e-6 ;
7071 // quick fix for strange cases (micros overflow)
7172 if (Ts <= 0 || Ts > 0.5 ) Ts = 1e-3 ;
7273
@@ -77,7 +78,7 @@ float MagneticSensorI2C::getVelocity(){
7778
7879 // save variables for future pass
7980 angle_prev = angle_c;
80- velocity_calc_timestamp = _micros () ;
81+ velocity_calc_timestamp = now_us ;
8182 return vel;
8283}
8384
Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ float MagneticSensorSPI::getAngle(){
6868// Shaft velocity calculation
6969float MagneticSensorSPI::getVelocity (){
7070 // calculate sample time
71- float Ts = (_micros () - velocity_calc_timestamp)*1e-6 ;
71+ unsigned long now_us = _micros ();
72+ float Ts = (now_us - velocity_calc_timestamp)*1e-6 ;
7273 // quick fix for strange cases (micros overflow)
7374 if (Ts <= 0 || Ts > 0.5 ) Ts = 1e-3 ;
7475
@@ -79,7 +80,7 @@ float MagneticSensorSPI::getVelocity(){
7980
8081 // save variables for future pass
8182 angle_prev = angle_c;
82- velocity_calc_timestamp = _micros () ;
83+ velocity_calc_timestamp = now_us ;
8384 return vel;
8485}
8586
You can’t perform that action at this time.
0 commit comments