send(pub,msg) publishes a
message to the topic specified by the publisher,
pub. This message can be received by
all subscribers in the ROS network that are subscribed to the topic
specified by pub.
Set up a publisher and subscriber to send and receive a message on a ROS network.
Connect to a ROS network.
rosinit
Launching ROS Core...
.................................................Done in 1.0486 seconds.
Initializing ROS master on http://192.168.0.10:51887.
Initializing global node /matlab_global_node_79464 with NodeURI http://bat1073812glnxa64:33431/
Create a publisher with a specific topic and message type. You can also return a default message to send using this publisher.
Modify the message before sending it over the network.
msg.X = 1;
msg.Y = 2;
send(pub,msg);
Create a subscriber and wait for the latest message. Verify the message is the one you sent.
sub = rossubscriber('position')
sub =
Subscriber with properties:
TopicName: '/position'
LatestMessage: [0x1 Point]
MessageType: 'geometry_msgs/Point'
BufferSize: 1
NewMessageFcn: []
pause(1);
sub.LatestMessage
ans =
ROS Point message with properties:
MessageType: 'geometry_msgs/Point'
X: 1
Y: 2
Z: 0
Use showdetails to show the contents of the message
Shut down the ROS network.
rosshutdown
Shutting down global node /matlab_global_node_79464 with NodeURI http://bat1073812glnxa64:33431/
Shutting down ROS master on http://192.168.0.10:51887.
................
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.