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.
src/encoders.cpp@3:35deb5c21b33, 2018-11-26 (annotated)
- Committer:
- rwgriffithv
- Date:
- Mon Nov 26 23:50:58 2018 +0000
- Revision:
- 3:35deb5c21b33
- Parent:
- 0:88c60458332e
pid controller updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rwgriffithv | 0:88c60458332e | 1 | #include "encoders.h" |
rwgriffithv | 0:88c60458332e | 2 | #include "pins.h" |
rwgriffithv | 0:88c60458332e | 3 | #include "globals.h" |
rwgriffithv | 0:88c60458332e | 4 | #include "mbed.h" |
rwgriffithv | 0:88c60458332e | 5 | #include "QEI.h" |
rwgriffithv | 0:88c60458332e | 6 | |
rwgriffithv | 0:88c60458332e | 7 | /*** |
rwgriffithv | 0:88c60458332e | 8 | * Assignment 2 |
rwgriffithv | 0:88c60458332e | 9 | * |
rwgriffithv | 0:88c60458332e | 10 | * Import the QEI in order to have functioning encoders. |
rwgriffithv | 0:88c60458332e | 11 | ***/ |
rwgriffithv | 0:88c60458332e | 12 | QEI wheel_R(ENC_RF, ENC_RB, NC, 624, QEI::X4_ENCODING); |
rwgriffithv | 0:88c60458332e | 13 | QEI wheel_L(ENC_LF, ENC_LB, NC, 624, QEI::X4_ENCODING); |
rwgriffithv | 0:88c60458332e | 14 | |
rwgriffithv | 0:88c60458332e | 15 | /////// |
rwgriffithv | 0:88c60458332e | 16 | // Encoder class implementation |
rwgriffithv | 0:88c60458332e | 17 | /////// |
rwgriffithv | 0:88c60458332e | 18 | |
rwgriffithv | 0:88c60458332e | 19 | Encoder::Encoder() { |
rwgriffithv | 0:88c60458332e | 20 | reset(); |
rwgriffithv | 0:88c60458332e | 21 | } |
rwgriffithv | 0:88c60458332e | 22 | |
rwgriffithv | 0:88c60458332e | 23 | void Encoder::reset() volatile { |
rwgriffithv | 0:88c60458332e | 24 | wheel_R.reset(); |
rwgriffithv | 0:88c60458332e | 25 | wheel_L.reset(); |
rwgriffithv | 0:88c60458332e | 26 | } |
rwgriffithv | 0:88c60458332e | 27 | |
rwgriffithv | 0:88c60458332e | 28 | int Encoder::getPulsesR() volatile { |
rwgriffithv | 0:88c60458332e | 29 | return wheel_R.getPulses(); |
rwgriffithv | 0:88c60458332e | 30 | } |
rwgriffithv | 0:88c60458332e | 31 | |
rwgriffithv | 0:88c60458332e | 32 | int Encoder::getPulsesL() volatile { |
rwgriffithv | 0:88c60458332e | 33 | return wheel_L.getPulses(); |
rwgriffithv | 0:88c60458332e | 34 | } |
rwgriffithv | 0:88c60458332e | 35 | |
rwgriffithv | 0:88c60458332e | 36 | void Encoder::printValues() volatile { |
rwgriffithv | 0:88c60458332e | 37 | pc.printf("R: %d\tL: %d\n", getPulsesR(), getPulsesL()); |
rwgriffithv | 0:88c60458332e | 38 | } |