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
encoder.h
- Committer:
- takenowa
- Date:
- 2019-04-30
- Revision:
- 5:32ee588c735d
- Parent:
- 4:c99eb511ac08
- Child:
- 6:36805e006b09
File content as of revision 5:32ee588c735d:
#ifndef ENCODER_H
#define ENCODER_H
#include "mbed.h"
#include "arm_math.h"
enum CH{
DISTANCE,
RPM,
VELOCITY,
ACCELERATION,
OMEGA,
DELTA_DISTANCE,
};
enum ENCODER_MODE{
X1_ENCODE,
X2_ENCODE,
X4_ENCODE,
};
enum TYPE_NUMBER{
NORMAL,
DELTA,
TYPE_NUMBER,
};
enum BEFORE_NUMBER{
CURRENT,
ONE_BEFORE,
TWO_BEFORE,
BEFORE_NUMBER,
};
class Encoder
{
public:
Encoder(PinName a_phase , PinName b_phase );
void calculate();
float getState(int ch);
void reset();
void init(float _ppr, float _radius,float _dt,int mode);
private:
void readAphaseRise();
void readAphaseFall();
void readBphaseRise();
void readBphaseFall();
float rpm, distance, omega, velocity, radius, delta_distance,
ppr, dt, dt_square, circle, acceleration;
float count[TYPE_NUMBER][BEFORE_NUMBER];/* = {
{[NORMAL][NOW], [NORMAL][ONE_BEFORE], [NORMAL][TWO_BEFORE]},
{[DELTA][NOW], [DELTA][ONE_BEFORE], [DELTA][TWO_BEFORE]}
}
*/
InterruptIn aPhase;
InterruptIn bPhase;
};
#endif