%% Setup a ROS Action Client and Execute an Action
% This example shows how to create a ROS action client and execute the action. Action types must be set up beforehand with an action server running.
% You must have set up the '/fibonacci' action type. To run this action server, use the following command on the ROS system:
% rosrun actionlib_tutorials fibonacci_server
% Connect to a ROS network. You must be connected to a ROS network to gather information about what actions are available. Replace ipaddress with your network address.

ipaddress = '192.168.17.129';
rosinit(ipaddress,11311)

%
% List actions available on the network. The only action set up on this network is the '/fibonacci' action.

rosaction list

%
% Create an action client. Specify the action name.

[actClient,goalMsg] = rosactionclient('/fibonacci');

%
% Wait for the action client to connect to the server.

waitForServer(actClient);

%
% The fibonacci action will calculate the fibonacci sequence for a given order specified in the goal message. The goal message was returned when creating the action client and can be modified to send goals to the ROS action server.

goalMsg.Order = 8

%
% Send the goal and wait for its completion. Specify a timeout of 10 seconds to complete the action.

[resultMsg,resultState] = sendGoalAndWait(actClient,goalMsg,10)

%

showdetails(resultMsg)

%
% Disconnect from the ROS network.

rosshutdown

% Copyright 2019 The MathWorks, Inc.