Search code examples
sshubuntu-16.04raspberry-pi3ubuntu-18.04ros

Raspberry Pi is not able to subscribe to ros topic published from base PC but vice-verse is working?


I am using the ubiquityrobotics Raspberry Pi image for the RPi 3B+, which is Ubuntu Xenial and ROS Kinetic. My base computer is running Ubuntu 18.04 and has ROS Melodic installed. I created subo_base workspace in the base PC and subo_rpi workspace in the RPi (assessing the RPi via ssh). Then I created a package in both the base PC and RPi and added the Publisher and Subscriber (http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29) files in each of the packages. When I run the publisher from the RPi, the base PC is able to subscribe but when I publish from the base PC, the RPi does not show any output and remains stuck (even though the Topic is visible on RPi using rostopic list).

Base PC is able to subscribe to RPi

RPi unable to subscribe to topic from PC

Some of the code is used in base PC

aakash@aakash:~$ mkdir -p ~/subo_base/src
aakash@aakash:~$ cd ~/subo_base/
aakash@aakash:~/subo_base$ catkin_make
aakash@aakash:~/subo_base$ source devel/setup.bash
aakash@aakash:~/subo_base$ echo $ROS_PACKAGE_PATH
aakash@aakash:~/subo_base$ cd ~/subo_base/src/
aakash@aakash:~/subo_base/src$ catkin_create_pkg motion_plan std_msgs rospy roscpp

To connect to RPi

aakash@aakash:~/subo_base/src/motion_plan/scripts$ export ROS_MASTER_URI=http://ubiquityrobot.local:11311
aakash@aakash:~/subo_base/src/motion_plan/scripts$ export ROS_IP='hostname -I'

Further, I am able to transfer files from and to the base PC via ssh scp so I guess netwkr might not be the issue?


Solution

  • The issue is most likely the hostname resolution and/or ROS network variable configuration.

    I dislike using the hostname in the variables, so I will give the examples using just IPs.

    Also the 'hostname -I' is definitely not suitable for setting your ROS_IP variable in all cases. So that might also be one source of your problem.

    From hostname man page

    -I, --all-ip-addresses>

    Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces. The loop‐back interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend on name resolution. Do not make any assumptions about the order of the output.

    You will want to use whatever specific ip address you need, so just use that or find a better way to determine which ip to set. echo $ROS_IP or printenv | grep ROS will tell you what your variables are currently set to so you can verify it is set correctly.

    For minimal proof that things are working you could try the following:

    Lets say your RPi ip is 192.168.0.2 and PC ip is 192.168.0.3

    You will need to decide which machine will be the master, for this example I will assume the PC will be the master.

    In a terminal on the PC run the following commands:

    roscore

    in a different terminal run (this is used instead of the subscriber/publisher node to test if things work)

    rostopic pub /test/topic std_msgs/String 'Hello World from PC' -r 1

    Now on the SSH terminal on the RPi run:

    export ROS_MASTER_URI=http://192.168.0.3:11311 && export ROS_IP=192.168.0.2

    now you should be able to echo the topic published on the PC from the SSH window.

    rostopic echo /test/topic

    ctrl+c out of the echo and you can try publishing some message on the RPi like:

    rostopic pub /test2/topic std_msgs/String 'Hello World from RPi' -r 1

    Now open a new terminal on the PC and try to echo the topic from RPi, any terminal sourced with the ROS installspace, usually source /opt/ros/kinetic/setup.bash, should work:

    rostopic echo /test2/topic

    ROS wiki page on running ROS on multiple machines

    ROS answer regarding setting up multiple machines