mit

Dependencies:   QEI mbed-src

Committer:
coldplay
Date:
Mon Dec 24 03:47:49 2018 +0000
Revision:
5:e90c8b57811c
Parent:
4:5ae9f8b3a16f
mit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abuchan 4:5ae9f8b3a16f 1 #include "Encoder.h"
abuchan 4:5ae9f8b3a16f 2
abuchan 4:5ae9f8b3a16f 3 //Encoder steps to revolutions of output shaft in radians
abuchan 4:5ae9f8b3a16f 4 float pulsesToRadians(float pulses) {
abuchan 4:5ae9f8b3a16f 5 return ((pulses/ENC_STEPS_PER_REV)*(2.0*PI));
abuchan 4:5ae9f8b3a16f 6 }
abuchan 4:5ae9f8b3a16f 7
abuchan 4:5ae9f8b3a16f 8 //Encoder steps to revolutions of output shaft in degrees
abuchan 4:5ae9f8b3a16f 9 float pulsesToDegrees(float pulses) {
abuchan 4:5ae9f8b3a16f 10 return ((pulses/ENC_STEPS_PER_REV)*360.0);
abuchan 4:5ae9f8b3a16f 11 }
abuchan 4:5ae9f8b3a16f 12
abuchan 4:5ae9f8b3a16f 13 Encoder::Encoder(PinName enc_a_pin, PinName enc_b_pin): qei_(enc_a_pin, enc_b_pin, NC, ENC_STEPS_PER_REV, QEI::X4_ENCODING) {
abuchan 4:5ae9f8b3a16f 14 //Use X4 encoding.
abuchan 4:5ae9f8b3a16f 15 //(encoder channel 1, encoder channel 2, index (n/a here), counts per revolution, mode (X4, X2))
abuchan 4:5ae9f8b3a16f 16 //QEI ;
abuchan 4:5ae9f8b3a16f 17 }
abuchan 4:5ae9f8b3a16f 18
abuchan 4:5ae9f8b3a16f 19 float Encoder::get_position(void) {
abuchan 4:5ae9f8b3a16f 20 return pulsesToRadians(qei_.getPulses());
abuchan 4:5ae9f8b3a16f 21 }