Skip to content

Commit

Permalink
♻️ (MotionKit): Change all number_of_rotations in degrees
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Mar 9, 2023
1 parent eee6813 commit 4cf6ce9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libs/MotionKit/include/RotationControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions libs/MotionKit/source/RotationControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 5 additions & 4 deletions libs/MotionKit/tests/MotionKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions libs/ReinforcerKit/include/ReinforcerKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions libs/ReinforcerKit/source/ReinforcerKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions spikes/lk_motion_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4cf6ce9

Please sign in to comment.