Attention: Answers.ros.org is deprecated as of August the 11th, 2023. Please visit robotics.stackexchange.com to ask a new question. This site will remain online in read-only mode during the transition and into the foreseeable future. Selected questions and answers have been migrated, and redirects have been put in place to direct users to the corresponding questions on Robotics Stack Exchange. Additional details are available here.
The site is read-only. Please transition to use Robotics Stack Exchange
0
Hello, I am new to ros and want to know how access the subscription data in another function using rclpy. I keep geeting the error: AttributeError: 'Pose_sub' object has no attribute 'pose'
It's essentially impossible that the subscription set up will be done and a message processed by your callback between the subscription creation time and the time you are calling "self.get_pose()".
What are you trying to accomplish with the pose? Most of the time I see folks use a timer with its own callback for some sort of processing code that runs regularly, using the latest stored sensor data from class state.
That timer callback would initially also have the same error (fyi you probably want to initialize self.pose = None in the constructor and check if self.pose is None in a conditional within other code that depends on pose to avoid exceptions being thrown). You can have your timer callback return early doing nothing until all required data is present.