Create a new topic

asked 2018-11-06 15:26:07 -0500

Dylan gravatar image

updated 2018-11-06 15:58:46 -0500

I'm reading some distances and I want to use them to make a controller, so I read that the best way is to create a new topic, publish there the distances and subscribe to that topic with another node. I'm using Python.

How can I create a new topic? I mean, I have a lot of topics but I need one more

Edit: the topic would receive 7 positions/orientations from a marker: marker.pose.pose.position.x, marker.pose.pose.position.y, marker.pose.pose.position.z, marker.pose.pose.orientation.x, marker.pose.pose.orientation.y, marker.pose.pose.orientation.z, marker.pose.pose.orientation.w

edit retag flag offensive close merge delete



I hate to say it. But if you work through the python publisher tutorial it shows you exactly how to do this.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-06 18:02:24 -0500 )edit

No, it doesnt say how to create a new TOPIC. I invented a possible solution but its not optimal

Dylan gravatar image Dylan  ( 2018-11-06 19:13:56 -0500 )edit

@PeteBlackerThe3rd is right, as soon as you create a publisher on a topic even if there are no nodes subscribed to it, it is created, hence it's a new topic.

Delb gravatar image Delb  ( 2018-11-07 01:06:21 -0500 )edit

According to your edit you just need to publish a geometry_msgs/Pose. Why does this solution isn't what you want ?

from geometry_msgs.msg import Pose
message pub = rospy.Publisher('chatter', Pose, queue_size=10)
Delb gravatar image Delb  ( 2018-11-07 01:10:17 -0500 )edit

To be clear you don't actively create and destroy topics. Simply publishing or subscribing to that topic name brings it into existence.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-07 03:00:54 -0500 )edit