Why can't I publish ROS messages using simulink?

3 views (last 30 days)
Hi,
I am testing exchange data between simulink and ROS. I have a laptop running a ROS project called tuetlesim, which is a example project of ROS. In this ROS project, a turtle will move according to the command from the topic called /turtle1/cmd_vel . The type of the message of the topic is geometry_msgs/Twist.
What I want to do is using simulink to publish the message and move the turtle. So,
Firstly, I set my network in matlab and ubuntu
% in matlab
setenv('ROS_MASTER_URI','http://192.168.1.250:11311')
% in ubuntu ~/.bashrc
export ROS_IP=192.168.1.250
Secondly, I test the network in matlab. It works and can show all topics
rosinit
rostopic list
Finally, I create a model as below. In this model, I also use a subscriber to subscribe the topic called /turtle1/pose, which contains the position(X/Y) of the turtle. This subscriber work perfectly. However, the publisher doesn't work.
configuration of publisher
In ubuntu, I check the node by rqt_graph. It shows that simulink successfully connect to the master.
However, there is no message can be receive from the /turtle1/cmd_vel.
Can anyone give me any hint about why this behaviour?
Thank you very much in advance,
Regards,
Liam

Answers (1)

Josh Chen
Josh Chen on 24 Apr 2023
Hello Liam,
When this kind of "only one way communication available" happens, it usually has something to do with the setting of environment variables or virtual machine.
Some ideas of troubleshooting for your reference:
  1. Are you able to receive message sent from MATLAB instead of Simulink?
  2. Check the setting for ROS_MASTER_URI and ROS_IP for both MALTAB and Ubuntu (See more details in this post)
  3. Are you using VMware Player? If yes, what kind of Network connection did you pick? We always find "NAT" is a good option.
  4. In general, you could probably just start ROS Master in VM, and use "rosinit('<ip_address>')" in MATLAB to make the connection. Please feel free to reach out to our technical support team if you are still facing this issue.
Hope this helps,
Thanks,
Josh

Categories

Find more on Publishers and Subscribers in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!