amiro-os / components / MotorIncrements.cpp @ 7520e117
History | View | Annotate | Download (848 Bytes)
1 | 58fe0e0b | Thomas Schöpping | #include <ch.hpp> |
---|---|---|---|
2 | #include <hal.h> |
||
3 | |||
4 | #include <qei.h> |
||
5 | |||
6 | #include <amiro/MotorIncrements.h> |
||
7 | |||
8 | using namespace chibios_rt; |
||
9 | using namespace amiro; |
||
10 | |||
11 | MotorIncrements::MotorIncrements(QEIDriver* qei0, QEIDriver* qei1) { |
||
12 | this->qeiDriver[0] = qei0; |
||
13 | this->qeiDriver[1] = qei1; |
||
14 | |||
15 | this->qeiConfig.mode = QEI_COUNT_BOTH;
|
||
16 | this->qeiConfig.channels[0].mode = QEI_INPUT_INVERTED; |
||
17 | this->qeiConfig.channels[1].mode = QEI_INPUT_NONINVERTED; |
||
18 | this->qeiConfig.range = 0x10000; |
||
19 | } |
||
20 | |||
21 | void MotorIncrements::start() {
|
||
22 | qeiStart(this->qeiDriver[0], &this->qeiConfig); |
||
23 | qeiStart(this->qeiDriver[1], &this->qeiConfig); |
||
24 | |||
25 | qeiEnable(this->qeiDriver[0]); |
||
26 | qeiEnable(this->qeiDriver[1]); |
||
27 | } |
||
28 | |||
29 | int MotorIncrements::qeiGetPosition(int idxQei) { |
||
30 | return qeiGetPositionI(this->qeiDriver[idxQei]); |
||
31 | } |
||
32 | |||
33 | int MotorIncrements::getQeiConfigRange() {
|
||
34 | return this->qeiConfig.range; |
||
35 | } |