Matlab can't receive Topic from Ros_MasterPC .

11 views (last 30 days)
Good morning, everyone.
I want to use Matlab on Windows10 and Ros on Ubuntu18.04 to exchange data with each other.
I can send Topic using rospublisher, but I cannot receive Topic (chatter2) properly using rossubscriber.
Please solve this problem.
Ros side
Terminal1
$ export ROS_IP=192.168.**. **
$ roscore
Terminal2
$ rosrun *** pub_matlab.py
< pub_matlab.py >
#! /usr/bin/env python
import rospy
from std_msgs.msg import String
def talker():
pub = rospy.Publisher('chatter2', String, queue_size=10)
rospy.init_node('Pub_matlab', anonymous=False)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = 'Hello'
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
Matlab side
>>rosinit('http://192.168.**. **:11311','NodeName','/matlab')
>>sub = rossubscriber("/chatter2", "std_msgs/String")
>>sub =
Subscriber property:
TopicName: '/chatter2'
LatestMessage: [0 x 1 String].
MessageType: 'std_msgs/String'
BufferSize: 1
NewMessageFcn: []
>> rostopic list
/chatter2
/rosout
/rosout_agg
/statistics
/tf
>> rostopic info /chatter2
Type: std_msgs/String
Publisher:
* /Pub_matlab (http://*****-19115N-CLR:******/)
Subscriber:
* /matlab (http://192.168.**. **:*****/)
>> rosnode ping Pub_matlab
Sends a ping to the Pub_matlab node with a timeout of 3 seconds.
No ping response.
No ping response.
No ping response.
No ping response.
Average ping response time: NaN milliseconds

Answers (1)

Cam Salzberger
Cam Salzberger on 4 Aug 2022
Hello Shogo,
This is probably the most common ROS communication issue I've seen. Usually the issue is that ROS_IP is not set in the terminal that you create the non-MATLAB publisher on. That seems to be the case here.
See this answer for more information.
-Cam

Categories

Find more on Network Connection and Exploration 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!