ROS in Simulink never receive anything

I am having really hard time getting ROS in Simulink to receive any messages from a remote PC.

It never works in MatLab either but here's the rub:
I run
rosinit('111.111.0.8') % a sudo address for my remote running turtlebot3_fake
I then jump over to Simulink and create a model that looks like this:

I hit run and it is always zero. What am I doing wrong?

Cheers,

Coach

 Accepted Answer

More specifically, you also need to set ROS_MASTER_URI and ROS_IP as specified in the mentioned link to connect to a remote master. Additionally, make sure that you can successfully ssh into the remote server.

3 Comments

Ameer,
I am going nuts here! I turned off my Jetson TX2 and turned it back on. The TX2 is where my MASTER is running.
On MatLab, I do the following:
% Jetson TX2 IP address
jetson_node_address = '192.xxx.x.8'
% Initialize ROS
rosinit(jetson_node_address,11311,"NodeName","matlab_node")
rosnode list
/matlab_node
/rosout
>> rostopic list
/rosout
/rosout_agg
>> rostopic list
/clock
/cmd_vel
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/imu
/joint_states
/odom
/rosout
/rosout_agg
/scan
/tf
So clearly, this means there is a connection right?
Next, I run these examples:
laser = rossubscriber('/scan');
>> scandata = receive(laser, 10);
Error using ros.Subscriber/receive (line 294)
The function did not receive any data and timed out.
>> odom = rossubscriber('/odom')
odom =
Subscriber with properties:
TopicName: '/odom'
MessageType: 'nav_msgs/Odometry'
LatestMessage: [0×1 Odometry]
BufferSize: 1
NewMessageFcn: []
>> odomdata = receive(odom, 10)
Error using ros.Subscriber/receive (line 294)
The function did not receive any data and timed out.
I moved my install to a windows based PC and viola! I would like the MatLab folks to maybe consider this a bug.
Orginal install:
MacBookPro
OS Mojave
It appears to be some issues with network configuration or the setting of environment variables. I am able to receive a message published by a node from an external server in MATLAB running on macOS Catalina, and I have previously done it on Mojave too.
The problem you mentioned: you are able to get the node list but cannot receive a message from a subscribed topic that happens when environment variables on the master server and MATLAB are not set properly. This link explains how to configure these variables: https://www.mathworks.com/matlabcentral/answers/119559-why-is-the-ros-subscriber-callback-in-matlab-not-triggered-when-messages-are-published-from-an-exter

Sign in to comment.

More Answers (0)

Products

Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!