getFeedbackMessage
Description
creates and returns an empty message, msg
= getFeedbackMessage(server
)msg
, whose message type is
determined by the action type of server
. The format of
msg
is determined by the DataFormat
property of
the action server. This message is the default feedback message that this server sends to
the client while executing a goal.
Examples
Create ROS Action Server and Execute Goal
This example shows how to create a ROS action server, connect an action client to it, receive goal, and execute it.
Connect to a ROS network.
rosinit
Launching ROS Core... ..Done in 2.1278 seconds. Initializing ROS master on http://172.19.136.75:52554. Initializing global node /matlab_global_node_56708 with NodeURI http://vdi-wd1bgl-223:61999/ and MasterURI http://localhost:52554.
Set up an action server for calculating Fibonacci sequence. Use structures for the ROS message data format. Use fibbonacciExecution
function as the callback.
cb = @fibonacciExecution; server = rosactionserver("/fibonacci","actionlib_tutorials/Fibonacci",ExecuteGoalFcn=cb,DataFormat="struct")
server = SimpleActionServer with properties: ActionName: '/fibonacci' ActionType: 'actionlib_tutorials/Fibonacci' ExecuteGoalFcn: @fibonacciExecution DataFormat: 'struct'
Create action client and send a goal to the server to calculate the Fibonacci sequence up to 10 terms past the first two terms, 0
and 1
. Display the result sequence.
client = rosactionclient("/fibonacci","actionlib_tutorials/Fibonacci",DataFormat="struct"); goal = rosmessage(client); goal.Order = int32(10); result = sendGoalAndWait(client,goal); result.Sequence
ans = 12×1 int32 column vector
0
1
1
2
3
5
8
13
21
34
⋮
Shut down ROS network.
rosshutdown;
Shutting down global node /matlab_global_node_56708 with NodeURI http://vdi-wd1bgl-223:61999/ and MasterURI http://localhost:52554. Shutting down ROS master on http://172.19.136.75:52554.
Warning: Error shutting down the ROS master.
Supporting Functions
The callback function fibbonacciExecution
is executed every time the server receives a goal execution request from the client. This function checks if the goal has been preempted, executes the goal and sends feedback to the client during goal execution.
function [result,success] = fibonacciExecution(src,goal,defaultFeedback,defaultResult) % Initialize variables success = true; result = defaultResult; feedback = defaultFeedback; feedback.Sequence = int32([0 1]); for k = 1:goal.Order % Check that the client has not canceled or sent a new goal if isPreemptRequested(src) success = false; break end % Send feedback to the client periodically feedback.Sequence(end+1) = feedback.Sequence(end-1) + feedback.Sequence(end); sendFeedback(src,feedback) % Pause to allow time to complete other callbacks (like client feedback) pause(0.2) end if success result.Sequence = feedback.Sequence; end end
Input Arguments
server
— ROS action server
SimpleActionServer
object handle
ROS action server, specified as a SimpleActionServer
object
handle.
Output Arguments
msg
— Default feedback message
ROS message
Default feedback message, returned as a ROS message whose type is determined by the
action type of server
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2022a
See Also
rosactionserver
| sendFeedback
| rosActionServerExecuteGoalFcn
| rosmessage
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)