ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Print a msg from a Turtlebot3 subscriber

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

Tima1995 gravatar image

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

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 -0600

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 image Tima1995  ( 2019-08-21 01:10:34 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 534 times

Last updated: Aug 20 '19