【问题标题】:ROS communication from PC to RaspberryPi从 PC 到 RaspberryPi 的 ROS 通信
【发布时间】: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


【解决方案1】:

问题与您的 ROS 主网络配置有关。

由于您可以 ping 主机但订阅者无法订阅主题,这表明主计算机(在您的情况下为 RaspberryPi)可能不接受远程连接,而只接受本地连接。为了验证这个假设,尝试在你的 RaspberryPi 上同时运行发布者和订阅者,你应该会得到想要的结果。如果是这样,那么在 ROS master 上进行如下配置:

export ROS_IP=0.0.0.0

这是监听任何接口。

如果这能解决问题,请尝试,否则,请尝试以下操作:

将以下内容添加到您 PC 的 /etc/hosts

192.168.1.81 PUT_HOSTNAME_OF_RASPBERRYPI_HERE

【讨论】:

  • 不,您提供的两种解决方案都没有解决问题。我在 PC 和 netcat raspberrypi 1234 上有相同的基本问题 netcat -l 1234,不起作用。但是,反之亦然!
【解决方案2】:

所以,在彻底了解了我的问题并收集了有关 linux 网络/配置的知识后,我意识到问题出在我的 PC/Linux 的防火墙配置上,它阻止了访问。

基本上,iptables 是 Linux 上的默认防火墙。我通过运行以下命令清除了 PC 上的 iptables 规则

# iptables -F
# iptables -X
# iptables -t nat -F
# iptables -t nat -X
# iptables -t mangle -F
# iptables -t mangle -X

这行得通! :D

来源:https://www.cyberciti.biz/tips/no-route-to-host-error-and-solution.html

【讨论】:

  • 这很奇怪。通常,当我使用 ROS 配置新机器时,我不会遇到此类问题。但是很好地解决了这个问题。
  • 我看到一台计算机有类似的问题,但从来没有完全弄清楚我们的根本原因。我们最终不得不对系统进行核攻击。
  • Linux机器的防火墙配置与ROS无关..当我看到iptables时,已经配置了很多(包括自动配置的docker相关),我使用它已经超过3个月了操作系统,我不知道该配置何时更改,或者不知道该防火墙配置是否包含该操作系统 Ubuntu 18.04。如果出现此类问题,我建议从防火墙配置开始分析问题。
【解决方案3】:

我也遇到了同样的问题!我一直在尝试很多不同的东西,一切都归功于我的 Ubuntu 18.04 防火墙!它阻止了连接,即使我能够 ping 并且 rostopic 和 rosnode 列表似乎很好! 但是,这种清除 Srivardhan Cholkar 给出的 iptables 规则的方式 对我不起作用,它正在关闭我的 Internet 连接...

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

我通过运行解决了它:

sudo ufw disable

并且成功了!

来源:https://linuxconfig.org/how-to-enable-disable-firewall-on-ubuntu-18-04-bionic-beaver-linux

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 2012-11-13
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多