Topic not being published

Hello dear community !

I joined here just recently. I searched for topics similar to mine but it didn’t solve my issue.
In the ROS Basics (5 days) course, in example 3.1, I run the following command as told:

rosrun my_examples_pkg

This gives the following output:

/opt/ros/noetic/lib/python3/dist-packages/rospy/ ’ /counter’ is not a legal ROS graph resource name. This may cause problems with other ROS tools
super(Publisher, self).init(name, data_class, Registration.PUB)
[FATAL] [1647509354.474772, 0.000000]: unable to register publication [/ /counter] with master: ERROR: parameter [topic] contains illegal chars

And also, to see if i have created a topic, i run (in second webshell) :

rostopic list | grep ‘/counter’

But output shows blank. As per the tutorial text, output SHOULD BE :

user ~ $ rostopic list | grep ‘/counter’

Where am I doing wrong? contains the following code:

#! /usr/bin/env python

import rospy
from std_msgs.msg import Int32

pub = rospy.Publisher(’ /counter’, Int32, queue_size=1)
rate = rospy.Rate(2)
count = Int32() = 0

while not rospy.is_shutdown():
pub.publish(count) += 1

Hi ,

user ~ $ rostopic list | grep ‘/counter’

It should be without ’ ', that is:

user ~ $ rostopic list | grep /counter

And in future, use image, from the menu to copy code, making it easy to comprehend with colors and all.

Inorder to see the output:

user ~ $ rostopic echo /counter

Let me know if it worked out

Thank you sir for the kind reply.
It didn’t work.


In second webshell, i run the following:

remove the space before /counter, as shown below. Spaces are not allowed when naming.

pub = rospy.Publisher(’/counter’, Int32, queue_size=1)```

Oh thank you so much sir…!!!
I found two errors to rectify it…first as told by you, i removed the space before /counter. Secondly, during compiling the workspace using catkin build, i was getting error that the workspace is already compiled using catkin_make. So i deleted the devel and build folders in catkin_ws and again compiled using catkin build.

it worked!

Hi @arjun2312 ,
Glad it worked out. Also, go through this link about ROS graph resource names Names - ROS Wiki, basically rules to be followed while nameing topics, classes etc in ROS.

This is not part of the ROS curriculum but shouldn’t take more than 15mins to go through it.

All the best.

1 Like