Ask Your Question
0

Print a msg from a Turtlebot3 subscriber

asked 2019-08-20 14:41:13 -0500

Tima1995 gravatar image

updated 2019-08-20 14:44:29 -0500

Hey,

I am just trying to print a msg that is subscribed from the cmd_vel_rc100 message. Here is some of the code:

def moving(self):
        self.pub_cmd_vel = rospy.Publisher('cmd_vel', Twist, queue_size=5)
        while self.finish:
            vel_cmd = Twist()
            vel_cmd_received = Twist()
            vel_cmd.linear.x = 0
            self.pub_cmd_vel.publish(vel_cmd)
            vel_cmd_received = rospy.Subscriber('cmd_vel_rc100', Twist, queue_size=5)
            print vel_cmd_received
            self.finish = False

When I run the node, I see the following in the terminal for the cmd_vel_rc100:

<rospy.topics.Subscriber object at 0x7fd7a0436d50>

Normally, the node must be of type Twist(). My question is now, why don´t I see the normal Twist message?

Thanks for your help!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-08-20 17:24:29 -0500

You need to use a different method to receive just a single message without a callback as you're trying to in your code. The rospy.wait_for_message() will do what you expect, blocking execution until a message is received and returning that message.

A rospy.Subscriber object is used when you want to register a callback function to receive messages whenever the arrive on a topic. You normally create it once when your node is created and destroy it when it closes. This is described in the tutorial here.

Hope this helps.

edit flag offensive delete link more

Comments

Worked well, thanks :)

Tima1995 gravatar imageTima1995 ( 2019-08-21 01:10:34 -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

1 follower

Stats

Asked: 2019-08-20 14:41:13 -0500

Seen: 19 times

Last updated: Aug 20