@@ -13,7 +13,7 @@ static constexpr float stepsPerRad = stepsPerDeg / ((2*pi)/360);
13
13
14
14
static enum class Action
15
15
{
16
- STRAIGHTFORWARD , TURN_LEFT, TURN_RIGHT
16
+ FORWARD, BACKWARD , TURN_LEFT, TURN_RIGHT
17
17
} lastAction;
18
18
19
19
Position lastKnownPosition = {0 ,0 };
@@ -67,7 +67,7 @@ void rotateCounter(const Counter steps, const Amplitude amplitude, bool const cl
67
67
68
68
void driveCounter (const Counter steps, const Amplitude amplitude, const bool backwards)
69
69
{
70
- lastAction = Action::STRAIGHTFORWARD ;
70
+ lastAction = backwards ? Action::BACKWARD : Action::FORWARD ;
71
71
LeftDrive::drive (steps, amplitude, backwards);
72
72
RightDrive::drive (steps, calcRightSpeed (amplitude), backwards);
73
73
}
@@ -88,10 +88,12 @@ void drive(const float distance, const Amplitude amplitude, const bool backwards
88
88
Position flushCurrentPosition ()
89
89
{
90
90
switch (lastAction) {
91
- case Action::STRAIGHTFORWARD:
91
+ case Action::FORWARD:
92
+ case Action::BACKWARD:
92
93
{
93
- lastKnownPosition.x += LeftDrive::counter * board::odoIntervalLength * std::cos (orientation);
94
- lastKnownPosition.y += LeftDrive::counter * board::odoIntervalLength * std::sin (orientation);
94
+ const std::int8_t reversed = (lastAction == Action::BACKWARD) ? -1 : 1 ;
95
+ lastKnownPosition.x += LeftDrive::counter * board::odoIntervalLength * std::cos (orientation) * reversed;
96
+ lastKnownPosition.y += LeftDrive::counter * board::odoIntervalLength * std::sin (orientation) * reversed;
95
97
break ;
96
98
}
97
99
case Action::TURN_LEFT:
0 commit comments