Micromouse 18
/
encoder
encoder
main.cpp@1:1b18e69bf50f, 2017-11-08 (annotated)
- Committer:
- mbshark
- Date:
- Wed Nov 08 01:38:27 2017 +0000
- Revision:
- 1:1b18e69bf50f
- Parent:
- 0:b9e03a03e580
- Child:
- 2:aa961ba3199e
motor testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kensterino | 0:b9e03a03e580 | 1 | #include "mbed.h" |
kensterino | 0:b9e03a03e580 | 2 | #include "QEI.h" |
kensterino | 0:b9e03a03e580 | 3 | Serial pc (PA_2, PA_3); //serial comm enabled on pins pa_2 and pa_3 |
kensterino | 0:b9e03a03e580 | 4 | QEI encoder_Right(PB_3, PA_15, NC, 360, QEI::X4_ENCODING); |
kensterino | 0:b9e03a03e580 | 5 | QEI encoder_Left(PA_1, PC_4, NC, 360, QEI::X4_ENCODING); //forward increases pulses |
mbshark | 1:1b18e69bf50f | 6 | PwmOut(m_Left, PC_7) |
kensterino | 0:b9e03a03e580 | 7 | |
kensterino | 0:b9e03a03e580 | 8 | //QEI functions |
kensterino | 0:b9e03a03e580 | 9 | /* |
kensterino | 0:b9e03a03e580 | 10 | void reset (void) |
kensterino | 0:b9e03a03e580 | 11 | Reset the encoder. |
kensterino | 0:b9e03a03e580 | 12 | int getCurrentState (void) |
kensterino | 0:b9e03a03e580 | 13 | Read the state of the encoder. |
kensterino | 0:b9e03a03e580 | 14 | int getPulses (void) |
kensterino | 0:b9e03a03e580 | 15 | Read the number of pulses recorded by the encoder. |
kensterino | 0:b9e03a03e580 | 16 | int getRevolutions (void) |
kensterino | 0:b9e03a03e580 | 17 | Read the number of revolutions recorded by the encoder on the index channel. |
kensterino | 0:b9e03a03e580 | 18 | */ |
kensterino | 0:b9e03a03e580 | 19 | |
kensterino | 0:b9e03a03e580 | 20 | int main() |
kensterino | 0:b9e03a03e580 | 21 | { |
kensterino | 0:b9e03a03e580 | 22 | |
kensterino | 0:b9e03a03e580 | 23 | while(1) { |
kensterino | 0:b9e03a03e580 | 24 | wait(0.1); |
mbshark | 1:1b18e69bf50f | 25 | m_Left.write(0.75); |
kensterino | 0:b9e03a03e580 | 26 | pc.printf("Pulses is: %i\n", encoder_Right.getPulses()); |
kensterino | 0:b9e03a03e580 | 27 | //pc.printf("Pulses is: %i\n", encoder_Left.getPulses()); |
kensterino | 0:b9e03a03e580 | 28 | } |
mbshark | 1:1b18e69bf50f | 29 | |
mbshark | 1:1b18e69bf50f | 30 | |
kensterino | 0:b9e03a03e580 | 31 | |
kensterino | 0:b9e03a03e580 | 32 | } |