Skip to content

Commit

Permalink
Rename action state transitions
Browse files Browse the repository at this point in the history
Now using active verbs.
Resolves #399.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Mar 30, 2019
1 parent 03dec21 commit 81b28ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions rcl_action/include/rcl_action/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ typedef enum rcl_action_goal_event_t
{
GOAL_EVENT_EXECUTE = 0,
GOAL_EVENT_CANCEL,
GOAL_EVENT_SET_SUCCEEDED,
GOAL_EVENT_SET_ABORTED,
GOAL_EVENT_SET_CANCELED,
GOAL_EVENT_SUCCEED,
GOAL_EVENT_ABORT,
GOAL_EVENT_CANCEL,
GOAL_EVENT_NUM_EVENTS
} rcl_action_goal_event_t;

Expand Down
22 changes: 11 additions & 11 deletions rcl_action/src/rcl_action/goal_state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ _cancel_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t eve
}

rcl_action_goal_state_t
_set_succeeded_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t event)
_succeed_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t event)
{
if ((GOAL_STATE_EXECUTING != state && GOAL_STATE_CANCELING != state) ||
GOAL_EVENT_SET_SUCCEEDED != event)
GOAL_EVENT_SUCCEED != event)
{
return GOAL_STATE_UNKNOWN;
}
return GOAL_STATE_SUCCEEDED;
}

rcl_action_goal_state_t
_set_aborted_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t event)
_abort_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t event)
{
if ((GOAL_STATE_EXECUTING != state && GOAL_STATE_CANCELING != state) ||
GOAL_EVENT_SET_ABORTED != event)
GOAL_EVENT_ABORT != event)
{
return GOAL_STATE_UNKNOWN;
}
return GOAL_STATE_ABORTED;
}

rcl_action_goal_state_t
_set_canceled_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t event)
_cancel_event_handler(rcl_action_goal_state_t state, rcl_action_goal_event_t event)
{
if (GOAL_STATE_CANCELING != state || GOAL_EVENT_SET_CANCELED != event) {
if (GOAL_STATE_CANCELING != state || GOAL_EVENT_CANCEL != event) {
return GOAL_STATE_UNKNOWN;
}
return GOAL_STATE_CANCELED;
Expand All @@ -83,13 +83,13 @@ static rcl_action_goal_event_handler
},
[GOAL_STATE_EXECUTING] = {
[GOAL_EVENT_CANCEL] = _cancel_event_handler,
[GOAL_EVENT_SET_SUCCEEDED] = _set_succeeded_event_handler,
[GOAL_EVENT_SET_ABORTED] = _set_aborted_event_handler,
[GOAL_EVENT_SUCCEED] = _succeed_event_handler,
[GOAL_EVENT_ABORT] = _abort_event_handler,
},
[GOAL_STATE_CANCELING] = {
[GOAL_EVENT_SET_SUCCEEDED] = _set_succeeded_event_handler,
[GOAL_EVENT_SET_ABORTED] = _set_aborted_event_handler,
[GOAL_EVENT_SET_CANCELED] = _set_canceled_event_handler,
[GOAL_EVENT_SUCCEED] = _succeed_event_handler,
[GOAL_EVENT_ABORT] = _abort_event_handler,
[GOAL_EVENT_CANCEL] = _cancel_event_handler,
},
};

Expand Down
2 changes: 1 addition & 1 deletion rcl_action/test/rcl_action/test_action_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ TEST_F(TestActionServer, test_action_clear_expired_goals)
handles.push_back(*goal_handle);
// Transition executing to aborted
ASSERT_EQ(RCL_RET_OK, rcl_action_update_goal_state(goal_handle, GOAL_EVENT_EXECUTE));
ASSERT_EQ(RCL_RET_OK, rcl_action_update_goal_state(goal_handle, GOAL_EVENT_SET_ABORTED));
ASSERT_EQ(RCL_RET_OK, rcl_action_update_goal_state(goal_handle, GOAL_EVENT_ABORT));
// Set time to something far in the future
ASSERT_EQ(RCL_RET_OK, rcl_set_ros_time_override(&this->clock, RCUTILS_S_TO_NS(99999)));
// Clear with valid arguments
Expand Down
24 changes: 12 additions & 12 deletions rcl_action/test/rcl_action/test_goal_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ using EventStateActiveCancelableTuple =
std::tuple<rcl_action_goal_event_t, rcl_action_goal_state_t, bool, bool>;
using StateTransitionSequence = std::vector<EventStateActiveCancelableTuple>;
const std::vector<std::string> event_strs = {
"EXECUTE", "CANCEL", "SET_SUCCEEDED", "SET_ABORTED", "SET_CANCELED"};
"EXECUTE", "CANCEL", "SUCCEED", "ABORT", "CANCEL"};

