Matlab can't receive Topic from Ros_MasterPC .

조회 수: 10 (최근 30일)
Shogo Hirano
Shogo Hirano 2022년 7월 9일
답변: Cam Salzberger 2022년 8월 4일
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에서 Network Connection and Exploration에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by