Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: backdrive backdrive_3
Diff: encoder.h
- Revision:
- 0:4b99060621fd
- Child:
- 2:4bb7c8730d91
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder.h Mon Jun 04 07:38:05 2018 +0000
@@ -0,0 +1,53 @@
+#ifndef ENCODER_H
+#define ENCODER_H
+
+#include "mbed.h"
+#include "arm_math.h"
+
+enum CH{
+ DISTANCE,
+ RPM,
+ VELOCITY,
+ ACCELERATION,
+ OMEGA,
+ DELTA_DISTANCE,
+};
+
+enum TYPE_NUMBER{
+ NORMAL,
+ DELTA,
+ TYPE_NUMBER,
+};
+
+enum BEFORE_NUMBER{
+ NOW,
+ ONE_BEFORE,
+ TWO_BEFORE,
+ BEFORE_NUMBER,
+};
+
+class Encoder
+{
+ public:
+ Encoder(PinName aPhase , PinName bPhase );
+ void calState();
+
+ float getState(int ch);
+
+ void reset();
+
+ void init(float _ppr, float _radius,float _dt);
+
+ private:
+ void read();
+
+ float rpm, distance, omega, velocity, radius, delta_distance,
+ ppr, dt, dt_square, circle, acceleration;
+
+ float count[TYPE_NUMBER][BEFORE_NUMBER];
+ InterruptIn aPhase;
+ DigitalIn bPhase;
+};
+
+#endif
+