Skip to content

Dev_Action_Server_State_Machine_Model

Martin Bischoff edited this page Aug 13, 2019 · 2 revisions

Action Server State Machine Model

0. ROS Specification

In Actionlib Detailed Description, ROS defined the action server with a state machine model:

Original at: http://wiki.ros.org/actionlib/DetailedDescription?action=AttachFile&do=get&target=server_states_detailed.png

Image from ROS Actionlib Detailed Description

Please read the server section of Actionlib Detailed Description as our server is based on the ROS state machine model

1. Corresponding Methods

Our ActionServer implements the state machine model. Each transition in the state machine is represented by a method. which sets the status of the server and calls methods overridden by you that defines custom behavior after state transition is complete.

Transition Representing Method On transition method
Receive Goal private void GoalCallback(actionGoal) protected abstract void OnGoalReceived()
Cancel Request private void CancelCallback(goalID) protected abstract void OnGoalRecalling(GoalID goalID)
protected abstract void OnGoalPreempting()
setAccepted protected void SetAccepted() protected abstract void OnGoalActive()
setRejected protected void SetRejected() protected virtual void OnGoalRejected()
setSucceeded protected void SetSucceeded() protected virtual void OnGoalSucceeded()
setAborted protected void SetAborted() protected virtual void OnGoalAborted()
setCanceled protected void SetCanceled() protected virtual void OnGoalCanceled()

1.0 Action Status

Our ActionServer uses ActionStatus enum which corresponds to constant byte values in GoalStatus

Additionally, we have an ActionStatus of NO_GOAL which corresponds to server status before receiving a goal.

1.1 Client Triggered Transitions

private void GoalCallback(TActionGoal actionGoal)

This method is called by WebSocket subscription for <action name>/goal topic. New goal gets stored in action.action_goal and server state is set to PENDING. Then, OnGoalReceived() is called.

protected abstract void OnGoalReceived()

This method is called by GoalCallback(actionGoal) after server saves goal and updates action status. Extension of ActionServer are required to implement this method.

private void CancelCallback(GoalID goalID)

This method is called by WebSocket subscription for <action name>/cancel topic, sets action status to RECALLING or PREEMPTING and calls OnGoalRecalling(GoalID goalID) or OnGoalPreempting() respectively

protected abstract void OnGoalRecalling(GoalID goalID)

This method is called by CancelCallback(goalID) when a goal is canceled during PENDING action state. Extension of ActionServer are required to implement this method.

protected abstract void OnGoalPreempting()

This method is called by CancelCallback(goalID) when a goal is canceled during ACTIVE action state. Extension of ActionServer are required to implement this method. Generally used to signal goal processing thread to stop and join.

1.2 Server Triggered Transitions

protected void SetAccepted(string text = "")

This method sets action status to ACTIVE from PENDING or to PREEMPTING from RECALLING. Invalid transitions are ignored and logged as a warning. Then OnGoalActive() or OnGoalPreempting() is called. Optionally, user can pass in a text for extra information in GoalStatus

protected abstract void OnGoalActive()

This method is called by SetAccepted() after action status is set to ACTIVE. Extension of ActionServer are required to implement this method, and is generally used to start a new thread for goal processing.

protected void SetRejected(string text = "")

This method sets action status to REJECTED from PENDING or RECALLING. Invalid transitions are ignored and logged as a warning. Then OnGoalRejected() is called. Optionally, user can pass in a text for extra information in GoalStatus

protected virtual void OnGoalRejected() { }

This method is called by SetRejected() after action status is set to REJECTED and doesn't do anything by default.

protected void SetSucceeded(TResult result = null, string text = "")

This method sets action status to SUCCEEDED from ACTIVE or PREEMPTING. Invalid transitions are ignored and logged as a warning. If user chooses to pass in an optional Result, action.action_result.result is updated. The result is then published and OnGoalSucceeded() is called. Optionally, user can pass in a text for extra information in GoalStatus

protected virtual void OnGoalSucceeded() { }

This method is called by SetSucceeded() after action status is set to SUCCEEDED and doesn't do anything by default.

protected void SetAborted(string text = "")

This method sets action status to ABORTED from ACTIVE or PREEMPTING. Invalid transitions are ignored and logged as a warning. Then OnGoalAborted() is called. Optionally, user can pass in a text for extra information in GoalStatus

protected virtual void OnGoalAborted() { }

This method is called by SetAborted() after action status is set to ABORTED and doesn't do anything by default.

protected void SetCanceled(TResult result = null, string text = "")

This method sets action status to RECALLED from RECALLING or PREEMPTED from PREEMPTING. Invalid transitions are ignored and logged as a warning. If user chooses to pass in an optional Result, action.action_result.result is updated. Then OnGoalCanceled() is called. Optionally, user can pass in a text for extra information in GoalStatus

protected virtual void OnGoalCanceled() { }

This method is called by SetCanceled() after action status is set to RECALLED or PREEMPTED and doesn't do anything by default.

1.3 Server Methods

protected void UpdateAndPublishStatus(ActionStatus actionStatus, string text = "")

Updates current action status and calls PublishStatus(). Optionally, user can pass in a text for extra information in GoalStatus. Generally not called in extension classes to prevent illegal state transitions.

protected void PublishStatus()

Publishes current action status as the first element of a GoalStatusArray to <action name>/status topic. If current status is NO_GOAL, an empty array is published.

protected void PublishFeedback()

Publishes current stored action.action_feedback with current ActionStatus and GoalID and publishes feedback to <action name>/feedback topic.

protected void PublishResult()

Publishes current stored action.action_result with current ActionStatus and GoalID and publishes feedback to <action name>/feedback topic.

protected ActionStatus GetStatus()

Returns the current ActionStatus. Note that this will return NO_GOAL which is not a part of ROS standard GoalStatus.

protected virtual void Log(string log) { }/protected virtual void LogWarning(string log) { }/protected virtual void LogError(string log) { }

Allows user to override to direct log messages to appropriate streams. Doesn't do anything by default.

1.4 Server Life Cycle

On construction, the server connects to provided serverURL.

To start advertising and subscribing, please call Start(). Note that Start() doesn't spin the server and without a spinning method, server will terminate.

Stop() will unadvertise and unsubscribe all topics and close the socket it is using.


© Siemens AG, 2019 Author: Sifan Ye ([email protected])

Clone this wiki locally