EEEN21000
GROUP 30 Line Following Buggy
|
#include "mbed.h"
Go to the source code of this file.
Classes | |
class | QEI |
Handle reading pulses from encoder. More... | |
Macros | |
#define | PREV_MASK 0x1 |
Mask for the previous state in determining direction. More... | |
#define | CURR_MASK 0x2 |
Mask for the current state in determining direction. More... | |
#define | INVALID 0x3 |
XORing both states where both bits have changed. More... | |
#define PREV_MASK 0x1 |
Mask for the previous state in determining direction.
Derivative work created in Jan 2021 by D.Smart, which has the following changes:
No copyright claim is being made on these changes.
Copyright (c) 2010 ARM Limited
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
QEI.
A quadrature encoder consists of two code tracks on a disc which are 90 degrees out of phase. It can be used to determine how far a wheel has rotated, relative to a known starting position.
Only one code track changes at a time leading to a more robust system than a single track, because any jitter around any edge won't cause a state change as the other track will remain constant.
Encoders can be a homebrew affair, consisting of infrared emitters/receivers and paper code tracks consisting of alternating black and white sections; alternatively, complete disk and PCB emitter/receiver encoder systems can be bought, but the interface, regardless of implementation is the same. Rotational position in degrees can be calculated by:
\( rotational\ position\ =\ \frac{pulse\ count}{X\ \cdot \ N} \cdot \ 360\\\)
Where X is the encoding type [e.g. X4 encoding => X=4], and N is the number of pulses per revolution.
Linear position can be calculated by:
\( linear\ position\ =\ \frac{pulse\ count}{X\ \cdot \ N} \cdot \ \frac{1}{PPI}\\\)
Where X is encoding type [e.g. X4 encoding => X=44], N is the number of pulses per revolution, and PPI is pulses per inch, or the equivalent for any other unit of displacement. PPI can be calculated by taking the circumference of the wheel or encoder disk and dividing it by the number of pulses per revolution.
#define CURR_MASK 0x2 |
Mask for the current state in determining direction.
#define INVALID 0x3 |
XORing both states where both bits have changed.