@@ -109,15 +109,14 @@ class Sensor{
109109 float min_elapsed_time = 0.000100 ; // default is 100 microseconds, or 10kHz
110110
111111 protected:
112- /* *
113- * Get current shaft angle from the sensor hardware, and
112+ /* * Get current shaft angle from the sensor hardware, and
114113 * return it as a float in radians, in the range 0 to 2PI.
115- *
114+ *
116115 * This method is pure virtual and must be implemented in subclasses.
117116 * Calling this method directly does not update the base-class internal fields.
118117 * Use update() when calling from outside code.
119118 */
120- virtual float getSensorAngle ()= 0;
119+ virtual float getSensorAngle () = 0;
121120 /* *
122121 * Call Sensor::init() from your sensor subclass's init method if you want smoother startup
123122 * The base class init() method calls getSensorAngle() several times to initialize the internal fields
@@ -126,14 +125,37 @@ class Sensor{
126125 */
127126 virtual void init ();
128127
129- // velocity calculation variables
130- float velocity=0 .0f ;
131- float angle_prev=0 .0f ; // result of last call to getSensorAngle(), used for full rotations and velocity
132- long angle_prev_ts=0 ; // timestamp of last call to getAngle, used for velocity
133- float vel_angle_prev=0 .0f ; // angle at last call to getVelocity, used for velocity
134- long vel_angle_prev_ts=0 ; // last velocity calculation timestamp
135- int32_t full_rotations=0 ; // full rotation tracking
136- int32_t vel_full_rotations=0 ; // previous full rotation value for velocity calculation
128+ /* * Last calculated velocity in rad/s */
129+ float velocity = 0 .0f ;
130+
131+ /* * Previously determined angle from getSensorAngle()
132+ *
133+ * Always in the range of 0 to 2PI
134+ */
135+ float angle_prev = 0 .0f ;
136+
137+ /* * Timestamp of last call to update() in micro seconds.
138+ */
139+ long angle_prev_ts = 0 ;
140+
141+ /* * Angle at last call to getVelocity 0 to 2PI.
142+ *
143+ * Used for velocity
144+ */
145+ float vel_angle_prev = 0 .0f ;
146+
147+ /* * Timestamp of last call to getVelocity() in micro seconds.
148+ */
149+ long vel_angle_prev_ts = 0 ; // last velocity calculation timestamp
150+
151+ /* * Previously determined number of full rotations.
152+ *
153+ * Updated in update()
154+ */
155+ int32_t full_rotations = 0 ;
156+
157+ /* * Velocity in 2PI/sec */
158+ int32_t vel_full_rotations = 0 ;
137159};
138160
139161#endif
0 commit comments