ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS_Matlab subscriber

asked 2014-03-27 04:44:06 -0500

Sanxano gravatar image

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);

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-04 13:51:47 -0500

AndyZe gravatar image

updated 2015-03-28 21:58:47 -0500

I added two lines to ~/.bashrc to make sure roscore has a predictable URI:

export ROS_IP=192.168.1.11 <== your computer's IP

export ROS_MASTER_URI=http://192.168.1.11:11311

To connect in MATLAB:

% Run the rosmatlab setup scripts

addpath([matlabroot '/toolbox/psp/rosmatlab/']);

rosmatlab_SetPath;

rosmatlab_AddClassPath;

% Connect to roscore which should be running in a terminal

node = rosmatlab.node('MATLAB_NODE', '192.168.1.11', 11311);

% Subscribe to the 'state' topic to receive updates on the state.

% The message type is lyap_control/plant

subscriber = rosmatlab.subscriber('state', 'lyap_control/plant', 1, node);
edit flag offensive delete link more

Comments

Does it work or not?? I can't subscribe from Matlab to ros topic, it seems to be unidirectional. Please, let me know if you solved it and share the full solution! thanks!!!

dottant gravatar image dottant  ( 2015-03-02 05:11:27 -0500 )edit

I want to know ,too.I meet the same problem give you a link,maybe can help you link text

ziyeshanwai gravatar image ziyeshanwai  ( 2015-03-28 21:32:04 -0500 )edit

Yeah, it works, guys. Have you tried it? Make sure the ip that you specify with ROS_IP is your computer's current IP.

AndyZe gravatar image AndyZe  ( 2015-03-28 21:58:11 -0500 )edit

Yes,I have tried.I worked!

ziyeshanwai gravatar image ziyeshanwai  ( 2015-03-29 04:36:50 -0500 )edit

Question Tools

Stats

Asked: 2014-03-27 04:44:06 -0500

Seen: 1,154 times

Last updated: Mar 28 '15