I'm currently working with MAVLink in Python (pymavlink) to control multiple drones. So far I am able to connect to the drones and communicate, change modes, etc. What I'm doing is essentially instantiating multiple objects from the class with a connection, etc -- so the basic stuff.--I'm working on creating a simple GUI (using web-based Flask, not TkInter) and need to devise a way to simultaneously update certain messages (GPS, mode, etc,) while at the same type being able to send commands, for each drone. Now I'm fairly new to Python but so far I've figured out that I'm going to need to use threads.The problem I've found is that listening to the MAVLink messages is blocking. I can read them continuously, for example, using this function from the pymavlink example:
But as you can see it's running in a while loop so it just stays there. What I want is to be able to get these messages asynchronously outside of a while loop so that I can then send messages.So if my drone class is something like this (this is just a sample -- not the actual thing):class Drone():
def __init__(self, port):
self.mav = mavutil.mavlink_connection(device=port, baud=57600)
self.lat = None
self.lon = None
self.alt = None
def getMessages(self):
self.lat = something
self.lon = something2
self.alt = something3
def update(self):
updateMode()I want my variables (lat, lon, alt) to be kept up to date so that they can refresh in the GUI and at the same type be able to call any update functions to send messages.I know I probably need to use the observer pattern but I need a bit of help implementing that in Python with MAVLink.Thanks!
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "MAVLink" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an mavlink+u...@googlegroups.com.
Weitere Optionen finden Sie unter https://groups.google.com/d/optout.