Skip to content

Commit

Permalink
🔥 (MotionKit): Remove useless boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Mar 9, 2023
1 parent 89b4b5f commit eee6813
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
3 changes: 1 addition & 2 deletions libs/MotionKit/include/MotionKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class MotionKit
RotationControl _rotation_control;
std::function<void()> _on_rotation_ended_callback {};

bool _target_not_reached = false;
bool _rotate_x_turns_requested = false;
bool _target_not_reached = false;
};

} // namespace leka
23 changes: 7 additions & 16 deletions libs/MotionKit/source/MotionKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "MotionKit.hpp"

#include "ThisThread.h"

using namespace leka;
using namespace std::chrono_literals;

Expand All @@ -17,8 +15,7 @@ void MotionKit::stop()

_imukit.onEulerAnglesReady({});

_target_not_reached = false;
_rotate_x_turns_requested = false;
_target_not_reached = false;
}

void MotionKit::startYawRotation(float degrees, Rotation direction,
Expand All @@ -29,8 +26,7 @@ void MotionKit::startYawRotation(float degrees, Rotation direction,
auto starting_angle = _imukit.getEulerAngles();
_rotation_control.setTarget(starting_angle, degrees);

_target_not_reached = true;
_rotate_x_turns_requested = true;
_target_not_reached = true;

auto on_timeout = [this] { stop(); };

Expand All @@ -49,9 +45,11 @@ void MotionKit::startYawRotation(float degrees, Rotation direction,
// LCOV_EXCL_START - Dynamic behavior, involving motors and time.
void MotionKit::processAngleForRotation(const EulerAngles &angles, Rotation direction)
{
auto must_stop = [&] { return !_rotate_x_turns_requested && !_target_not_reached; };
if (_target_not_reached) {
auto speed = _rotation_control.processRotationAngle(angles);

if (must_stop()) {
setMotorsSpeedAndDirection(speed, direction);
} else {
stop();

if (_on_rotation_ended_callback) {
Expand All @@ -60,21 +58,14 @@ void MotionKit::processAngleForRotation(const EulerAngles &angles, Rotation dire

return;
}

if (_rotate_x_turns_requested && _target_not_reached) {
auto speed = _rotation_control.processRotationAngle(angles);

setMotorsSpeedAndDirection(speed, direction);
}
}

void MotionKit::setMotorsSpeedAndDirection(float speed, Rotation direction)
{
if (speed == 0.F) {
_motor_left.stop();
_motor_right.stop();
_target_not_reached = false;
_rotate_x_turns_requested = false;
_target_not_reached = false;
} else {
_motor_left.spin(direction, speed);
_motor_right.spin(direction, speed);
Expand Down

0 comments on commit eee6813

Please sign in to comment.