ROS_Matlab subscriber
Hi,
I'm using Matlab/ROS interface (with Matlab R2013a and ROS fuerte)
I've done the Matlab example where a node publish and subscriber from Matalb and this example works without problem. But now I have gazebo running and I want to subscrib from Matlab and It doesn't work.. Could anyone tell me what is wrong?
I do: roscore
roslaunch gazebo_world ....
and execute this code from Matlab:
global rosMasterIp; rosMasterIp = '127.0.1.1';
global localhostIp; localhostIp = '127.0.0.1';
% Create a new node named /NODE and connect it to the master.
node = rosmatlab.node('NODE', rosMasterIp, 11311, 'rosIP', localhostIp);
% Add a publisher of a topic named /TOPIC to the node to send message of type std_msgs/String.
publisher = rosmatlab.publisher('TOPIC','std_msgs/String',node);
% Add a subscriber to a topic named /TOPIC to the node to receive message
subscriber = rosmatlab.subscriber('TOPIC','std_msgs/String',1,node)
%Gazebo topic
subscriber2 = rosmatlab.subscriber('gazebo/model_states', 'gazebo_msgs/ModelStates',1,node);
subscriber.setOnNewMessageListeners({@function1}); subscriber2.setOnNewMessageListeners({@function2});
% Create a new message of type std_msgs/String.
msg = rosmatlab.message('std_msgs/String',node);
% Set the data field of the message and then publish the message
msg.setData(sprintf('Message created: %s',datestr(now)));
publisher.publish(msg); pause(1);