File tree Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Original file line number Diff line number Diff line change 2
2
#include " ../foc_utils.h"
3
3
#include " ../time_utils.h"
4
4
5
-
5
+ // TODO add an init method to make the startup smoother by initializing internal variables to current values rather than 0
6
6
7
7
float Sensor::updateSensor () {
8
8
float val = getSensorAngle ();
@@ -22,9 +22,10 @@ float Sensor::getVelocity() {
22
22
// quick fix for strange cases (micros overflow)
23
23
if (Ts <= 0 || Ts > 0.5 ) Ts = 1e-3 ;
24
24
// velocity calculation
25
- float vel = (angle_prev - vel_angle_prev)/ Ts;
25
+ float vel = ( (full_rotations - vel_full_rotations)*_2PI + ( angle_prev - vel_angle_prev) ) / Ts;
26
26
// save variables for future pass
27
27
vel_angle_prev = angle_prev;
28
+ vel_full_rotations = full_rotations;
28
29
vel_angle_prev_ts = angle_prev_ts;
29
30
return vel;
30
31
}
Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ class Sensor{
112
112
float vel_angle_prev=0 ; // angle at last call to getVelocity, used for velocity
113
113
long vel_angle_prev_ts=0 ; // !< last velocity calculation timestamp
114
114
int32_t full_rotations=0 ; // full rotation tracking
115
+ int32_t vel_full_rotations=0 ;
115
116
};
116
117
117
118
#endif
You can’t perform that action at this time.
0 commit comments