-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3PEncoder.hpp
More file actions
40 lines (29 loc) · 1.02 KB
/
3PEncoder.hpp
File metadata and controls
40 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <pigpio.h>
#include <atomic>
class AMT102VEncoder
{
public:
AMT102VEncoder(int gpioA, int gpioB, int gpioC);
~AMT102VEncoder();
void start();
void stop();
// 現在のパルスカウント値
int getPosition() const;
// 直近の回転方向(1=正転, -1=逆転, 0=静止)
int getDirection() const;
// 分解能測定(1回転あたりのパルス数/PPRを自動計測)
// 計測のため、1回転させる必要がある
int measurePPR();
private:
int pinA, pinB, pinC;
std::atomic<int> position;
std::atomic<int> lastDirection;
std::atomic<bool> revolutionFlag;
// pigpioコールバックID管理用
int cbIdA, cbIdB, cbIdC;
static void encoderISR(int gpio, int level, uint32_t tick, void* userdata);
static void cPhaseISR(int gpio, int level, uint32_t tick, void* userdata);
// pigpio初期化状態を管理(複数インスタンスでも正しく扱うために)
static std::atomic<int> pigpioInitCount;
};