ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The problem you are running into is you are calling the minimal_subscriber.printmsg()
function which sits in an infinite loop and you haven't started spinning the node to let the callbacks start receiving messages.
What you are trying to do is probably better done with a rclpy Timer. Here is a python example of one being used. Just pass your desired frequency to the timer constructor (which seems to be 2 for you, since you sleep for half a second), remove the while loop inside your printmsg
function, and remove the call in the main function.
Spin should block so your program won't exit, and it should print the value of self.topub
every half second.