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(){
29
29
30
30
// I2C communication begin
31
31
Wire.begin ();
32
-
32
+
33
33
// velocity calculation init
34
34
angle_prev = 0 ;
35
35
velocity_calc_timestamp = _micros ();
@@ -66,7 +66,8 @@ float MagneticSensorI2C::getAngle(){
66
66
// Shaft velocity calculation
67
67
float MagneticSensorI2C::getVelocity (){
68
68
// 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 ;
70
71
// quick fix for strange cases (micros overflow)
71
72
if (Ts <= 0 || Ts > 0.5 ) Ts = 1e-3 ;
72
73
@@ -77,7 +78,7 @@ float MagneticSensorI2C::getVelocity(){
77
78
78
79
// save variables for future pass
79
80
angle_prev = angle_c;
80
- velocity_calc_timestamp = _micros () ;
81
+ velocity_calc_timestamp = now_us ;
81
82
return vel;
82
83
}
83
84
Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ float MagneticSensorSPI::getAngle(){
68
68
// Shaft velocity calculation
69
69
float MagneticSensorSPI::getVelocity (){
70
70
// 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 ;
72
73
// quick fix for strange cases (micros overflow)
73
74
if (Ts <= 0 || Ts > 0.5 ) Ts = 1e-3 ;
74
75
@@ -79,7 +80,7 @@ float MagneticSensorSPI::getVelocity(){
79
80
80
81
// save variables for future pass
81
82
angle_prev = angle_c;
82
- velocity_calc_timestamp = _micros () ;
83
+ velocity_calc_timestamp = now_us ;
83
84
return vel;
84
85
}
85
86
You can’t perform that action at this time.
0 commit comments