Skip to content

Commit

Permalink
✨ (RobotController): Add transition from setup to working if connected
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Jul 15, 2024
1 parent 569b838 commit 6909201
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions libs/RobotKit/include/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ struct StateMachine {

return make_transition_table(
// clang-format off
* sm::state::setup + event<sm::event::setup_complete> [sm::guard::is_not_charging {}] = sm::state::idle
, sm::state::setup + event<sm::event::setup_complete> [sm::guard::is_charging {}] = sm::state::charging
* sm::state::setup + event<sm::event::setup_complete> [sm::guard::is_not_charging {} && sm::guard::is_not_connected {}] = sm::state::idle
, sm::state::setup + event<sm::event::setup_complete> [sm::guard::is_not_charging {} && sm::guard::is_connected {}] = sm::state::working
, sm::state::setup + event<sm::event::setup_complete> [sm::guard::is_charging {}] = sm::state::charging
, sm::state::setup + boost::sml::on_exit<_> / sm::action::run_launching_behavior {}

, sm::state::idle + boost::sml::on_entry<_> / (sm::action::start_sleep_timeout {}, sm::action::start_waiting_behavior {})
Expand Down
18 changes: 17 additions & 1 deletion libs/RobotKit/tests/StateMachine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,36 @@ TEST_F(StateMachineTest, initialState)
EXPECT_FALSE(sm.is(lksm::state::charging));
}

TEST_F(StateMachineTest, stateSetupEventSetupCompleteGuardIsChargingFalse)
TEST_F(StateMachineTest, stateSetupEventSetupCompleteGuardIsChargingFalseIsConnectedFalse)
{
sm.set_current_states(lksm::state::setup);

EXPECT_CALL(mock_rc, runLaunchingBehavior).Times(1);
EXPECT_CALL(mock_rc, isCharging).WillRepeatedly(Return(false));
EXPECT_CALL(mock_rc, startSleepTimeout).Times(1);
EXPECT_CALL(mock_rc, startWaitingBehavior).Times(1);
EXPECT_CALL(mock_rc, isBleConnected).WillRepeatedly(Return(false));

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

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

TEST_F(StateMachineTest, stateSetupEventSetupCompleteGuardIsChargingFalseIsConnectedTrue)
{
sm.set_current_states(lksm::state::setup);

EXPECT_CALL(mock_rc, runLaunchingBehavior).Times(1);
EXPECT_CALL(mock_rc, isCharging).WillRepeatedly(Return(false));
EXPECT_CALL(mock_rc, startIdleTimeout).Times(1);
EXPECT_CALL(mock_rc, startWorkingBehavior).Times(1);
EXPECT_CALL(mock_rc, isBleConnected).WillRepeatedly(Return(true));

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

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

TEST_F(StateMachineTest, stateSetupEventSetupCompleteGuardIsChargingTrue)
{
sm.set_current_states(lksm::state::setup);
Expand Down

0 comments on commit 6909201

Please sign in to comment.