class TestGoalHandleStateTransitionSequence
: public ::testing::TestWithParam<StateTransitionSequence>
Expand Down Expand Up @@ -243,38 +243,38 @@ const StateTransitionSequence valid_state_transition_sequences[] = {
{
std::make_tuple(GOAL_EVENT_EXECUTE, GOAL_STATE_EXECUTING, true, true),
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELING, true, false),
std::make_tuple(GOAL_EVENT_SET_CANCELED, GOAL_STATE_CANCELED, false, false),
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELED, false, false),
},
{
std::make_tuple(GOAL_EVENT_EXECUTE, GOAL_STATE_EXECUTING, true, true),
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELING, true, false),
std::make_tuple(GOAL_EVENT_SET_SUCCEEDED, GOAL_STATE_SUCCEEDED, false, false),
std::make_tuple(GOAL_EVENT_SUCCEED, GOAL_STATE_SUCCEEDED, false, false),
},
{
std::make_tuple(GOAL_EVENT_EXECUTE, GOAL_STATE_EXECUTING, true, true),
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELING, true, false),
std::make_tuple(GOAL_EVENT_SET_ABORTED, GOAL_STATE_ABORTED, false, false),
std::make_tuple(GOAL_EVENT_ABORT, GOAL_STATE_ABORTED, false, false),
},
{
std::make_tuple(GOAL_EVENT_EXECUTE, GOAL_STATE_EXECUTING, true, true),
std::make_tuple(GOAL_EVENT_SET_SUCCEEDED, GOAL_STATE_SUCCEEDED, false, false),
std::make_tuple(GOAL_EVENT_SUCCEED, GOAL_STATE_SUCCEEDED, false, false),
},
{
std::make_tuple(GOAL_EVENT_EXECUTE, GOAL_STATE_EXECUTING, true, true),
std::make_tuple(GOAL_EVENT_SET_ABORTED, GOAL_STATE_ABORTED, false, false),
std::make_tuple(GOAL_EVENT_ABORT, GOAL_STATE_ABORTED, false, false),
},
{
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELING, true, false),
std::make_tuple(GOAL_EVENT_SET_CANCELED, GOAL_STATE_CANCELED, false, false),
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELED, false, false),
},
{
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELING, true, false),
std::make_tuple(GOAL_EVENT_SET_ABORTED, GOAL_STATE_ABORTED, false, false),
std::make_tuple(GOAL_EVENT_ABORT, GOAL_STATE_ABORTED, false, false),
},
// This is an odd case, but valid nonetheless
{
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_CANCELING, true, false),
std::make_tuple(GOAL_EVENT_SET_SUCCEEDED, GOAL_STATE_SUCCEEDED, false, false),
std::make_tuple(GOAL_EVENT_SUCCEED, GOAL_STATE_SUCCEEDED, false, false),
},
};

Expand All @@ -300,13 +300,13 @@ const StateTransitionSequence invalid_state_transition_sequences[] = {
std::make_tuple(GOAL_EVENT_EXECUTE, GOAL_STATE_UNKNOWN, false, false),
},
{
std::make_tuple(GOAL_EVENT_SET_CANCELED, GOAL_STATE_UNKNOWN, false, false),
std::make_tuple(GOAL_EVENT_CANCEL, GOAL_STATE_UNKNOWN, false, false),
},
{
std::make_tuple(GOAL_EVENT_SET_SUCCEEDED, GOAL_STATE_UNKNOWN, false, false),
std::make_tuple(GOAL_EVENT_SUCCEED, GOAL_STATE_UNKNOWN, false, false),
},
{
std::make_tuple(GOAL_EVENT_SET_ABORTED, GOAL_STATE_UNKNOWN, false, false),
std::make_tuple(GOAL_EVENT_ABORT, GOAL_STATE_UNKNOWN, false, false),
},
};

