[ROS2][rclpy][Publisher] publish a msg to an existing topic [closed]

asked 2020-01-16 02:23:58 -0500

lin404 gravatar image

updated 2020-01-16 17:54:21 -0500

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?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by lin404
close date 2020-01-27 19:08:15.575704

Comments

What would you consider the semantic difference between create_publisher(...) and get_publisher(...) that you are asking about? And can you also edit your question to clarify what you mean by "get the target topic" and "call an existing topic"?

tfoote gravatar image tfoote  ( 2020-01-16 19:14:37 -0500 )edit

@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 give create_publisher a different name for example cmd_vel_1, it will create a new topic called cmd_vel_1 then do publish() without any problem? Or it will return an error saying there is no cmd_vel_1? --> That's my concern about the difference between create_publisher and get_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.

lin404 gravatar image lin404  ( 2020-01-19 20:10:56 -0500 )edit