Robotics StackExchange | Archived questions

rostopic pub/echo not working on single pc system

I'm working my way through the tutorials in the wiki one by one and I and into some issues in the 'Examining the Simple Publisher and Subscriber' tutorial (link text). All my code is identical to that of the code within.

The Issue was that the listener wasnt picking up what the publisher was publishing.

Trying to troubleshoot I got to the point where I was simply trying to publish to a topic then echo it in the terminal, similar to this tutorial, but I couldn't relpicate these results. ie echo something published to a topic. In this case aftering trying rostopic pub /hello std_msgs/String “Hello Robot", rostopic list would display /hello /rosout /rosout_agg but rostopic echo /hello yields nothing.

Any help would be greatly appreciated, is there anything else that would help answer my question?

Currently using kinetic 1.12.12 on a single machine running Ubuntu.

EDIT - Extra Info:

The output of roscore is:

... logging to /home/nvidia/.ros/log/55fbfc34-fb20-11e7-91c6-00044b8d27bd/roslaunch-tegratx2-ubuntu-3563.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://localhost:34786/
ros_comm version 1.12.12


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.12

NODES

auto-starting new master
process[master]: started with pid [3574]
ROS_MASTER_URI=http://localhost:11311/

setting /run_id to 55fbfc34-fb20-11e7-91c6-00044b8d27bd
process[rosout-1]: started with pid [3587]
started core service [/rosout]

The output of env | grep -i ros | sort is:

CMAKE_PREFIX_PATH=/home/nvidia/TestCatkinWS/devel:/opt/ros/kinetic
LD_LIBRARY_PATH=/home/nvidia/TestCatkinWS/devel/lib:/opt/ros/kinetic/lib:/usr/local/lib:/usr/local/lib:/usr/local/cuda-8.0/lib64
PATH=/opt/ros/kinetic/bin:/usr/local/cuda-8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
PKG_CONFIG_PATH=/home/nvidia/TestCatkinWS/devel/lib/pkgconfig:/opt/ros/kinetic/lib/pkgconfig
PYTHONPATH=/home/nvidia/TestCatkinWS/devel/lib/python2.7/dist-packages:/opt/ros/kinetic/lib/python2.7/dist-packages
ROS_DISTRO=kinetic
ROS_ETC_DIR=/opt/ros/kinetic/etc/ros
ROS_IP=10.222.146.184
ROSLISP_PACKAGE_DIRECTORIES=/home/nvidia/TestCatkinWS/devel/share/common-lisp
ROS_MASTER_URI=http://localhost:11311
ROS_PACKAGE_PATH=/home/nvidia/TestCatkinWS/src:/opt/ros/kinetic/share
ROS_ROOT=/opt/ros/kinetic/share/ros

The output of ip addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether d2:02:37:ef:73:7d brd ff:ff:ff:ff:ff:ff
3: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 00:04:4b:8d:27:bf brd ff:ff:ff:ff:ff:ff
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1
    link/ipip 0.0.0.0 brd 0.0.0.0
5: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:04:4b:8d:27:bd brd ff:ff:ff:ff:ff:ff
    inet 10.222.76.123/16 brd 10.222.255.255 scope global dynamic wlan0
       valid_lft 3419sec preferred_lft 3419sec
    inet6 fe80::f95b:2b75:ad28:20e2/64 scope link 
       valid_lft forever preferred_lft forever

The output of route -n is:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.222.0.1      0.0.0.0         UG    600    0        0 wlan0
1.1.1.1         10.222.0.1      255.255.255.255 UGH   600    0        0 wlan0
10.222.0.0      0.0.0.0         255.255.0.0     U     600    0        0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlan0

The addresses are different but consistent

Asked by TheMilkman on 2018-01-16 00:07:04 UTC

Comments

Could you add the output of env | grep -i ros | sort, ip addr show and route -n to your question? Feel free to redact your IP addresses, but be consistent.

Edit: perhaps also add the output of roscore.

Make sure to use the Preformatted Text button for everything.

Asked by gvdhoorn on 2018-01-16 03:37:02 UTC

Also, try to add a -r 10 after the rostopic pub ... command. This publishes the message with 10 Hz. It might be that the one-time message is lost between publishing and subscribing with rostopic echo.

