Matlab can't receive Topic from Ros_MasterPC .

9 次查看(过去 30 天)
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

回答(1 个)

Cam Salzberger
Cam Salzberger 2022-8-4
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

类别

Help CenterFile Exchange 中查找有关 ROS Network Access in MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by