Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Diff: PositionSensor/PositionSensor.cpp
- Revision:
- 192:3152a86cd108
- Parent:
- 186:c18db1e31da6
- Child:
- 225:81b72a4bf18b
--- a/PositionSensor/PositionSensor.cpp Sat Feb 10 03:42:07 2018 +0000 +++ b/PositionSensor/PositionSensor.cpp Sat Feb 10 03:58:36 2018 +0000 @@ -2,8 +2,8 @@ #include "mbed.h" #include "PositionSensor.h" -#include "defaults.h" #include "derived.h" +#include "prefs.h" /* * CPR: counts per revolution (4x lines per revolution) @@ -13,7 +13,7 @@ PositionSensorEncoder::PositionSensorEncoder(int cpr, float offset) { _cpr = cpr; _offset = offset; - _lobes = (int) (RESOLVER_LOBES); + _lobes = (int) (_RESOLVER_LOBES); _valid = false; _rotations = 0; @@ -55,7 +55,7 @@ */ float PositionSensorEncoder::GetMechPosition() { - return GetUnlimitedElecPosition() / 3.0f; + return GetUnlimitedElecPosition() / _POLE_PAIRS; } /* @@ -66,7 +66,7 @@ int raw = TIM2->CNT; if (raw < 0) raw += _cpr; if (raw >= _cpr) raw -= _cpr; - float ep = fmod((POLE_PAIRS / RESOLVER_LOBES * (2 * PI * (raw) / (float)_cpr + _offset)), 2 * PI); + float ep = fmod((_POLE_PAIRS / _RESOLVER_LOBES * (2 * PI * (raw) / (float)_cpr + _offset)), 2 * PI); if (ep < 0) { return ep + 2 * PI; } else { @@ -80,7 +80,7 @@ float PositionSensorEncoder::GetUnlimitedElecPosition() { int raw = TIM2->CNT; - float ep = POLE_PAIRS / RESOLVER_LOBES * (2 * PI * (raw) / (float)_cpr + _offset); + float ep = _POLE_PAIRS / _RESOLVER_LOBES * (2 * PI * (raw) / (float)_cpr + _offset); return ep + _rotations * 2 * PI; }