Expand Down
34 changes: 17 additions & 17 deletions rcl_action/test/rcl_action/test_goal_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ TEST(TestGoalStateMachine, test_valid_transitions)
EXPECT_EQ(GOAL_STATE_CANCELING, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_EXECUTING,
GOAL_EVENT_SET_SUCCEEDED);
GOAL_EVENT_SUCCEED);
EXPECT_EQ(GOAL_STATE_SUCCEEDED, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_EXECUTING,
GOAL_EVENT_SET_ABORTED);
GOAL_EVENT_ABORT);
EXPECT_EQ(GOAL_STATE_ABORTED, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_CANCELING,
GOAL_EVENT_SET_CANCELED);
GOAL_EVENT_CANCEL);
EXPECT_EQ(GOAL_STATE_CANCELED, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_CANCELING,
GOAL_EVENT_SET_ABORTED);
GOAL_EVENT_ABORT);
EXPECT_EQ(GOAL_STATE_ABORTED, state);
}

Expand All @@ -53,15 +53,15 @@ TEST(TestGoalStateMachine, test_invalid_transitions)
// Invalid from ACCEPTED
rcl_action_goal_state_t state = rcl_action_transition_goal_state(
GOAL_STATE_ACCEPTED,
GOAL_EVENT_SET_SUCCEEDED);
GOAL_EVENT_SUCCEED);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_ACCEPTED,
GOAL_EVENT_SET_ABORTED);
GOAL_EVENT_ABORT);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_ACCEPTED,
GOAL_EVENT_SET_CANCELED);
GOAL_EVENT_CANCEL);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);

// Invalid from EXECUTING
Expand All @@ -71,7 +71,7 @@ TEST(TestGoalStateMachine, test_invalid_transitions)
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_EXECUTING,
GOAL_EVENT_SET_CANCELED);
GOAL_EVENT_CANCEL);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);

// Invalid from CANCELING
Expand All @@ -95,15 +95,15 @@ TEST(TestGoalStateMachine, test_invalid_transitions)
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_SUCCEEDED,
GOAL_EVENT_SET_SUCCEEDED);
GOAL_EVENT_SUCCEED);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_SUCCEEDED,
GOAL_EVENT_SET_ABORTED);
GOAL_EVENT_ABORT);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_SUCCEEDED,
GOAL_EVENT_SET_CANCELED);
GOAL_EVENT_CANCEL);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);

// Invalid from ABORTED
Expand All @@ -117,15 +117,15 @@ TEST(TestGoalStateMachine, test_invalid_transitions)
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_ABORTED,
GOAL_EVENT_SET_SUCCEEDED);
GOAL_EVENT_SUCCEED);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_ABORTED,
GOAL_EVENT_SET_ABORTED);
GOAL_EVENT_ABORT);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_ABORTED,
GOAL_EVENT_SET_CANCELED);
GOAL_EVENT_CANCEL);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);

// Invalid from CANCELED
Expand All @@ -139,14 +139,14 @@ TEST(TestGoalStateMachine, test_invalid_transitions)
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_CANCELED,
GOAL_EVENT_SET_SUCCEEDED);
GOAL_EVENT_SUCCEED);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_CANCELED,
GOAL_EVENT_SET_ABORTED);
GOAL_EVENT_ABORT);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
state = rcl_action_transition_goal_state(
GOAL_STATE_CANCELED,
GOAL_EVENT_SET_CANCELED);
GOAL_EVENT_CANCEL);
EXPECT_EQ(GOAL_STATE_UNKNOWN, state);
}

0 comments on commit 81b28ec

Please sign in to comment.