From b3f6b919b443992c599931e46a96e6bff4f9a4c6 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Thu, 9 Mar 2023 10:42:05 +0100 Subject: [PATCH] :recycle: (MotionKit): Change all number_of_rotations in degrees --- libs/MotionKit/include/RotationControl.hpp | 2 +- libs/MotionKit/source/RotationControl.cpp | 4 ++-- libs/MotionKit/tests/MotionKit_test.cpp | 9 +++++---- libs/ReinforcerKit/include/ReinforcerKit.h | 1 + libs/ReinforcerKit/source/ReinforcerKit.cpp | 4 ++-- spikes/lk_motion_kit/main.cpp | 14 +++++++------- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libs/MotionKit/include/RotationControl.hpp b/libs/MotionKit/include/RotationControl.hpp index c06b246cc9..f9c47749f4 100644 --- a/libs/MotionKit/include/RotationControl.hpp +++ b/libs/MotionKit/include/RotationControl.hpp @@ -12,7 +12,7 @@ class RotationControl public: RotationControl() = default; - void setTarget(EulerAngles starting_angles, float number_of_rotations); + void setTarget(EulerAngles starting_angles, float degrees); auto processRotationAngle(EulerAngles current_angles) -> float; private: diff --git a/libs/MotionKit/source/RotationControl.cpp b/libs/MotionKit/source/RotationControl.cpp index aa54808053..1081cad029 100644 --- a/libs/MotionKit/source/RotationControl.cpp +++ b/libs/MotionKit/source/RotationControl.cpp @@ -9,10 +9,10 @@ using namespace leka; -void RotationControl::setTarget(EulerAngles starting_angle, float number_of_rotations) +void RotationControl::setTarget(EulerAngles starting_angle, float degrees) { _euler_angles_previous = starting_angle; - _angle_rotation_target = number_of_rotations * 360.F; + _angle_rotation_target = degrees; _angle_rotation_sum = 0; } diff --git a/libs/MotionKit/tests/MotionKit_test.cpp b/libs/MotionKit/tests/MotionKit_test.cpp index 94a0476f6d..cc43c175e0 100644 --- a/libs/MotionKit/tests/MotionKit_test.cpp +++ b/libs/MotionKit/tests/MotionKit_test.cpp @@ -36,6 +36,7 @@ class MotionKitTest : public ::testing::Test mock::Timeout mock_timeout {}; const EulerAngles angles {0.F, 0.F, 0.F}; + const float kOneTurnDegrees = 360.0; mock::IMUKit mock_imukit {}; @@ -61,7 +62,7 @@ TEST_F(MotionKitTest, rotateClockwise) EXPECT_CALL(mock_motor_left, spin(Rotation::clockwise, _)).Times(AtLeast(1)); EXPECT_CALL(mock_motor_right, spin(Rotation::clockwise, _)).Times(AtLeast(1)); - motion.startYawRotation(1, Rotation::clockwise); + motion.startYawRotation(kOneTurnDegrees, Rotation::clockwise); mock_imukit.call_angles_ready_callback(angles); } @@ -80,7 +81,7 @@ TEST_F(MotionKitTest, rotateCounterClockwise) EXPECT_CALL(mock_motor_left, spin(Rotation::counterClockwise, _)).Times(AtLeast(1)); EXPECT_CALL(mock_motor_right, spin(Rotation::counterClockwise, _)).Times(AtLeast(1)); - motion.startYawRotation(1, Rotation::counterClockwise); + motion.startYawRotation(kOneTurnDegrees, Rotation::counterClockwise); mock_imukit.call_angles_ready_callback(angles); } @@ -99,7 +100,7 @@ TEST_F(MotionKitTest, rotateAndStop) EXPECT_CALL(mock_motor_left, spin(Rotation::clockwise, _)).Times(AtLeast(1)); EXPECT_CALL(mock_motor_right, spin(Rotation::clockwise, _)).Times(AtLeast(1)); - motion.startYawRotation(1, Rotation::clockwise); + motion.startYawRotation(kOneTurnDegrees, Rotation::clockwise); mock_imukit.call_angles_ready_callback(angles); EXPECT_CALL(mock_timeout, stop).Times(1); @@ -125,7 +126,7 @@ TEST_F(MotionKitTest, rotateAndTimeOutOver) EXPECT_CALL(mock_motor_left, spin(Rotation::clockwise, _)).Times(AtLeast(1)); EXPECT_CALL(mock_motor_right, spin(Rotation::clockwise, _)).Times(AtLeast(1)); - motion.startYawRotation(1, Rotation::clockwise); + motion.startYawRotation(kOneTurnDegrees, Rotation::clockwise); mock_imukit.call_angles_ready_callback(angles); EXPECT_CALL(mock_timeout, stop).Times(1); diff --git a/libs/ReinforcerKit/include/ReinforcerKit.h b/libs/ReinforcerKit/include/ReinforcerKit.h index 38e7ef8335..cb77530133 100644 --- a/libs/ReinforcerKit/include/ReinforcerKit.h +++ b/libs/ReinforcerKit/include/ReinforcerKit.h @@ -40,6 +40,7 @@ class ReinforcerKit interface::LedKit &_ledkit; MotionKit &_motionkit; Reinforcer _default_reinforcer = Reinforcer::Rainbow; + const float kThreeTurnDegrees = 1080.F; void playBlinkGreen(); void playSpinBlink(); diff --git a/libs/ReinforcerKit/source/ReinforcerKit.cpp b/libs/ReinforcerKit/source/ReinforcerKit.cpp index de5143a324..59dde69348 100644 --- a/libs/ReinforcerKit/source/ReinforcerKit.cpp +++ b/libs/ReinforcerKit/source/ReinforcerKit.cpp @@ -52,14 +52,14 @@ void ReinforcerKit::playBlinkGreen() { _videokit.playVideoOnce("/fs/home/vid/system/robot-system-reinforcer-happy-no_eyebrows.avi"); _ledkit.start(&led::animation::blink_green); - _motionkit.startYawRotation(3, Rotation::clockwise, [this] { _ledkit.stop(); }); + _motionkit.startYawRotation(kThreeTurnDegrees, Rotation::clockwise, [this] { _ledkit.stop(); }); } void ReinforcerKit::playSpinBlink() { _videokit.playVideoOnce("/fs/home/vid/system/robot-system-reinforcer-happy-no_eyebrows.avi"); _ledkit.start(&led::animation::spin_blink); - _motionkit.startYawRotation(3, Rotation::counterClockwise, [this] { _ledkit.stop(); }); + _motionkit.startYawRotation(kThreeTurnDegrees, Rotation::counterClockwise, [this] { _ledkit.stop(); }); } void ReinforcerKit::playFire() diff --git a/spikes/lk_motion_kit/main.cpp b/spikes/lk_motion_kit/main.cpp index 193c20b751..26ec4622ca 100644 --- a/spikes/lk_motion_kit/main.cpp +++ b/spikes/lk_motion_kit/main.cpp @@ -94,25 +94,25 @@ void onMagicCardAvailable(const MagicCard &card) { switch (card.getId()) { case (MagicCard::number_1.getId()): - motionkit.startYawRotation(1, Rotation::counterClockwise, [] { log_debug("Callback end of rotation"); }); + motionkit.startYawRotation(90, Rotation::counterClockwise, [] { log_debug("Callback end of rotation"); }); break; case (MagicCard::number_2.getId()): - motionkit.startYawRotation(2, Rotation::clockwise); + motionkit.startYawRotation(180, Rotation::clockwise); break; case (MagicCard::number_3.getId()): - motionkit.startYawRotation(3, Rotation::counterClockwise); + motionkit.startYawRotation(360, Rotation::counterClockwise); break; case (MagicCard::number_4.getId()): - motionkit.startYawRotation(4, Rotation::clockwise); + motionkit.startYawRotation(540, Rotation::clockwise); break; case (MagicCard::number_5.getId()): - motionkit.startYawRotation(5, Rotation::counterClockwise); + motionkit.startYawRotation(720, Rotation::counterClockwise); break; case (MagicCard::number_6.getId()): - motionkit.startYawRotation(6, Rotation::clockwise); + motionkit.startYawRotation(1080, Rotation::clockwise); break; case (MagicCard::number_7.getId()): - motionkit.startYawRotation(7, Rotation::counterClockwise); + motionkit.startYawRotation(1080, Rotation::counterClockwise); break; case (MagicCard::number_10.getId()): motionkit.stop();