mavlink / mavros

MAVLink to ROS gateway with proxy for Ground Control Station
Other
902 stars 993 forks source link

Problem with mavros state message #1801

Closed huytd-pi closed 2 years ago

huytd-pi commented 2 years ago

This is only bug and feature tracker, please use it to report bugs or request features.


Issue details

I do a state theme subscription and have the following code:

import mavros_msgs.msg
class NavigationController():

    def __init__(self):
        .............
        state_sub = rospy.Subscriber(mavros.get_topic('state'), State, self._state_callback)
        self.UAV_state = mavros_msgs.msg.State()
        ...............
    def _state_callback(self, topic):
        self.UAV_state.armed = topic.armed
        self.UAV_state.connected = topic.connected
        self.UAV_state.mode = topic.mode
        self.UAV_state.guided = topic.guided

and error message AttributeError: 'NavigationController' object has no attribute 'UAV_state'

I run on gazebo emulator no error, but when embedding running on raspi hardware with ros is noetic and px4 mini with firmware v1.12.3 appear this error

MAVROS version and platform

Mavros: 2.1.0 ROS: noetic Ubuntu: 20.04

Autopilot type and version

[ ] ArduPilot [ x ] PX4

Version: v1.12.3

Node logs

[ERROR] [1668334533.161187]: bad callback: <bound method NavigationController._state_callback of <__main__.NavigationController object at 0xb674d650>>
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/home/dronepi/huytd/drone_tracking/src/drone_real_environment/scripts/NavigationServers.py", line 80, in _state_callback
    self.UAV_state.armed = topic.armed
AttributeError: 'NavigationController' object has no attribute 'UAV_state'
vooon commented 2 years ago

Try to make initialisation before subscription.

huytd-pi commented 2 years ago

Try to make initialisation before subscription.

thanks, this solution helped me