ros2actionserver
Description
The ros2actionserver
object creates a ROS 2 action server in
MATLAB®. You can use a ros2actionclient
object from another MATLAB session to create an action client, connect to the action server, and request
the execution of action goals. When a connected client sends a goal execution request, the
server executes the callback function ExecuteGoalFcn
. The server can
provide periodic feedback on execution progress to the clients, preempt a goal upon receiving
a cancel request, and abort a goal if an error occurs during goal execution.
ros2actionserver
can accept multiple goals, but executes the goals in a
first-in, first-out manner.
An action is defined by a type and three messages: one message for the goal, one for the feedback, and one for the result. On receiving a goal, the server calls the goal reception callback to decide whether to accept or reject the goal. If the server accepts the goal, the server goal execution callback must periodically send feedback to the client during goal execution, and return an appropriate result when goal execution completes. The behavior of the action server is inherently asynchronous because it becomes active only when an action client connects to the ROS 2 network and issues a goal execution request.
Creation
Syntax
Description
creates an action server object, server
= ros2actionserver(node
,actionname
,actiontype
,ExecuteGoalFcn
=cb)server
, that corresponds to the
ROS 2 action of the specified name actionname
and type
actiontype
and attaches it to the ROS 2 node specified by the
ros2node
object
node
. You must also specify the
ExecuteGoalFcn
property as a function handle callback,
cb
, which handles goal execution when the client sends a
goal.
sets additional properties using one or more server
= ros2actionserver(node
,actionname
,actiontype
,ExecuteGoalFcn
=cb,Name=Value)Name=Value
arguments.
Properties
Object Functions
ros2message | Create ROS 2 message structures |
getFeedbackMessage | Create new ROS 2 action feedback message |
handleGoalResponse | Accept or reject new ROS 2 action goal and send status |
isPreemptRequested | Check if a goal has been preempted |
sendFeedback | Send feedback to ROS 2 action client during goal execution |
Examples
Limitations
If a ROS 2 action server and the action clients connected to it are running in the same MATLAB session, the server cannot process cancel requests from the client.
Extended Capabilities
Version History
Introduced in R2023b