Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename action state transitions #300

Merged
merged 2 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions rclpy/rclpy/action/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class GoalEvent(Enum):
"""Goal events that cause state transitions."""

EXECUTE = 1
CANCEL = 2
SET_SUCCEEDED = 3
SET_ABORTED = 4
SET_CANCELED = 5
REQUEST_CANCEL = 2
SUCCEED = 3
ABORT = 4
CANCEL = 5


class ServerGoalHandle:
Expand Down Expand Up @@ -149,14 +149,14 @@ def publish_feedback(self, feedback):
_rclpy_action.rclpy_action_publish_feedback(
self._action_server._handle, feedback_message)

def set_succeeded(self):
self._update_state(GoalEvent.SET_SUCCEEDED)
def succeed(self):
self._update_state(GoalEvent.SUCCEED)

def set_aborted(self):
self._update_state(GoalEvent.SET_ABORTED)
def abort(self):
self._update_state(GoalEvent.ABORT)

def set_canceled(self):
self._update_state(GoalEvent.SET_CANCELED)
def cancel(self):
self._update_state(GoalEvent.CANCEL)

def destroy(self):
with self._lock:
Expand Down Expand Up @@ -330,7 +330,7 @@ async def _execute_goal(self, execute_callback, goal_handle):
if goal_handle.is_active:
self._node.get_logger().warning(
'Goal state not set, assuming aborted. Goal ID: {0}'.format(goal_uuid))
goal_handle.set_aborted()
goal_handle.abort()

self._node.get_logger().debug(
'Goal with ID {0} finished with state {1}'.format(goal_uuid, goal_handle.status))
Expand Down Expand Up @@ -363,7 +363,7 @@ async def _execute_cancel_request(self, request_header_and_message):

if CancelResponse.ACCEPT == response:
# Notify goal handle
goal_handle._update_state(GoalEvent.CANCEL)
goal_handle._update_state(GoalEvent.REQUEST_CANCEL)
else:
# Remove from response
cancel_response.goals_canceling.remove(goal_info)
Expand Down
70 changes: 35 additions & 35 deletions rclpy/src/rclpy/_rclpy_action.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,33 +1349,33 @@ convert_from_py_goal_event(const int64_t pyevent)
}
to_decref[num_to_decref++] = pyexecute;

