Skip to content

How to get mavlink system messages on my program? #1165

@ghost

Description

Hello, I want to make great and simple drone delivery GCS for my drone delivery apparatus(it is just for hobby yet.)

I found mavlink critical message is printed on pycharm console like below :

"CRITICAL:autopilot:PreArm: Fence enabled, need position estimate"
(I don't know how to add a picture so I copied the message here.)

I want this message to printed in my PYQT5 text label.

I dig in the web and only found this way :
https://dronekit-python.readthedocs.io/en/latest/guide/mavlink_messages.html

in above link, I guess this code is only solution :

@vehicle.on_message('*')
def listener(self, name, message):
    print 'message: %s' % message

but when I try this code in my class it does not work.

global mw

class DroneWorker(QThread):
    def __init__(self, _mw):
        super().__init__()
        global mw
        self.mw = _mw
        self.connection_string = "COM9"
        self.vehicle = connect(self.connection_string, baud=57600, wait_ready=True)
        print(" Connected, Autopilot Firmware version: %s" % self.vehicle.version) 
        self.alive = True

   @vehicle.on_message('*')
   def listener(self, name, message):
       print 'message: %s' % message

    def run(self):
        while self.alive:
            self.mw.drone_heading.setText(str(self.vehicle.heading))
            self.mw.num_sat.setText(str(self.vehicle.gps_0.satellites_visible))
            self.mw.batt_voltage.setText(str(self.vehicle.battery.voltage))
            self.mw.flight_mode.setText(str(self.vehicle.mode))
            self.mw.mavlink_message.setText(str(self.vehicle.system_status))

I added "self" in front of vehicle, like this :

@self.vehicle.on_message('*')
def listener(self, name, message):
       print 'message: %s' % message

it also didn't work.

I also tried to make "vehicle" to "global" variables but it also failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions