www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/UseAROSPublisherObjectExample.m

    %% Use ROS Publisher Object
% Create a |Publisher| object using the class 
% constructor.
%%
% Start the ROS master.

% Copyright 2015 The MathWorks, Inc.

master = robotics.ros.Core;
%%
% Create a ROS node, which connects to the master.
node = robotics.ros.Node('/test1');
%%
% Create a publisher and send string data. The publisher attaches to the 
% node object in the first argument.
pub = robotics.ros.Publisher(node, '/robotname', 'std_msgs/String');
msg = rosmessage(rostype.std_msgs_String);
msg.Data = 'robot1';
send(pub,msg);

%%
% Clear the publisher and ROS node. Shut down the ROS master.
clear('pub','node')
clear('master')