【发布时间】:2019-03-23 18:02:31
【问题描述】:
我使用 ROS 从我的 PC 到 RaspberryPi 的通信出现问题,因为我无法从 PC 向 Rasp 发送消息,但反之亦然。我不明白问题出在哪里。
我在我的 PC 和 RaspberryPi 上运行 ros-kinetic,并在两台机器上实现了 ros_pub 和 ros_sub 包。我想在 PC 上使用 ros_pub 包发布传感器消息主题,并在 RaspberryPi 上使用 ros_sub 包订阅该传感器消息主题。
主 URI 正在 RaspberryPi 上运行。
publisher.py
#!/usr/bin/python
import rospy
from std_msgs.msg import String
from ros_msgs.msg import SensorInformation
def publisher():
rospy.init_node('publisher')
pub = rospy.Publisher('message_topic', SensorInformation, queue_size=1)
rate = rospy.Rate(1)
sensor = SensorInformation()
sensor.data.header.stamp = rospy.Time.now()
sensor.data.header.frame_id = "Ultrasonic Sensor Frame"
sensor.data.radiation_type=sensor.data.ULTRASOUND
#sensor.data.field_of_view = 0.5
sensor.data.range = 23.10
#sensor.data.min_range = 0.002
#sensor.data.max_range= 2.00
#sensor.part_number = 14320
#sensor.manufacturer_name= "Sri"
while not rospy.is_shutdown():
pub.publish(sensor)
rate.sleep()
if __name__ == '__main__':
try:
publisher()
except rospy.ROSInterruptException:
pass
订阅者.py
#!/usr/bin/python
import rospy
from std_msgs.msg import String
from ros_msgs.msg import SensorInformation
def subCallback(data):
rospy.loginfo(data.data.range)
def subscriber():
rospy.init_node('subscriber')
rospy.Subscriber('message_topic', SensorInformation, subCallback)
rospy.spin()
if __name__ == '__main__':
try:
subscriber()
except rospy.ROSInterruptException:
pass
SensorInformation.msg
sensor_msgs/Range data
string manufacturer_name
uint32 part_number
PC 的 .bashrc
export ROS_MASTER_URI=http://192.168.1.81:11311/
export ROS_HOSTNAME=192.168.1.102
export ROS_IP=192.168.1.102
RaspPi 的 .bashrc
export ROS_MASTER_URI=http://192.168.1.81:11311/
export ROS_HOSTNAME=192.168.1.81
export ROS_IP=192.168.1.81
当我在 PC 上运行 rosrun ros_pub publisher.py 并测试 rostopic echo /message_topic 时,主题是否在同一台机器上发布。它正在发布带有一些数据的消息
在RaspberryPi上运行rosrun ros_subsubscriber.py,我无法接收到消息数据并测试了rostopic echo /message_topic,如果我能看到任何消息数据,并且没有数据。
这是结果,当我运行 rosnode info /publisher
rosnode info /publisher
--------------------------------------------------------------------------------
Node [/publisher]
Publications:
* /message_topic [std_msgs/String]
* /rosout [rosgraph_msgs/Log]
Subscriptions: None
Services:
* /publisher/get_loggers
* /publisher/set_logger_level
contacting node http://192.168.1.102:44631/ ...
ERROR: Communication with node[http://192.168.1.102:44631/] failed!
但是,反之亦然,即发布者为 RaspberryPi,订阅者为 PC。
问题可能出在哪里?解决办法是什么?
另外,使用 rospy_tutorials 我尝试在 PC 上运行talker.py 和在 RaspberryPi 上运行 listener.py,我无法在 RaspberryPi 上收到消息。
此外,我还有一个基本问题,如下所述: 电脑上
netcat -l 1234
在 RaspPi 上
netcat 192.168.1.102 1234
这没有结果,至少没有错误。
然后我运行下面没有给主机的路由,
netcat -nvz -w 1 192.168.1.102 1234
netcat: connect to 192.168.1.102 port 1234 (tcp) failed: No route to host
【问题讨论】:
-
您的PC是否与master正确连接?
-
它已正确连接,否则当我从 PC 运行 rostopic echo 时,它不应该成功运行,我会收到错误消息“无法与 Master 通信”或其他东西,但我得到了结果电脑
-
尝试在终端上使用
rostopic pub将内容发布到您想要的方向(这不起作用)并尝试在另一端使用rostopic echo。 -
我不明白你的意思是“rostopic pub”,为什么它会发布一些东西??
-
rostopic pub是发布主题的命令实用程序。它需要几个其他参数,但它是测试两台机器是否可以相互通信的有效方法。
标签: python raspberry-pi iptables ros netcat