Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/sm/add-transition-sleeping-state-to-idle…
Browse files Browse the repository at this point in the history
…-state' into develop
  • Loading branch information
ladislas committed Mar 21, 2022
2 parents b7610db + 434145c commit addfcf4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libs/RobotKit/include/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace sm::event {
};
struct sleep_timeout_did_end {
};
struct command_received {
};
struct charge_did_start {
};
struct charge_did_stop {
Expand Down Expand Up @@ -118,6 +120,7 @@ struct StateMachine {
, sm::state::sleeping + boost::sml::on_entry<_> / sm::action::start_sleeping_behavior {}
, sm::state::sleeping + boost::sml::on_exit<_> / sm::action::stop_sleeping_behavior {}

, sm::state::sleeping + event<sm::event::command_received> = sm::state::idle
, sm::state::sleeping + event<sm::event::charge_did_start> [sm::guard::is_charging {}] = sm::state::charging

, sm::state::charging + boost::sml::on_entry<_> / sm::action::start_charging_behavior {}
Expand Down
9 changes: 9 additions & 0 deletions libs/RobotKit/tests/RobotController_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ TEST_F(RobotControllerTest, stateIdleEventTimeout)
EXPECT_TRUE(rc.state_machine.is(lksm::state::sleeping));
}

TEST_F(RobotControllerTest, stateSleepingEventCommandReceived)
{
rc.state_machine.set_current_states(lksm::state::sleeping);

// TODO: Trigger command_received in StateMachine from BLE

// EXPECT_TRUE(rc.state_machine.is(lksm::state::idle));
}

TEST_F(RobotControllerTest, stateSleepingEventChargeDidStartGuardIsChargingTrue)
{
rc.state_machine.set_current_states(lksm::state::sleeping);
Expand Down
13 changes: 13 additions & 0 deletions libs/RobotKit/tests/StateMachine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ TEST_F(StateMachineTest, stateIdleEventTimeout)
EXPECT_TRUE(sm.is(lksm::state::sleeping));
}

TEST_F(StateMachineTest, stateSleepEventCommandReceived)
{
sm.set_current_states(lksm::state::sleeping);

EXPECT_CALL(mock_rc, stopSleepingBehavior).Times(1);
EXPECT_CALL(mock_rc, startSleepTimeout).Times(1);
EXPECT_CALL(mock_rc, startWaitingBehavior).Times(1);

sm.process_event(lksm::event::command_received {});

EXPECT_TRUE(sm.is(lksm::state::idle));
}

TEST_F(StateMachineTest, stateSleepEventChargeDidStart)
{
sm.set_current_states(lksm::state::sleeping);
Expand Down

0 comments on commit addfcf4

Please sign in to comment.