Main Content

ROS Actions Overview

Client to Server Relationship

ROS Actions have a client-to-server communication relationship with a specified protocol. The actions use ROS topics to send goal messages from a client to the server. You can cancel goals using the action client. After receiving a goal, the server processes it and can give information back to the client. This information includes the status of the server, the state of the current goal, feedback on that goal during operation, and finally a result message when the goal is complete.

Use thesendGoalfunction to send goals to the server. Send the goal and wait for it to complete usingsendGoalAndWait. This function enables you to return the result message, final state of the goal and status of the server. While the server is executing a goal, the callback function,FeedbackFcn, is called to provide data relevant to that goal (seeSimpleActionClient). Cancel the current goal usingcancelGoalor all goals on server usingcancelAllGoals.

Performing Actions Workflow

In general, the following steps occur when creating and executing a ROS action on a ROS network.

  • Setup ROS action server. Check what actions are available on a ROS network by typingrosactionlistin the MATLAB®command window.

  • Userosactionclientto create action clients and connect them to the server. Specify an action type currently available on the ROS network. UsewaitForServerto wait for the action client to connect to the server.

  • Send a goal usingsendGoal. Define agoalMsgthat corresponds to the action type. When you create an action client usingrosactionclient, a blankgoalMsgis returned. You can modify this message with your desired parameters.

  • When a goal status becomes'active', the goal begins execution and theActivationFcncallback function is called. For more information on modifying this callback function, seeSimpleActionClient.

  • While the goal status remains'active', the server continues to execute the goal. The feedback callback function processes information about this goals execution periodically whenever a new feedback message is received. Use theFeedbackFcnto access or process the message data sent from the ROS server.

  • When the goal is achieved, the server returns a result message and status. Use theResultFcncallback to access or process the result message and status.

Action Messages and Functions

ROS actions use ROS messages to send goals and receive feedback about their execution. In MATLAB, you can use callback functions to access or process the feedback and result information from these messages. After you create theSimpleActionClientobject, specify the callback functions by assigning function handles to the properties on the object. You can create the object usingrosactionclient.

  • GoalMsg— The goal message contains information about the goal. To perform an action, you must send a goal message with updated goal information (seesendGoal). The type of goal message depends on the type of ROS action.

  • ActivationFcn— Once a goal is received on the action server, its status goes to'pending'until the server decides to execute it. The status is then'active'. At this moment, MATLAB executes the callback function defined in theActivationFcnproperty of theSimpleActionClientobject. There is no ROS message or data associated with this function. By default, this function simply displays'Goal is active'on the MATLAB command line to notify you the goal is being executed.

    The default function handle is:

    @(~) disp('Goal is active')
  • FeedbackFcn— The feedback function is used to process the information from the feedback message. The type of feedback message depends on the action type. The feedback function executes periodically during the goal operation whenever a new feedback message is received. By default, the function displays the details of the message usingshowdetails. You can do other processing on the feedback message in the feedback function.

    The default function handle is:

    @(~,味精)disp (['Feedback: ',showdetails(msg)])

    味精is the feedback message as an input argument to the function you define.

  • ResultFcn— The result function executes when the goal has been completed. Inputs to this function include both the result message and the status of execution. The type of result message depends on the action type. This message,味精和状态,s, are the same as the outputs you get when usingsendGoalAndWait. This function can also be used to trigger dependent processes after a goal is completed.

    The default function handle is:

    @(~,s,msg) disp(['Result with state ',char(s),': ',showdetails(msg)])

See Also

|

Related Topics