A node is a process that performs some form of logic as part of your full robot control system, a topic is an interface through which multiple nodes can communicate. A node can publish and subscribe to any number of topics, and any number of nodes can publish and subscribe to a single topic (though it's more common that only a single node is responsible for publishing on a topic).
This also implies that a topic can exist separately from any node that contains a publisher for it. If there is an active subscription to the topic but nobody is publishing on it, then the topic will also still show up in ros2 topic list
. For instance if you run ros2 topic echo foo std_msgs/msg/Bool
, then in another terminal run ros2 topic list
, then you will see the /foo
topic even though nobody has ever published anything on it! The output of ros2 topic info /foo
will show that, telling you that there is 1 subscription but 0 publishers:
$ ros2 topic info /foo
Type: std_msgs/msg/Bool
Publisher count: 0
Subscription count: 1
Adding the -v
flag will give more output about the possible publishers or subscriptions:
$ ros2 topic info /foo -v
Type: std_msgs/msg/Bool
Publisher count: 0
Subscription count: 1
Node name: _ros2cli_340
Node namespace: /
Topic type: std_msgs/msg/Bool
Endpoint type: SUBSCRIPTION
GID: 01.0f.3e.26.54.01.00.00.01.00.00.00.00.00.05.04.00.00.00.00.00.00.00.00
QoS profile:
Reliability: RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT
Durability: RMW_QOS_POLICY_DURABILITY_VOLATILE
Lifespan: 2147483651294967295 nanoseconds
Deadline: 2147483651294967295 nanoseconds
Liveliness: RMW_QOS_POLICY_LIVELINESS_AUTOMATIC
Liveliness lease duration: 2147483651294967295 nanoseconds
So this says that the subscription comes the node _ros2cli_340
, which is the name picked by the ros2 echo
command.
This situation also could happen if you run RQT or Rviz to monitor or visualize a topic, then kill the publishing node: they keep their subscription and the topic still exists.
Another situation I have seen in the past is if the publisher is run on another machine (your robot) and you run ros2 topic list
on another machine connected to the same network (your laptop), then when you kill the publisher it may take a while for your machine to notice that the topic is gone, even without any subscription to it.
So all that is to say that if you see a topic, it doesn't necessarily mean you have a zombie process publishing to it. To figure out what is happening I would:
- run
ros2 topic info /topic -v
to see if there is either a publisher or a subscription and what their name is, which could help determining where to look for it. - maybe run
ros2 node list -a
to help further to understand all the nodes that are running - Finally if that doesn't give anything or your not able to find where they are running (which shouldn't happen easily if you just use
ros2 run
and ctl+c in terminals to ...
(more)
You may be confusing the concepts of 'node' and 'topic'. Could you show what you do to see that '/scan is still running'? Are you using
ros2 topic list
maybe? Or do you see it in RQT or Rviz? What do you get when you runros2 topic info /range
? And how did you start the node that publishes on/scan
, usingros2 run
, orros2 launch
perhaps?Hi, Sorry for the delay reply!
I thought the topic is the name of something to run and sends/receives information which is considered as a node?
I used ros2 topic list and I see it running as /scan. The /scan comes from the file where I had the publisher to pretend like as if it's "/scan". I checked and there is no one running it.
I ran the
ros2 run publisher test
.After 5 hours later, it's gone. I'm not sure now.
I will definitely check the ros2 topic info /scan when it happens again. I don't know how to get it doing the same thing again, to be honest.
There is one thing I know for sure is that restart pc would fix this issue lol