I’m currently using this code
import olympe
from olympe.messages.ardrone3.Piloting import TakeOff, Landing, moveBy
from olympe.messages.ardrone3.PilotingState import (
PositionChanged,
AlertStateChanged,
FlyingStateChanged,
NavigateHomeStateChanged,
)
class FlightListener(olympe.EventListener):
@olympe.listen_event(FlyingStateChanged() | AlertStateChanged() |
NavigateHomeStateChanged())
def onStateChanged(self, event, scheduler):
print("HELLO WORLDS")
print("{} = {}".format(event.message.name, event.args["state"]))
@olympe.listen_event(FlyingStateChanged() | NavigateHomeStateChanged() | PositionChanged())
def onPositionChanged(self, event, scheduler):
position_data = {
"latitude": event.args["latitude"],
"longitude": event.args["longitude"],
}
print("HELLO WORLD")
print("GPS position:", json.dumps(position_data, indent=2))
drone = olympe.Drone("10.202.0.1")
with FlightListener(drone):
drone.connect()
drone(
FlyingStateChanged(state="hovering")
| (TakeOff() & FlyingStateChanged(state="hovering"))
).wait()
drone(moveBy(1, 0, 0, 0)).wait()
drone(Landing()).wait()
drone(FlyingStateChanged(state="landed")).wait()
drone.disconnect()
but it says that the key for event.args is wrong, and doesn’t print the GPS coordinates.