[ROS2][rclpy][Publisher] publish a msg to an existing topic [closed]
I know I can do below to publish msgs to a publisher.
pub = node.create_publisher(msg_type, topic)
pub.publish(some data)
My question is: Do I have to create_publisher
first to get the target topic
? There is no way to call an existing topic
, something like get_publisher()
? Or create_publisher
is just kind of calling a topic
when it is already existing?
What would you consider the semantic difference between
create_publisher(...)
andget_publisher(...)
that you are asking about? And can you also edit your question to clarify what you mean by "get the targettopic
" and "call an existingtopic
"?@tfoote Sorry for the confusion. The existing system already has a topic named
cmd_vel
which I want to use. While, I was just wondering if I givecreate_publisher
a different name for examplecmd_vel_1
, it will create a new topic calledcmd_vel_1
then dopublish()
without any problem? Or it will return an error saying there is nocmd_vel_1
? --> That's my concern about the difference betweencreate_publisher
andget_publisher
, since I might not want to create a new topic, instead I prefer it can return the error telling me I am trying to use an inexistent topic.