mencari respon motor launcher dengan fungsi step
Dependencies: Motor mbed millis
Fork of transfer_function_motor by
encoderKRAI.h@2:8f1bb7191680, 2017-04-13 (annotated)
- Committer:
- Najib_irvani
- Date:
- Thu Apr 13 13:52:41 2017 +0000
- Revision:
- 2:8f1bb7191680
- Parent:
- 0:be14d75c8037
transfer motor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Najib_irvani | 0:be14d75c8037 | 1 | #ifndef ENCODERKRAI_H |
Najib_irvani | 0:be14d75c8037 | 2 | #define ENCODERKRAI_H |
Najib_irvani | 0:be14d75c8037 | 3 | |
Najib_irvani | 0:be14d75c8037 | 4 | /** |
Najib_irvani | 0:be14d75c8037 | 5 | * Includes |
Najib_irvani | 0:be14d75c8037 | 6 | */ |
Najib_irvani | 0:be14d75c8037 | 7 | #include "mbed.h" |
Najib_irvani | 0:be14d75c8037 | 8 | |
Najib_irvani | 0:be14d75c8037 | 9 | /** |
Najib_irvani | 0:be14d75c8037 | 10 | * Defines |
Najib_irvani | 0:be14d75c8037 | 11 | */ |
Najib_irvani | 0:be14d75c8037 | 12 | #define PREV_MASK 0x1 //Mask for the previous state in determining direction |
Najib_irvani | 0:be14d75c8037 | 13 | //of rotation. |
Najib_irvani | 0:be14d75c8037 | 14 | #define CURR_MASK 0x2 //Mask for the current state in determining direction |
Najib_irvani | 0:be14d75c8037 | 15 | //of rotation. |
Najib_irvani | 0:be14d75c8037 | 16 | #define INVALID 0x3 //XORing two states where both bits have changed. |
Najib_irvani | 0:be14d75c8037 | 17 | |
Najib_irvani | 0:be14d75c8037 | 18 | /** |
Najib_irvani | 0:be14d75c8037 | 19 | * Quadrature Encoder Interface. |
Najib_irvani | 0:be14d75c8037 | 20 | */ |
Najib_irvani | 0:be14d75c8037 | 21 | class encoderKRAI { |
Najib_irvani | 0:be14d75c8037 | 22 | |
Najib_irvani | 0:be14d75c8037 | 23 | public: |
Najib_irvani | 0:be14d75c8037 | 24 | |
Najib_irvani | 0:be14d75c8037 | 25 | typedef enum Encoding { |
Najib_irvani | 0:be14d75c8037 | 26 | |
Najib_irvani | 0:be14d75c8037 | 27 | X2_ENCODING, |
Najib_irvani | 0:be14d75c8037 | 28 | X4_ENCODING |
Najib_irvani | 0:be14d75c8037 | 29 | |
Najib_irvani | 0:be14d75c8037 | 30 | } Encoding; |
Najib_irvani | 0:be14d75c8037 | 31 | |
Najib_irvani | 0:be14d75c8037 | 32 | /** Membuat interface dari encoder |
Najib_irvani | 0:be14d75c8037 | 33 | * |
Najib_irvani | 0:be14d75c8037 | 34 | * @param inA DigitalIn, out A dari encoder |
Najib_irvani | 0:be14d75c8037 | 35 | * @param inB DigitalIn, out B dari encoder |
Najib_irvani | 0:be14d75c8037 | 36 | */ |
Najib_irvani | 0:be14d75c8037 | 37 | encoderKRAI(PinName channelA, PinName channelB, int pulsesPerRev, Encoding encoding = X2_ENCODING); |
Najib_irvani | 0:be14d75c8037 | 38 | |
Najib_irvani | 0:be14d75c8037 | 39 | /** |
Najib_irvani | 0:be14d75c8037 | 40 | * Reset encoder. |
Najib_irvani | 0:be14d75c8037 | 41 | * |
Najib_irvani | 0:be14d75c8037 | 42 | * Menset pulse dan revolusi/putaran menjadi 0 |
Najib_irvani | 0:be14d75c8037 | 43 | */ |
Najib_irvani | 0:be14d75c8037 | 44 | void reset(void); |
Najib_irvani | 0:be14d75c8037 | 45 | |
Najib_irvani | 0:be14d75c8037 | 46 | /** |
Najib_irvani | 0:be14d75c8037 | 47 | * Membaca pulse yang didapat oleh encoder |
Najib_irvani | 0:be14d75c8037 | 48 | * |
Najib_irvani | 0:be14d75c8037 | 49 | * @return Nilai pulse yang telah dilalui. |
Najib_irvani | 0:be14d75c8037 | 50 | */ |
Najib_irvani | 0:be14d75c8037 | 51 | int getPulses(void); |
Najib_irvani | 0:be14d75c8037 | 52 | |
Najib_irvani | 0:be14d75c8037 | 53 | /** |
Najib_irvani | 0:be14d75c8037 | 54 | * Membaca putaran yang didapat oleh encoder |
Najib_irvani | 0:be14d75c8037 | 55 | * |
Najib_irvani | 0:be14d75c8037 | 56 | * @return Nilai revolusi/putaran yang telah dilalui. |
Najib_irvani | 0:be14d75c8037 | 57 | */ |
Najib_irvani | 0:be14d75c8037 | 58 | int getRevolutions(void); |
Najib_irvani | 0:be14d75c8037 | 59 | |
Najib_irvani | 0:be14d75c8037 | 60 | /** |
Najib_irvani | 0:be14d75c8037 | 61 | * Membaca pulse yang didapat oleh encoder |
Najib_irvani | 0:be14d75c8037 | 62 | * |
Najib_irvani | 0:be14d75c8037 | 63 | * @return Nilai pulse yang telah dilalui. |
Najib_irvani | 0:be14d75c8037 | 64 | */ |
Najib_irvani | 0:be14d75c8037 | 65 | //int readDeltaPulses(void); |
Najib_irvani | 0:be14d75c8037 | 66 | |
Najib_irvani | 0:be14d75c8037 | 67 | /** |
Najib_irvani | 0:be14d75c8037 | 68 | * Membaca putaran yang didapat oleh encoder |
Najib_irvani | 0:be14d75c8037 | 69 | * |
Najib_irvani | 0:be14d75c8037 | 70 | * @return Nilai revolusi/putaran yang telah dilalui. |
Najib_irvani | 0:be14d75c8037 | 71 | */ |
Najib_irvani | 0:be14d75c8037 | 72 | //int readDeltaRevolutions(void); |
Najib_irvani | 0:be14d75c8037 | 73 | |
Najib_irvani | 0:be14d75c8037 | 74 | private: |
Najib_irvani | 0:be14d75c8037 | 75 | |
Najib_irvani | 0:be14d75c8037 | 76 | /** |
Najib_irvani | 0:be14d75c8037 | 77 | * Menghitung pulse |
Najib_irvani | 0:be14d75c8037 | 78 | * |
Najib_irvani | 0:be14d75c8037 | 79 | * Digunakan setiap rising/falling edge baik channel A atau B |
Najib_irvani | 0:be14d75c8037 | 80 | * Membaca putaran CW atau CCW => mengakibatkan pertambahan/pengurangan pulse |
Najib_irvani | 0:be14d75c8037 | 81 | */ |
Najib_irvani | 0:be14d75c8037 | 82 | void encode(void); |
Najib_irvani | 0:be14d75c8037 | 83 | |
Najib_irvani | 0:be14d75c8037 | 84 | /** |
Najib_irvani | 0:be14d75c8037 | 85 | * Indeks setiap rising edge untuk menghitung putaran |
Najib_irvani | 0:be14d75c8037 | 86 | * Nilai bertambah 1 |
Najib_irvani | 0:be14d75c8037 | 87 | */ |
Najib_irvani | 0:be14d75c8037 | 88 | //void index(void); |
Najib_irvani | 0:be14d75c8037 | 89 | |
Najib_irvani | 0:be14d75c8037 | 90 | Encoding encoding_; |
Najib_irvani | 0:be14d75c8037 | 91 | |
Najib_irvani | 0:be14d75c8037 | 92 | InterruptIn channelA_; |
Najib_irvani | 0:be14d75c8037 | 93 | InterruptIn channelB_; |
Najib_irvani | 0:be14d75c8037 | 94 | //InterruptIn index_; |
Najib_irvani | 0:be14d75c8037 | 95 | |
Najib_irvani | 0:be14d75c8037 | 96 | int pulsesPerRev_; |
Najib_irvani | 0:be14d75c8037 | 97 | int prevState_; |
Najib_irvani | 0:be14d75c8037 | 98 | int currState_; |
Najib_irvani | 0:be14d75c8037 | 99 | |
Najib_irvani | 0:be14d75c8037 | 100 | volatile int pulses_; |
Najib_irvani | 0:be14d75c8037 | 101 | volatile int revolutions_; |
Najib_irvani | 0:be14d75c8037 | 102 | |
Najib_irvani | 0:be14d75c8037 | 103 | |
Najib_irvani | 0:be14d75c8037 | 104 | }; |
Najib_irvani | 0:be14d75c8037 | 105 | |
Najib_irvani | 0:be14d75c8037 | 106 | #endif /* ENCODERKRAI_H */ |