Ask Your Question

subcribing to 2 topics and publishing selected data in same node

asked 2019-10-11 11:32:34 -0600

roboter gravatar image

updated 2019-10-11 11:33:03 -0600

hello everyone. i have two messages publishing on their message with their topic name. now i want to subscribe these two topics and publish a new topic which will take some selected data from one topic and selected data from other, then publish the new message. i can subscribe to a topics, assign some new values and publish the new message but i am unable to do the above problem.

  1. Is it possible?

  2. if yes, then let's take geometry_msgs. Topic1 gives Point and Topic2 gives Point and Twist. how can i create a new geometry_msg that subscribe to both and produce a new message such that Point is from topic1 and Twist is from topic2.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-11 20:40:22 -0600

Look into message filters ( you can create a subscriber that has its callback triggered when you have information from the 2 topics available.

In the callback you can combine that information and publish to your new topic

edit flag offensive delete link more


things are little unclear for me. Can you look t the code and show me ho to do this???

def listener():
    rospy.init_node('move_turtlebot', anonymous=True)  #node
    rospy.Subscriber("/Topic1", Pose, move_turtlebot)  #subcribin to topic1
    rospy.Subscriber("/Topic2", Pose, move_turtlebot)  #subscribing to topic2

def move_turtlebot(data):
    pub = rospy.Publisher('Topic3', Pose, queue_size=10)                       
    move_turtlebot= Pose()    #msg type pose
    Pose.position= Topic1.Pose.postion       #take position from topic 1
    Pose.Orientation= Topic2.Pose.orientation    #take orientation from topic2

    pub.publish(data)                             #publish the msg

if __name__ == '__main__':

    except rospy.ROSInterruptException:
roboter gravatar image roboter  ( 2019-10-12 08:31:55 -0600 )edit

Please read the documentation for the package.

stevemacenski gravatar image stevemacenski  ( 2019-10-14 11:18:12 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-10-11 11:32:34 -0600

Seen: 418 times

Last updated: Oct 11 '19