Asked by mgruhler on 2018-01-16 05:08:55 UTC

@mig: good suggestion. I assumed that OP had started rosptopic echo /hello before the rostopic pub .., but it could definitely be the case that the message is lost because the subscription is not yet there.

Asked by gvdhoorn on 2018-01-16 05:14:25 UTC

Thanks @gvdhoorn and @mig for your quick replies! I've added the extra info in the original question.

@mig I tried both ways to be honest to no avail. I thought the latching of the rostopic pub would mean the message would stay there until its picked up by a subscriber anyway?

Asked by TheMilkman on 2018-01-16 20:09:58 UTC

Try removing the ROS_IP environment variable, as you are doing all of this locally and it shouldn't be needed. It is different to the ROS_MASTER_URI which may be causing issues.

Asked by ufr3c_tjc on 2018-01-16 23:05:42 UTC

... and in fact it doesn't match any of your interface IP's so is probably the cause. I'm not sure if setting it to localhost will work, but try remove it completely and restart your terminals and retry pub/sub.

Asked by ufr3c_tjc on 2018-01-16 23:07:38 UTC

Thanks @ufr3c_tjc! That got the rostopic pub/echo working. Although rostopic pub /hello std_msgs/String hello outputs 7 iterations of invalid ROS_IP (an empty string) to the terminal. I've probably not removed it correctly?

Also, this didn't fix the talker/listener tutorial, any other ideas?

Asked by TheMilkman on 2018-01-16 23:19:22 UTC

Where are you setting the ROS_IP variable? Is it in your ~/.bashrc file? If so, just take that line out. You want to remove the variable, not set it to empty.

Asked by ufr3c_tjc on 2018-01-16 23:25:41 UTC

Thanks for your help! Everything works like a dream! So ROS_IP is used when communicating between multiple machines?

Asked by TheMilkman on 2018-01-16 23:36:08 UTC

Can you suggest any resources (other than the wiki/tutorials) for learning about ROS?

Asked by TheMilkman on 2018-01-17 00:03:22 UTC

Yes, ROS_IP is used when networking between PCs. There are many ROS tutorials across the core packages. Start with core items such as topics, TF, frames, URDF etc. Then you can move into navigation stack and MoveIt. A book like...

Asked by ufr3c_tjc on 2018-01-17 00:56:05 UTC

this one would also be a good resource to learn from.

Asked by ufr3c_tjc on 2018-01-17 00:56:25 UTC

@ufr3c_tjc can you post the solution as an answer? thx.

Asked by mgruhler on 2018-01-17 02:25:21 UTC

Yes, ROS_IP is used when networking between PCs

This is not entirely accurate: ROS_IP can also be used to disambiguate between multiple IPs on a multi-homed system. That does not always mean multiple (physical) machines need to be involved in the communication.

Asked by gvdhoorn on 2018-01-17 03:01:04 UTC

@TheMilkman: can you tell us why you set ROS_IP initially? And with that value?

Asked by gvdhoorn on 2018-01-17 03:02:25 UTC

@gvdhoorn I initially set ROS_IP to localhost so I could get roscore to run, was having issues starting it from time to time.

Asked by TheMilkman on 2018-01-28 18:55:15 UTC

In hindsight though, I should have only set ROS_MASTER_URI though right? Since I'm working on a single PC system @gvdhoorn

Asked by TheMilkman on 2018-02-18 18:04:53 UTC

If this is really just a stand-alone system (ie: no other network hosts involved), then you shouldn't have had to set any of those variables.

Unless you have a multi-homed system and roscore was choosing a wrong (ie: unreachable) IP address, it should've just worked.

Asked by gvdhoorn on 2018-02-19 02:30:19 UTC

Yeah okay, maybe because I was trying to fix things while not really unserstanding what I was doing I broke other components unknowingly, oops

Asked by TheMilkman on 2018-03-14 20:35:36 UTC

Answers

replace " to ' works for me

Asked by oldorange on 2019-01-03 22:29:09 UTC

Comments

Can you clarify what you write here? What is "to"?

Asked by gvdhoorn on 2019-01-04 03:10:24 UTC