def fly(self): print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | ( GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> ( TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait") ) ) ).wait() self.drone(MaxTilt(40)).wait().success() for i in range(3): print("Moving by ({}/3)...".format(i + 1)) self.drone(moveBy(0.1, 0, 0, math.pi, _timeout=20)).wait().success() print("Landing...") self.drone( Landing() >> FlyingStateChanged(state="landed", _timeout=5) ).wait() print("Landed\n")
def takeOff(self, client): print("Taking off") if (self.drone.get_state(FlyingStateChanged)['state'] == FlyingStateChanged_State.landed): self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged( fixed=1, _timeout=self.timeout, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged(state="hovering", _timeout=self.timeout, _policy="check_wait")))).wait() messageToSend = { "op": "takeOff", "userId": client.userId, "response": 1 } self.flying = True else: messageToSend = { "op": "takeOff", "userId": client.userId, "response": 0 } client.send((json.dumps(messageToSend) + "\n"))
def start(self): # Connect the the drone self.drone.connection() print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait")))).wait( ) self.drone( moveBy(0, -1.15, -0.5, -3.142) >> FlyingStateChanged( state="hovering", _timeout=10)).wait() self.drone( moveBy(2.0, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=10)).wait() # Setup your callback functions to do some live video processing self.drone.set_streaming_callbacks(raw_cb=self.yuv_frame_cb) # Start video streaming self.drone.start_video_streaming()
def fly(self): # Takeoff, fly, land, ... print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait")))).wait( ) df = pd.read_csv('route.csv') #self.drone(moveBy(4, 2, 0, 0)>> FlyingStateChanged(state="hovering", _timeout=5)).wait() while (True): for i in range(len(df)): print('-----------------------------------', (df.X[i] / 4) - 10.125, (df.Y[i] / 4) - 10.125, '------------------------------------------') self.positive_control((df.X[i] / 4) - 10.125, (df.Y[i] / 4) - 10.125) self.drone( PCMD(1, 0, 0, 0, 0, timestampAndSeqNum=0, _timeout=10)) #self.positive_control(-7.2,-7.2) #self.drone(PCMD(1, 0, 0, 0, 0, timestampAndSeqNum=0, _timeout=10)) self.drone(Landing()) self.drone.disconnection()
def start(self): self.drone.connection() self.drone.start_piloting() print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait")))).wait( ) self.drone( moveBy(0, -1.15, -0.5, -3.142) >> FlyingStateChanged( state="hovering", _timeout=10)).wait() self.drone( moveBy(3.0, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=10)).wait() # You can record the video stream from the drone if you plan to do some # post processing. # Here, we don't record the (huge) raw YUV video stream # raw_data_file=os.path.join(self.tempd,'raw_data.bin'), # raw_meta_file=os.path.join(self.tempd,'raw_metadata.json'), # Setup your callback functions to do some live video processing self.drone.set_streaming_callbacks(raw_cb=self.yuv_frame_cb, ) # Start video streaming self.drone.start_video_streaming() while True: cv2.waitKey(1)
def CommonTakeOff(self): if not self._on_test: if (self._drone.get_state(FlyingStateChanged)["state"] is not FlyingStateChanged_State.hovering): self._drone(GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait")).wait() self._drone( TakeOff(_no_expect=True) & FlyingStateChanged(state="hovering", _policy="wait", _timeout=5) ).wait() else : self.my_log.info("Mode simulation: informations reçues")
def takeOff(drone): drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait")))).wait()
def _takeoff(self): """""" print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=5, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=5, _policy="check_wait"))) ).wait()
def test_takeoff_if_necessary_1(): with olympe.Drone(DRONE_IP) as drone: drone.connect() print("Takeoff if necessary...") if (drone.get_state(FlyingStateChanged)["state"] is not FlyingStateChanged_State.hovering): drone( GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait")).wait() drone( TakeOff(_no_expect=True) & FlyingStateChanged( state="takingoff", _policy="wait", _timeout=5)).wait() drone.disconnect()
def test_takeoff_if_necessary_2(): with olympe.Drone(DRONE_IP) as drone: drone.connect() print("Takeoff if necessary...") drone( FlyingStateChanged(state="hovering", _policy="check") | ( GPSFixStateChanged(fixed=1, _timeout=10) >> ( TakeOff(_no_expect=True) & FlyingStateChanged(state="takingoff", _policy="wait", _timeout=5) ) ) ).wait() drone.disconnect()
def fly(self): # Takeoff, fly, land, ... print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | ( GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> ( TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait") ) ) ).wait() self.drone(MaxTilt(40)).wait().success()
def fly(self): # Takeoff, fly, land, ... print("Takeoff if necessary...") self.drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | ( GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> ( TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait") ) ) ).wait() self.drone(moveBy(0,-1.15,-0.5,-3.142)>> FlyingStateChanged(state="hovering",_timeout=10)).wait()
import math import olympe from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing, moveTo, Circle, PCMD from olympe.messages.ardrone3.PilotingState import moveToChanged, FlyingStateChanged, PositionChanged, AttitudeChanged from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged from olympe.messages.ardrone3.PilotingState import GpsLocationChanged from olympe.enums.ardrone3.Piloting import MoveTo_Orientation_mode drone = olympe.Drone("10.202.0.1") drone.connection() # Take-off drone( FlyingStateChanged(state="hovering", _policy="check") | FlyingStateChanged(state="flying", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=10, _policy="check_wait") >> (TakeOff(_no_expect=True) & FlyingStateChanged( state="hovering", _timeout=10, _policy="check_wait")))).wait() # Get the home position drone_location = drone.get_state(GpsLocationChanged) # Move 10m drone( moveBy(10, 0, 0, math.pi) >> PCMD(1, 0, 0, 0, 0, 0) >> FlyingStateChanged( state="hovering", _timeout=5)).wait().success() # Go back home drone( moveTo(drone_location["latitude"], drone_location["longitude"],
import logging import olympe from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing, NavigateHome, moveTo from olympe.messages.ardrone3.PilotingState import FlyingStateChanged, NavigateHomeStateChanged, moveToChanged from olympe.enums.ardrone3.Piloting import MoveTo_Orientation_mode from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged, HomeChanged # olympe.log.set_config(logging.basicConfig(level=logging.DEBUG)) with olympe.Drone("10.202.0.1") as drone: drone.connect() print("\n\n\n ----- Starting experience ----- \n\n\n") drone(GPSFixStateChanged(fixed=1, _timeout=10, _policy='check_wait')).wait() drone_home = drone.get_state(HomeChanged) print(drone_home) drone( TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() print("\n\n\n -----TakeOff complete----- \n\n\n") N_STEPS = 2 #number of steps before back to base STEP = 2 #Distance (in m) of one step forward for i in range(N_STEPS): drone(
if not os.path.exists(path_CR2): os.makedirs(path_CR2) print(paths_CR1) print(paths_CR2) print("\n\n\n ----- Starting experience ----- \n\n\n") # 192.168.42.1 to connect to the real drone # 10.202.0.1 to connect to virtual Ethernet interface (Sphinx) with olympe.Drone("192.168.42.1") as drone: drone.connect() # Save the "home" position to be able to get back to it later # drone(GPSFixStateChanged(fixed=1, _timeout=10, _policy='check_wait')).wait() drone(GPSFixStateChanged(_policy="wait")) drone_home = drone.get_state(HomeChanged) print(drone_home) drone( TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() print("\n\n\n -----TakeOff complete----- \n\n\n") saver = threading.Thread(target=save_packets, args=(30, paths_CR1[0], CR1, paths_CR2[0], CR2)) saver.start() saver.join() for STEP in range(1, N_STEPS):
from __future__ import print_function # python2/3 compatibility for the print function 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.PilotingState import FlyingStateChanged from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing, NavigateHome, moveTo # Connection drone = olympe.Drone("10.202.0.1") drone.connection() # Wait for GPS fix drone(GPSFixStateChanged(_policy='wait')) print( "*******************************************************************************************************" ) print("GPS position before take-off :", drone.get_state(HomeChanged)) print( "*******************************************************************************************************" ) # Take-off drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)).wait() #Go to entrance drone( moveBy(-6.5, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() drone(
class FlightListener(olympe.EventListener): def set_logger(self, logger): self.my_log = logger; def set_socket(self, websocket): self._brain_client = websocket; def set_relay(self, relay): self._relay = relay def set_drone_coordinates(self, coordinates): self._drone_coordinates = coordinates def set_initialized_socket(self, initialized): self._socket_initialized = initialized; def set_my_name(self, name): self.my_name = name; def on_signal_lost (self, func): self._on_signal_lost = func; @olympe.listen_event(NavigateHomeStateChanged()) def on_navigation_changed(self, event, scheduler): global navigate_home_status_lookup try : if hasattr(self, "my_log"): self.my_log.info("{} = {}".format(event.message.name, event.args["state"])) self.emit_status("navigate_home_status_changed", navigate_home_status_lookup.index(event.args["state"])) except(Exception) as err : if hasattr(self, "my_log"): self.my_log.info(err) @olympe.listen_event(FlyingStateChanged()) def on_state_changed(self, event, scheduler): global flying_status_lookup try : if hasattr(self, "my_log"): self.my_log.info("{} = {}".format(event.message.name, event.args["state"])) self.emit_status("flight_status_changed", flying_status_lookup.index(event.args["state"])) except(Exception) as err : if hasattr(self, "my_log"): self.my_log.info(err) @olympe.listen_event(AlertStateChanged() ) def on_alert_raised(self, event, scheduler): global alert_lookup try : if hasattr(self, "my_log"): self.my_log.info("{} = {}".format(event.message.name, event.args["state"])) self.emit_status("on_alert_changed", alert_lookup.index(event.args["state"])) except(Exception) as err : if hasattr(self, "my_log"): self.my_log.info(err) @olympe.listen_event(PositionChanged() | moveToChanged()) def on_position_changed(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info( "latitude = {} longitude = {} altitude = {}".format( event.args["latitude"], event.args["longitude"], event.args["altitude"] ) ) if hasattr(self, "_drone_coordinates"): self._drone_coordinates.update_position(event.args["latitude"], event.args["longitude"], event.args["altitude"]) self.on_element_position_update('position_update', event) @olympe.listen_event(HomeChanged()) def on_home_changed(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info( "latitude = {} longitude = {} altitude = {}".format( event.args["latitude"], event.args["longitude"], event.args["altitude"] ) ) if hasattr(self, "_relay"): self._relay.update_position(event.args["latitude"], event.args["longitude"], event.args["altitude"]) self.on_element_position_update('home_position_update', event) """ @olympe.listen_event( FlyingStateChanged(state="motor_ramping") >> FlyingStateChanged(state="takingoff", _timeout=1.) >> FlyingStateChanged(state="hovering", _timeout=5.) ) def on_take_off(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info("Décollage du drone") #event.message.name self.emit_status("takeoff", event.args["success"]) """ @olympe.listen_event(rssi_changed()) def on_signal_changed(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info(event.args) self.on_internal_status_changed(event.message.name, event.args["rssi"]) if hasattr(self, "_on_signal_lost") and event.args["rssi"] <= -120: self._on_signal_lost() @olympe.listen_event(NumberOfSatelliteChanged()) def on_satellite_changed(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info(event); self.on_internal_status_changed(event.message.name, event.args["numberOfSatellite"]) @olympe.listen_event(BatteryStateChanged()) def on_battery_update(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info(event); self.on_internal_status_changed(event.message.name, event.args["percent"]) @olympe.listen_event(GPSFixStateChanged()) def on_gps_changed(self, event, scheduler): if hasattr(self, "my_log"): self.my_log.info(event); self.on_internal_status_changed(event.message.name, event.args["fixed"]) def on_internal_status_changed(self, name, value): try : if hasattr(self, "_socket_initialized") and hasattr(self, "my_name") and hasattr(self,"_brain_client") and self._socket_initialized: self._brain_client.emit('internal_status_changed', {"id":self.my_name, "status":name, "result":value}) except(Exception) as error : if hasattr(self, "my_log"): self.my_log.error("Une erreur est survenue lors de la mise à jour des états interne") self.my_log.error(error) self.my_log.error("{} = {}".format(value.message.name, value.args)) def on_element_position_update(self, event, value): try : if hasattr(self, "_socket_initialized") and hasattr(self, "my_name") and hasattr(self,"_brain_client") and self._socket_initialized: self._brain_client.emit(event, {"id":self.my_name,"latitude": value.args["latitude"], "longitude": value.args["longitude"], "altitude": value.args["altitude"] }) except(Exception) as error : if hasattr(self, "my_log"): self.my_log.error("Une erreur est survenue lors de la mise à jour des positions") self.my_log.error(error) self.my_log.error("{} = {}".format(value.message.name, value.args)) def emit_status(self, name, value): try : if hasattr(self, "_socket_initialized") and hasattr(self, "my_name") and hasattr(self,"_brain_client") and self._socket_initialized: self._brain_client.emit(name, {"drone_name":self.my_name, "status":value}) except(Exception) as error : if hasattr(self, "my_log"): self.my_log.error("Une erreur est survenue lors de la mise à jour des états interne") self.my_log.error(error) self.my_log.error("{} = {}".format(value.message.name, value.args))
# -*- coding: UTF-8 -*- import olympe from olympe.messages.ardrone3.Piloting import TakeOff from olympe.messages.ardrone3.PilotingState import FlyingStateChanged from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged with olympe.Drone("10.202.0.1") as drone: drone.connect() print("Takeoff if necessary...") drone( FlyingStateChanged(state="hovering", _policy="check") | (GPSFixStateChanged(fixed=1, _timeout=10) >> (TakeOff(_no_expect=True) & FlyingStateChanged(state="hovering", _policy="wait", _timeout=5)) )).wait()
def position(drone): drone(GPSFixStateChanged(_policy = 'wait')) return drone.get_state(HomeChanged)