PyObject * pycancel = PyObject_GetAttrString(pygoal_event_class, "CANCEL");
if (!pycancel) {
PyObject * pyrequest_cancel = PyObject_GetAttrString(pygoal_event_class, "REQUEST_CANCEL");
if (!pyrequest_cancel) {
MULTI_DECREF(to_decref, num_to_decref)
return -1;
}
to_decref[num_to_decref++] = pycancel;
to_decref[num_to_decref++] = pyrequest_cancel;

PyObject * pyset_succeeded = PyObject_GetAttrString(pygoal_event_class, "SET_SUCCEEDED");
if (!pyset_succeeded) {
PyObject * pysucceed = PyObject_GetAttrString(pygoal_event_class, "SUCCEED");
if (!pysucceed) {
MULTI_DECREF(to_decref, num_to_decref);
return -1;
}
to_decref[num_to_decref++] = pyset_succeeded;
to_decref[num_to_decref++] = pysucceed;

PyObject * pyset_aborted = PyObject_GetAttrString(pygoal_event_class, "SET_ABORTED");
if (!pyset_aborted) {
PyObject * pyabort = PyObject_GetAttrString(pygoal_event_class, "ABORT");
if (!pyabort) {
MULTI_DECREF(to_decref, num_to_decref)
return -1;
}
to_decref[num_to_decref++] = pyset_aborted;
to_decref[num_to_decref++] = pyabort;

PyObject * pyset_canceled = PyObject_GetAttrString(pygoal_event_class, "SET_CANCELED");
if (!pyset_canceled) {
PyObject * pycancel = PyObject_GetAttrString(pygoal_event_class, "CANCEL");
if (!pycancel) {
MULTI_DECREF(to_decref, num_to_decref)
return -1;
}
to_decref[num_to_decref++] = pyset_canceled;
to_decref[num_to_decref++] = pycancel;

PyObject * pyexecute_val = PyObject_GetAttrString(pyexecute, "value");
if (!pyexecute_val) {
Expand All @@ -1384,55 +1384,55 @@ convert_from_py_goal_event(const int64_t pyevent)
}
to_decref[num_to_decref++] = pyexecute_val;

PyObject * pycancel_val = PyObject_GetAttrString(pycancel, "value");
if (!pycancel_val) {
PyObject * pyrequest_cancel_val = PyObject_GetAttrString(pyrequest_cancel, "value");
if (!pyrequest_cancel_val) {
MULTI_DECREF(to_decref, num_to_decref);
return -1;
}
to_decref[num_to_decref++] = pycancel_val;
to_decref[num_to_decref++] = pyrequest_cancel_val;

PyObject * pyset_succeeded_val = PyObject_GetAttrString(pyset_succeeded, "value");
if (!pyset_succeeded_val) {
PyObject * pysucceed_val = PyObject_GetAttrString(pysucceed, "value");
if (!pysucceed_val) {
MULTI_DECREF(to_decref, num_to_decref);
return -1;
}
to_decref[num_to_decref++] = pyset_succeeded_val;
to_decref[num_to_decref++] = pysucceed_val;

PyObject * pyset_aborted_val = PyObject_GetAttrString(pyset_aborted, "value");
if (!pyset_aborted_val) {
PyObject * pyabort_val = PyObject_GetAttrString(pyabort, "value");
if (!pyabort_val) {
MULTI_DECREF(to_decref, num_to_decref);
return -1;
}
to_decref[num_to_decref++] = pyset_aborted_val;
to_decref[num_to_decref++] = pyabort_val;

PyObject * pyset_canceled_val = PyObject_GetAttrString(pyset_canceled, "value");
if (!pyset_canceled_val) {
PyObject * pycancel_val = PyObject_GetAttrString(pycancel, "value");
if (!pycancel_val) {
MULTI_DECREF(to_decref, num_to_decref);
return -1;
}
to_decref[num_to_decref++] = pyset_canceled_val;
to_decref[num_to_decref++] = pycancel_val;

const int64_t execute = PyLong_AsLong(pyexecute_val);
const int64_t request_cancel = PyLong_AsLong(pyrequest_cancel_val);
const int64_t succeed = PyLong_AsLong(pysucceed_val);
const int64_t abort = PyLong_AsLong(pyabort_val);
const int64_t cancel = PyLong_AsLong(pycancel_val);
const int64_t set_succeeded = PyLong_AsLong(pyset_succeeded_val);
const int64_t set_aborted = PyLong_AsLong(pyset_aborted_val);
const int64_t set_canceled = PyLong_AsLong(pyset_canceled_val);
MULTI_DECREF(to_decref, num_to_decref)

if (execute == pyevent) {
return GOAL_EVENT_EXECUTE;
}
if (cancel == pyevent) {
return GOAL_EVENT_CANCEL;
if (request_cancel == pyevent) {
return GOAL_EVENT_REQUEST_CANCEL;
}
if (set_succeeded == pyevent) {
return GOAL_EVENT_SET_SUCCEEDED;
if (succeed == pyevent) {
return GOAL_EVENT_SUCCEED;
}
if (set_aborted == pyevent) {
return GOAL_EVENT_SET_ABORTED;
if (abort == pyevent) {
return GOAL_EVENT_ABORT;
}
if (set_canceled == pyevent) {
return GOAL_EVENT_SET_CANCELED;
if (cancel == pyevent) {
return GOAL_EVENT_CANCEL;
}

PyErr_Format(
Expand Down
18 changes: 9 additions & 9 deletions rclpy/test/action/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def timed_spin(self, duration):
rclpy.spin_once(self.node, executor=self.executor, timeout_sec=0.1)

def execute_goal_callback(self, goal_handle):
goal_handle.set_succeeded()
goal_handle.succeed()
return Fibonacci.Result()

def test_constructor_defaults(self):
Expand Down Expand Up @@ -280,7 +280,7 @@ def execute_callback(goal_handle):
# Wait, to give the opportunity to cancel
time.sleep(3.0)
self.assertTrue(goal_handle.is_cancel_requested)
goal_handle.set_canceled()
goal_handle.cancel()
return Fibonacci.Result()

def cancel_callback(request):
Expand Down Expand Up @@ -326,7 +326,7 @@ def execute_callback(goal_handle):
# Wait, to give the opportunity to cancel
time.sleep(3.0)
self.assertFalse(goal_handle.is_cancel_requested)
goal_handle.set_canceled()
goal_handle.cancel()
return Fibonacci.Result()

def cancel_callback(request):
Expand Down Expand Up @@ -378,7 +378,7 @@ def cancel_callback(request):
def execute_callback(gh):
# The goal should already be in state CANCELING
self.assertTrue(gh.is_cancel_requested)
gh.set_canceled()
gh.cancel()
return Fibonacci.Result()

action_server = ActionServer(
Expand Down Expand Up @@ -424,13 +424,13 @@ def execute_callback(gh):
self.assertEqual(server_goal_handle.status, GoalStatus.STATUS_CANCELED)
action_server.destroy()

def test_execute_set_succeeded(self):
def test_execute_succeed(self):

def execute_callback(goal_handle):
self.assertEqual(goal_handle.status, GoalStatus.STATUS_EXECUTING)
result = Fibonacci.Result()
result.sequence.extend([1, 1, 2, 3, 5])
goal_handle.set_succeeded()
goal_handle.succeed()
return result

action_server = ActionServer(
Expand All @@ -455,13 +455,13 @@ def execute_callback(goal_handle):
self.assertEqual(result_response.result.sequence.tolist(), [1, 1, 2, 3, 5])
action_server.destroy()

def test_execute_set_aborted(self):
def test_execute_abort(self):

def execute_callback(goal_handle):
self.assertEqual(goal_handle.status, GoalStatus.STATUS_EXECUTING)
result = Fibonacci.Result()
result.sequence.extend([1, 1, 2, 3, 5])
goal_handle.set_aborted()
goal_handle.abort()
return result

action_server = ActionServer(
Expand Down Expand Up @@ -596,7 +596,7 @@ def execute_with_feedback(goal_handle):
feedback = Fibonacci.Feedback()
feedback.sequence = [1, 1, 2, 3]
goal_handle.publish_feedback(feedback)
goal_handle.set_succeeded()
goal_handle.succeed()
return Fibonacci.Result()

action_server = ActionServer(
Expand Down