Ask Your Question

Waiting for subscriber to connect to /cmd_vel

asked 2021-02-22 19:53:51 -0600

RobotHunter gravatar image

I'm doing a project to control a Sunfounder robot car kit, which includes a PCA9685 servo controller and TB6612 motor driver, using ROS. My current step is to control it directly with keyboard commands using teleop_twist_keyboard. I used this tutorial and code from Tiziano Fiorenzani, slightly modified where necessary. I have ROS Noetic installed on the robot and my laptop, and I run three nodes on the robot: roscore, the servo driver package, and the low level control package. On my laptop, I run roscore and teleop_twist_keyboard.

However, when I run the node, I get the message "Waiting for subscriber to connect to /cmd_vel" continuously. When I do rostopic list on the laptop, it shows it sees the /cmd_vel topic. Letting the node run for several minutes doesn't change anything. A few things I should point out:

  • In the tutorial, Fiorenzani stores most files on the laptop and uses Samba to bring them over to the robot car: I installed the files directly on the robot car
  • The subscriber object is coded in the low level control package node
  • My Ubuntu laptop and the robot car are actually running two different ROS distros: my Ubuntu laptop is on ROS Melodic, while the car is ROS Noetic. I read somewhere that this shouldn't be a major issue but perhaps it's what's causing this.

Does anyone know what could be causing this? Thanks for your help.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-02-23 01:22:39 -0600

mgruhler gravatar image

I run three nodes on the robot: roscore, the servo driver package, and the low level control package. On my laptop, I run roscore and teleop_twist_keyboard.

This is the root cause of your issue. In general, ROS allows only for one roscore to be running (there are approaches to having multiple masters, but let's put those aside for now). The roscore then coordinates all topics and how the different nodes communicate (i.e. it sets up the transports for the messages etc). Note that the roscore is not a "node".

Have a look at the Networking wiki page. You should (at least) have ROS_MASTER_URI properly set on the machine where the roscore is NOT running. I suggest you start the roscore on your robot. Having set either ROS_IP or ROS_HOSTNAME (never both!) might be required too. Note that you have to export those environment variables in every terminal!

my Ubuntu laptop is on ROS Melodic, while the car is ROS Noetic.

This might be the cause of several problems, but not of what you are experiencing here. This is clearly an issue with in improperly configured network. I would, in general, advise against mixing distros, but for exchanging simple and stable messages you should usually be fine. Sending only a Twist message should work (but I haven't tested that...)

When I do rostopic list on the laptop, it shows it sees the /cmd_vel topic

rostopic list will display any available topic. I.e. any topic on the system (here: your laptop) that any node subscribes or publishes to. even if there is nothing on the other end. So seeing the cmd_vel topic on your laptop basically only tells you that your teleop_keyboard node is publishing to it. use rostopic info to get more information about a topic, such as which node publishes or subscribed to it...

edit flag offensive delete link more


I didn't start a roscore on my laptop and exported ROS_MASTER_URI and ROS_IP, however I still got the same issue. I ran rostopic info /cmd_vel from my laptop, and /picar_llc from the raspberry pi is listed as a subscriber. So that tells me that the laptop and robot are connected and the subscriber is coded correctly.

Any ideas what could be the issue? One thing I noticed is that the port I connected to in ROS_MASTER_URI, which is the port given in the top of the robot's roscore terminal, is different than the port listed as the subscriber to /cmd_vel. I'll try exporting to that instead and see if it works.

EDIT: Very odd, I tried that, and the export ROS_MASTER_URI and export ROS_IP commands both worked, but when I tried anything to do with rostopic I got a traceback error.

RobotHunter gravatar image RobotHunter  ( 2021-02-23 13:57:51 -0600 )edit

you should only export the port of the roscore, not what the single subscribers/publishers use. As long as you haven't changed anything, the default port is 11311.

Have you checked all the information provided in the Wiki link I provided? Can you ping back and forth? Maybe provide a screenshot of rosrun rqt_graph rqt_graph, with basically everything checked. Also, roswtf might help in debugging issues.

mgruhler gravatar image mgruhler  ( 2021-02-24 06:12:35 -0600 )edit

I didn't read the entire wiki page yet, but I tried pinging between both machines and they both were able to ping each other. I kept going up until the "netcat" part, and the command netcat -1 1234 doesn't seem to work because it doesn't recognize the "-1". Overall though since they can ping each other that shouldn't be necessary. However, and this is pretty confusing, I ssh-ed to the Raspberry Pi to run rosrun rqt_graph rqt_graph with the intention of posting it here and, it can't find the rqt_graph package. I sourced setup.bash and bashrc, but I still can't access rqt_graph. I'm not sure if there's something wrong with the way that I installed ROS on the Pi, because I also had to manually install common_msgs to use geometry_msgs. I was able to publish to ROS topics and directly control ...(more)

RobotHunter gravatar image RobotHunter  ( 2021-02-24 16:25:42 -0600 )edit

answered 2021-02-23 00:22:19 -0600

mugetsu gravatar image

are you able to see any the topics from the robot via your laptop? And can your robot see any topics from your laptop? make sure to set ROS_MASTER_URI to your laptop on the robot

edit flag offensive delete link more


Running rostopic list on the laptop, I can see the topics running on the robot. I haven't checked whether the robot can see topics running on the laptop, however. And as for ROS_MASTER_URI, I did export it from the laptop to the robot, but not from the robot to the laptop.

RobotHunter gravatar image RobotHunter  ( 2021-02-23 00:59:32 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-02-22 19:53:51 -0600

Seen: 44 times

Last updated: Feb 23