Adding to what @simon.steinmann91 already said:
-
Actually, it’s not mandatory to use
rospy.spin(), for ROS Python subscribers (it’s mandatory for C++). It can be replaced by the kind of while loop in the code above (just to keep the main program from exiting). See this post for further clarifications: -
rospy.on_shutdown()is not meant to be called the way you think. It’s a “configuration” statement that tells ROS the function to be called when it’s shutting down. In other words, when we writerospy.on_shutdown(shutdownhook), we are saying “Hey ROS, whenever you are shutting down please call the shutdownhook() function!” -
The line
self._odomdata = Odometry()initializesself._odomdatawith an empty odometry message while the lineself._odomdata = msgactually assigns it a real odometry message from the subscriber.