Ask Your Question
0

subcribing to 2 topics and publishing selected data in same node

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

roboter gravatar image

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

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
0

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

Look into message filters (http://wiki.ros.org/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

Comments

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
    rospy.spin()



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
    rospy.sleep(0.1)

if __name__ == '__main__':
    try:
        listener()

    except rospy.ROSInterruptException:
        pass
roboter gravatar imageroboter ( 2019-10-12 08:31:55 -0500 )edit

Please read the documentation for the package.

stevemacenski gravatar imagestevemacenski ( 2019-10-14 11:18:12 -0500 )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

2 followers

Stats

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

Seen: 45 times

Last updated: Oct 11