Bonjour à tous,
Je travaille actuellement avec le SDK 7.7.4 de Parrot pour un projet utilisant un drone, mais je rencontre des difficultés pour obtenir le nombre de satellites détectés par le drone. Mon code actuel ne semble pas fonctionner comme prévu.
Je ne reçois pas les données attendues et je me demande s’il y a des modifications récentes dans le SDK qui pourraient affecter cette fonctionnalité ou si je fais quelque chose de mal dans mon implémentation. Quelqu’un pourrait-il m’orienter ou me montrer un exemple fonctionnel pour obtenir correctement le nombre de satellites ?
Voici un extrait de mon 1er code:
import olympe
from olympe.messages.ardrone3.PilotingState import PositionChanged
from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged
from olympe.messages.ardrone3.Piloting import TakeOff
from olympe.messages.ardrone3.GPSSettingsState import HomeChanged
from olympe.messages.ardrone3.GPSState import NumberOfSatelliteChanged
import time
import threading
# Replace with the IP address of your SkyController
SKYCONTROLLER_IP = "192.168.53.1"
class SatelliteCounter:
def __init__(self):
self.num_satellites = None
self.lock = threading.Event()
def number_of_satellites_callback(self, event, scheduler):
self.num_satellites = event.args["numberOfSatellite"]
self.lock.set()
def get_number_of_satellites(drone):
satellite_counter = SatelliteCounter()
# Subscribe to the NumberOfSatelliteChanged event
drone.subscribe(NumberOfSatelliteChanged(), satellite_counter.number_of_satellites_callback)
# Wait for the event to be triggered
if satellite_counter.lock.wait(10): # Wait for up to 10 seconds
return satellite_counter.num_satellites
else:
print("Timeout waiting for satellite information")
return None
def main():
# Create a Drone object connected via the SkyController
drone = olympe.Drone(SKYCONTROLLER_IP)
# Connect to the drone
if drone.connect():
print("Successfully connected to the drone")
# Keep the drone in the air for 10 seconds
time.sleep(5)
drone(NumberOfSatelliteChanged(_policy='check_wait'))
time.sleep(5)
# Wait for GPS fix
# Get the number of satellites
msg = str(drone.get_state(NumberOfSatelliteChanged))
print("GPS number of satellites changed: ", msg)
time.sleep(30)
print("Will disconnected now")
# Disconnect from the drone
drone.disconnect()
else:
print("Failed to connect to the drone")
if __name__ == "__main__":
main()
Voici un extrait de mon second code:
import olympe
import os
from olympe.messages.ardrone3.Piloting import TakeOff, Landing, moveBy
from olympe.messages.ardrone3.GPSState import NumberOfSatelliteChanged
from olympe.messages.ardrone3.PilotingState import FlyingStateChanged
import time
olympe.log.update_config({"loggers": {"olympe": {"level": "WARNING"}}})
DRONE_IP = "192.168.53.1"
def test_subscriber():
drone = olympe.Drone(DRONE_IP, media_autoconnect=False)
# subscribe to all events during the drone connection
with drone.subscribe(
lambda event, controller: print(f"{event}")
):
drone.connect()
# Subscribe to NumberOfSatelliteChanged
# If you call `drone.subscribe` without using the `with` statement,
# you'll have to call `drone.unsubscribe()` later.
satellite_sub = drone.subscribe(
lambda event, controller: print("Numberofsatellite =", event.args["state"]),
NumberOfSatelliteChanged(numberOfSatellite=None, _policy="wait"),
)
flying_sub = drone.subscribe(
lambda event, controller: print("Flyingstate =", event.args["state"]),
FlyingStateChanged(_policy="check"),
)
assert (
drone(
FlyingStateChanged(state="hovering")
| (TakeOff() & FlyingStateChanged(state="hovering"))
)
.wait(5)
.success()
)
assert drone(moveBy(10, 0, 0, 0)).wait().success()
drone(Landing()).wait()
assert drone(FlyingStateChanged(state="landed")).wait().success()
# unsubscribe from NumberOfSatelliteChanged
drone.unsubscribe(satellite_sub)
# unsubscribe from FlyingStateChanged
drone.unsubscribe(flying_sub)
drone.disconnect()
if __name__ == "__main__":
test_subscriber()
Merci beaucoup pour votre aide !