-
Notifications
You must be signed in to change notification settings - Fork 8
/
DirectionalOdometer.cpp
53 lines (49 loc) · 1.18 KB
/
DirectionalOdometer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "DirectionalOdometer.hpp"
namespace before
{
DirectionalOdometer::DirectionalOdometer(int directionPin,
int pulsePin,
int pulsesPerMeter)
: DirectionlessOdometer(pulsePin, pulsesPerMeter)
, mDirectionPin{directionPin}
{
mInterruptManager.triggerOnNewPulse(pulsePin, [this]() {
if (mPinReader.read(mDirectionPin))
{
mPulses++;
}
else
{
mPulses--;
}
});
}
} // namespace before
namespace after
{
DirectionalOdometer::DirectionalOdometer(
Encoder& encoder,
InterruptServiceManager& interruptServiceManager,
PinReader& pinReader,
int directionPin,
int pulsePin)
: mEncoder{encoder}
, mPinReader{pinReader}
, mDirectionPin{directionPin}
{
interruptServiceManager.triggerOnNewPulse(pulsePin, [this]() {
if (mPinReader.read(mDirectionPin))
{
mEncoder.incrementPulses();
}
else
{
mEncoder.decrementPulses();
}
});
}
double DirectionalOdometer::getDistance() const
{
return mEncoder.getDistance();
}
} // namespace after