SimpleFOClibrary  2.1
Sensor.cpp
Go to the documentation of this file.
1 #include "Sensor.h"
2 #include "../foc_utils.h"
3 #include "../time_utils.h"
4 
11  return 0;
12 }
13 
16 
17  // calculate sample time
18  unsigned long now_us = _micros();
19  float Ts = (now_us - velocity_calc_timestamp)*1e-6;
20  // quick fix for strange cases (micros overflow)
21  if(Ts <= 0 || Ts > 0.5) Ts = 1e-3;
22 
23  // current angle
24  float angle_c = getAngle();
25  // velocity calculation
26  float vel = (angle_c - angle_prev)/Ts;
27 
28  // save variables for future pass
29  angle_prev = angle_c;
30  velocity_calc_timestamp = now_us;
31  return vel;
32 }
Sensor::needsSearch
virtual int needsSearch()
Definition: Sensor.cpp:10
Sensor.h
Sensor::getVelocity
virtual float getVelocity()
Definition: Sensor.cpp:15
_micros
unsigned long _micros()
Definition: time_utils.cpp:21
Sensor::getAngle
virtual float getAngle()=0