%% Use ROS Subscriber Object
% Use a ROS Subscriber object to receive messages over the ROS network.
% Start the ROS master and node.

master = ros.Core;
node = ros.Node('/test');

%
% Create a publisher and subscriber to send and receive a message over the ROS network.

pub = ros.Publisher(node,'/chatter','std_msgs/String');
pause(1)
sub = ros.Subscriber(node,'/chatter','std_msgs/String');

%
% Send a message over the network.

msg = rosmessage('std_msgs/String');
msg.Data = 'hello world';
send(pub,msg)

%
% View the message data using the LatestMessage property of the Subscriber object.

pause(1)
sub.LatestMessage

%
% Clear the publisher, subscriber, and ROS node. Shut down the ROS master.

clear('pub','sub','node')
clear('master')

% Copyright 2012 The MathWorks, Inc.
%