www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/UseAROSSubscriberObjectExample.m
%% Use ROS Subscriber Object % Use a ROS |Subscriber| object to receive messages over the ROS network. % Copyright 2015 The MathWorks, Inc. %% % Start the ROS master and node. master = robotics.ros.Core; node = robotics.ros.Node('/test'); %% % Create a publisher and subscriber to send and receive a message over the % ROS network. pub = robotics.ros.Publisher(node,'/chatter','std_msgs/String'); pause(1) sub = robotics.ros.Subscriber(node,'/chatter','std_msgs/String'); %% % Send a message over the network. msg = rosmessage(rostype.std_msgs_String); msg.Data = 'hello world'; send(pub,msg) %% % View the message data using the |LatestMesasge| 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')