# -*- coding: UTF-8 -*- import olympe from olympe.messages.ardrone3.Piloting import TakeOff drone = olympe.Drone("192.168.42.1") drone.connection() drone(TakeOff()).wait() drone.disconnection()
def __init__(self): if rospy.get_param("/indoor"): rospy.loginfo("We are indoor") else: rospy.loginfo("We are outdoor") self.pub_image = rospy.Publisher("/anafi/image", Image, queue_size=1) self.pub_time = rospy.Publisher("/anafi/time", Time, queue_size=1) self.pub_attitude = rospy.Publisher("/anafi/attitude", QuaternionStamped, queue_size=1) self.pub_location = rospy.Publisher("/anafi/location", PointStamped, queue_size=1) self.pub_height = rospy.Publisher("/anafi/height", Float32, queue_size=1) self.pub_speed = rospy.Publisher("/anafi/speed", Vector3Stamped, queue_size=1) self.pub_air_speed = rospy.Publisher("/anafi/air_speed", Float32, queue_size=1) self.pub_link_goodput = rospy.Publisher("/anafi/link_goodput", UInt16, queue_size=1) self.pub_link_quality = rospy.Publisher("/anafi/link_quality", UInt8, queue_size=1) self.pub_wifi_rssi = rospy.Publisher("/anafi/wifi_rssi", Int8, queue_size=1) self.pub_battery = rospy.Publisher("/anafi/battery", UInt8, queue_size=1) self.pub_state = rospy.Publisher("/anafi/state", String, queue_size=1) self.pub_mode = rospy.Publisher("/anafi/mode", String, queue_size=1) self.pub_pose = rospy.Publisher("/anafi/pose", PoseStamped, queue_size=1) self.pub_odometry = rospy.Publisher("/anafi/odometry", Odometry, queue_size=1) self.pub_rpy = rospy.Publisher("/anafi/rpy", Vector3Stamped, queue_size=1) self.pub_skycontroller = rospy.Publisher("/skycontroller/command", SkyControllerCommand, queue_size=1) rospy.Subscriber("/anafi/takeoff", Empty, self.takeoff_callback) rospy.Subscriber("/anafi/land", Empty, self.land_callback) rospy.Subscriber("/anafi/emergency", Empty, self.emergency_callback) rospy.Subscriber("/anafi/offboard", Bool, self.offboard_callback) rospy.Subscriber("/anafi/cmd_rpyt", PilotingCommand, self.rpyt_callback) rospy.Subscriber("/anafi/cmd_moveto", MoveToCommand, self.moveTo_callback) rospy.Subscriber("/anafi/cmd_moveby", MoveByCommand, self.moveBy_callback) rospy.Subscriber("/anafi/cmd_camera", CameraCommand, self.camera_callback) # Connect to the SkyController if rospy.get_param("/skycontroller"): rospy.loginfo("Connecting through SkyController") self.drone = olympe.Drone(SKYCTRL_IP) # Connect to the Anafi else: rospy.loginfo("Connecting directly to Anafi") self.drone = olympe.Drone(DRONE_IP) # Create listener for RC events self.every_event_listener = EveryEventListener(self) rospy.on_shutdown(self.stop) self.srv = Server(setAnafiConfig, self.reconfigure_callback) self.connect() # To convert OpenCV images to ROS images self.bridge = CvBridge()
import olympe from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing from olympe.messages.ardrone3.PilotingState import FlyingStateChanged # drone = olympe.Drone("10.202.0.1") drone = olympe.Drone("10.202.0.1", logfile=open("/tmp/drone_moveby.log", "a+")) drone.connection() drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)).wait() drone(moveBy(5, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() drone(Landing()).wait() drone.disconnection()
# only print the XMP tags we are interested in if xmp_tag in XMP_TAGS_OF_INTEREST: print(resource.resource_id, xmp_tag, xmp_value) def setup_photo_burst_mode(drone): drone(set_camera_mode(cam_id=0, value="photo")).wait() # For the file_format: jpeg is the only available option # dng is not supported in burst mode drone( set_photo_mode( cam_id=0, mode="burst", format="rectilinear", file_format="jpeg", burst="burst_14_over_1s", bracketing="preset_1ev", capture_interval=0.0, )).wait() def main(drone): drone.connect() setup_photo_burst_mode(drone) take_photo_burst(drone) if __name__ == "__main__": with olympe.Drone(ANAFI_IP) as drone: main(drone)
# -*- coding: UTF-8 -*- import olympe from olympe.messages.ardrone3.Piloting import TakeOff from olympe.messages.ardrone3.PilotingState import FlyingStateChanged from olympe.enums.ardrone3.PilotingState import FlyingStateChanged_State from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged with olympe.Drone("10.202.0.1") 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="hovering", _policy="wait", _timeout=5) ).wait()
def simulate(config): """Runs a simulation given the configuration dictionary""" signal.signal(signal.SIGINT, signal_handler) SPHINX_ROOT = os.getenv("SPHINX_ROOT") ACTOR = SPHINX_ROOT + "/actors/pedestrian.actor::name={}::path={}" GZ_DRONE = SPHINX_ROOT + "/drones/local_anafi4k.drone" MOVE_RNG = 5 # moves the drone in the Z axis by 0.5 or -0.5 teleop, sphinx, data_logger = None, None, None for i in range(config["reps"]): os.system( "pkill telem") # Sometimes the telemetry daemon isnt killed auto. print("\nRun no {}. Initial wait: {}".format(i, config["delay_start"])) config["run_name"] = "run{}".format(i) # ==== PER-RUN SETUP ==== # ======================= # Generate world files (depends on the grid size) print("Generating new world.") tstart = time() world = WorldBuilder(config) objects = world.get_object_models() (world_fpath, subj_fpath, peds_fpath) = world.get_paths() config["final_peds"] = world.get_num_peds() print("{} seconds to generate a world".format(int(time() - tstart))) # nm[-1] gives the pedestrian number; nm ~= P1, P0, .. GZ_SUBJECT = ACTOR.format("subject", subj_fpath) GZ_PEDS = " ".join( [ACTOR.format(nm[-1], txt) for (nm, txt) in peds_fpath]) # ==== TASK DISPATCH ==== # ======================= print("Dispatching background tasks.") sphinx_fname = config["datapath"] + "/sphinx{}.log".format(i) sphinx = BackgroundTask("sphinx --datalog {} {} {} {}".format( world_fpath, GZ_DRONE, GZ_SUBJECT, GZ_PEDS), log=True, log_file=sphinx_fname, wait=8) # Create drone and joystick and randomly vary drone height # around 5s creating both drone = olympe.Drone(JoystickTeleop.SIMULATED_IP, loglevel=0) teleop = JoystickTeleop(drone, config["speed"], config["refresh"]) vary_anafi_height(teleop, config["set_height"], MOVE_RNG) print("Drone taking off!") # about 4s teleop._takeoff() print("Starting to log data :D") # about 4s data_logger = DataLogger(config, objects) data_logger.start() # ==== WAIT UNTIL EXPERT POLICY RECORDING IS FINISHED ==== # ======================================================== # Control the drone :D teleop.start() print("\n\nKilling processes!") sphinx.kill() os.system("pkill gzserver") # print("Halo") data_logger.stop() # saves-closes the .CSV when finished # every once in a while delete ~/.parrot-sphinx logs # these files can get really big if random() > 0.9: _HOME = os.getenv("HOME") shutil.rmtree(_HOME + "/.parrot-sphinx")
# -*- coding: UTF-8 -*- import olympe from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing from olympe.messages.ardrone3.PilotingState import FlyingStateChanged DRONE_IP = "10.202.0.1" if __name__ == "__main__": drone = olympe.Drone(DRONE_IP) drone.connect() assert drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) ).wait().success() assert drone( moveBy(10, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) ).wait().success() assert drone(Landing()).wait().success() drone.disconnect()
shell=True, ) .decode() .strip() ) except subprocess.CalledProcessError: pass else: if keyboard_variant == "azerty": ctrl_keys = AZERTY_CTRL_KEYS return ctrl_keys if __name__ == "__main__": p0 = subprocess.Popen(['sphinx', '/opt/parrot-sphinx/usr/share/sphinx/drones/anafi4k.drone::with_front_cam=1']) with olympe.Drone(DRONE_IP) as drone: time.sleep(3) drone.connection() time.sleep(2) p1 = subprocess.Popen(['../clones/parrot-groundsdk/out/pdraw-linux/staging/native-wrapper.sh', 'pdraw', '-u','rtsp://10.202.0.1/live']) # p1 = subprocess.Popen(['../clones/parrot-groundsdk/out/pdraw-linux/staging/native-wrapper.sh', 'pdraw', '-u','rtsp://192.168.42.1/live']) time.sleep(2) control = KeyboardCtrl() while not control.quit(): if control.takeoff(): drone(TakeOff()) elif control.landing(): drone(Landing()) if control.has_piloting_cmd(): drone( PCMD(
# -*- coding: UTF-8 -*- import olympe from olympe.messages.ardrone3.Piloting import TakeOff, moveTo, Landing from olympe.messages.ardrone3.PilotingState import FlyingStateChanged, moveToChanged from olympe.messages.camera import start_recording, stop_recording from olympe.messages import gimbal from olympe.enums.ardrone3.Piloting import MoveTo_Orientation_mode DRONE_IP = "10.202.0.1" casey = olympe.Drone("10.202.1.1") drone = olympe.Drone(DRONE_IP) # if __name__ == "__main__": # with olympe.Drone(DRONE_IP) as drone: drone.connect() casey.connect() # Start a flying action asynchronously drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) >> moveTo( 21.37313, -157.7123, 15, MoveTo_Orientation_mode.NONE, 0.0) >> moveToChanged(status="DONE") >> moveTo( 21.37313, -157.7098, 15, MoveTo_Orientation_mode.NONE, 0.0) >> moveToChanged(status="DONE") >> Landing()) casey(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) >> moveTo( 21.3708, -157.709881, 15, MoveTo_Orientation_mode.NONE, 0.0) >> moveToChanged(status="DONE") >> moveTo( 21.368464, -157.71239, 15, MoveTo_Orientation_mode.NONE, 0.0) >> moveToChanged(status="DONE") >> Landing()).wait().success() # t:21.3708,lng:-157.709881 - east
import math import time import olympe from olympe.messages.ardrone3.Piloting import TakeOff, Landing, PCMD from olympe.messages.ardrone3.PilotingState import FlyingStateChanged with olympe.Drone("10.202.0.1", loglevel=3) as drone: drone.connection() print("\n\n\n ---------- \n\n\n") drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)).wait() print("\n\n\n -----TakeOff complete----- \n\n\n") while True: drone(PCMD(1, roll=20, pitch=100, yaw=50, gaz=20, timestampAndSeqNum=0)).wait() time.sleep(0.2) print("\n\n\n ---- Circle finished ---- \n\n\n") drone(Landing()).wait() print("\n\n\n ---- Drone landed ---- \n\n\n") #Leaving the with statement and disconnecting the drone.
import olympe import olympe_deps as od from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing from olympe.messages.skyctrl.CoPiloting import setPilotingSource import time import cv2 import mss import numpy as np import apriltag # Create the apriltag detector detector = apriltag.Detector() # If using real drone with Skycontroller 3: drone = olympe.Drone("192.168.53.1", mpp=True, drone_type=od.ARSDK_DEVICE_TYPE_ANAFI4K) # If using simulation: # drone = olympe.Drone("10.202.0.1") # Connect to the drone drone.connection() drone(setPilotingSource(source="Controller")).wait() # Flag for takeoff state takeoff_flag = False # Here we use mss to capture the screen output from PDrAW with mss.mss() as sct: # Set which part of the screen to capture. Make sure your PDrAW window is always here. monitor = {"top": 60, "left": 60, "width": 960, "height": 540}
def __init__(self): # Create the olympe.Drone object from its IP address self.drone = olympe.Drone(DRONE_IP) super().__init__()
# rapheal = findOffset(lat,lng,80,0) # michaelangelo = findOffset(lat,lng,60, 0) # donatello = findOffset(lat,lng,40,0) # splinter = findOffset(lat,lng,20,0) # leonardo = findOffset(lat,lng,0,0) casey = findOffset(lat,lng,-20,0) return casey DRONE_IP = "10.202.0.1" casey_ip = "10.202.1.1" donatello_ip = "10.202.2.1" leonardo_ip = "10.202.3.1" michelangelo_ip = "10.202.4.1" raphael_ip = "10.202.5.1" splinter_ip = "10.202.6.1" casey = olympe.Drone(casey_ip) donatello = olympe.Drone(donatello_ip) leonardo = olympe.Drone(leonardo_ip) michelangelo = olympe.Drone(michelangelo_ip) # raphael = olympe.Drone(raphael_ip) # splinter = olympe.Drone(splinter_ip) def followerTakeOff(drone): drone( FlyingStateChanged(state="hovering") | (TakeOff() & FlyingStateChanged(state="hovering")) ).wait().success() def print_event(event): # Here we're just serializing an event object and truncate the result if necessary
# Drone IP ANAFI_IP = "10.202.0.1" # Drone web server URL ANAFI_URL = "http://{}/".format(ANAFI_IP) # Drone media web API URL ANAFI_MEDIA_API_URL = ANAFI_URL + "api/v1/media/medias/" #Connect to drone os.system('cls' if os.name == 'nt' else 'clear') clear_output(wait=True) print("*******************************************************************************************************") print("CONNECTING TO DRONE") print("*******************************************************************************************************") drone = olympe.Drone(ANAFI_IP) drone.connection() os.system('cls' if os.name == 'nt' else 'clear') clear_output(wait=True) print("*******************************************************************************************************") print("CONNECTION SUCCESSFUL") print("*******************************************************************************************************") #Takeoff os.system('cls' if os.name == 'nt' else 'clear') clear_output(wait=True) print("*******************************************************************************************************") print("TAKING OFF") print("*******************************************************************************************************") drone( TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)
"filename": "olympe.log" }, "ulog_log_file": { "class": "logging.FileHandler", "formatter": "default_formatter", "filename": "ulog.log" }, }, "loggers": { "olympe": { "handlers": ["console", "olympe_log_file"] }, "ulog": { "level": "DEBUG", "handlers": ["console", "ulog_log_file"], } } }) DRONE_IP = "10.202.0.1" if __name__ == "__main__": drone = olympe.Drone(DRONE_IP, name="toto") drone.connect() assert drone(TakeOff()).wait().success() assert drone.start_video_streaming() time.sleep(10) assert drone.stop_video_streaming() assert drone(Landing()).wait().success() drone.disconnect()
def __init__(self): # Create the olympe.Drone object from its IP address self.drone = olympe.Drone(DRONE_IP) # subscribe to flight listener listener = FlightListener(self.drone) listener.subscribe() self.last_frame = np.zeros((1, 1, 3), np.uint8) self.frame_queue = queue.Queue() self.flush_queue_lock = threading.Lock() self.detector = Detector() self.keypoints_image = np.zeros((1, 1, 3), np.uint8) self.keypoints = deque(maxlen=5) self.faces = deque(maxlen=10) self.f = open("distances.csv", "w") self.face_distances = deque(maxlen=10) self.image_width = 1280 self.image_height = 720 self.half_face_detection_size = 150 self.poses_model = load("models/posesmodel.joblib") self.pose_predictions = deque(maxlen=5) self.pause_finding_condition = threading.Condition(threading.Lock()) self.pause_finding_condition.acquire() self.pause_finding = True self.person_thread = threading.Thread(target=self.fly_to_person) self.person_thread.start() # flight parameters in meter self.flight_height = 0.0 self.max_height = 1.0 self.min_dist = 1.5 # keypoint map self.nose = 0 self.left_eye = 1 self.right_eye = 2 self.left_ear = 3 self.right_ear = 4 self.left_shoulder = 5 self.right_shoulder = 6 self.left_elbow = 7 self.right_elbow = 8 self.left_wrist = 9 self.right_wrist = 10 self.left_hip = 11 self.right_hip = 12 self.left_knee = 13 self.right_knee = 14 self.left_ankle = 15 self.right_ankle = 16 # person distance self.eye_dist = 0.0 # save images self.save_image = False self.image_counter = 243 self.pose_file = open("poses.csv", "w") super().__init__() super().start()
AttitudeChanged, AltitudeAboveGroundChanged, AlertStateChanged, FlyingStateChanged, NavigateHomeStateChanged, ) # working subscription - drone leader takes off and moves away # casey takes off after drone leader takes off and will follow leaders position # this does a square flight pattern olympe.log.update_config({"loggers": {"olympe": {"level": "WARNING"}}}) DRONE_IP = "10.202.0.1" casey_ip = "10.202.1.1" casey = olympe.Drone(casey_ip) def caseyTakeOff(): casey( FlyingStateChanged(state="hovering") | (TakeOff() & FlyingStateChanged(state="hovering")) ).wait().success() def print_event(event): # Here we're just serializing an event object and truncate the result if necessary # before printing it. if isinstance(event, olympe.ArsdkMessageEvent): max_args_size = 60 args = str(event.args) args = (args[: max_args_size - 3] + "...") if len(args) > max_args_size else args
# michaelangelo = findOffset(lat,lng,60, 0) # donatello = findOffset(lat,lng,40,0) # splinter = findOffset(lat,lng,20,0) # leonardo = findOffset(lat,lng,0,0) casey = findOffset(lat, lng, -20, 0) return casey DRONE_IP = "10.202.0.1" casey_ip = "10.202.1.1" donatello_ip = "10.202.2.1" leonardo_ip = "10.202.3.1" michelangelo_ip = "10.202.4.1" raphael_ip = "10.202.5.1" splinter_ip = "10.202.6.1" casey = olympe.Drone(casey_ip) donatello = olympe.Drone(donatello_ip) leonardo = olympe.Drone(leonardo_ip) michelangelo = olympe.Drone(michelangelo_ip) raphael = olympe.Drone(raphael_ip) splinter = olympe.Drone(splinter_ip) def followerTakeOff(drone): drone( FlyingStateChanged(state="hovering") | (TakeOff() & FlyingStateChanged(state="hovering"))).wait().success() def print_event(event): # Here we're just serializing an event object and truncate the result if necessary
# If you are testing this with physcial drone, please ensure you have big enough free space. import olympe import olympe_deps as od from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing from olympe.messages.ardrone3.PilotingState import FlyingStateChanged, PositionChanged, SpeedChanged from olympe.messages.skyctrl.CoPiloting import setPilotingSource import time SIMULATION = True # choose wether to use simulated drone or physical one file_object = open('drone_log.txt', 'w', encoding='UTF-8') # create a file to store logs if SIMULATION: # connect to simulated drone in SPHINX and redirect drone logs into the file to keep terminal clean drone = olympe.Drone("10.202.0.1", logfile=file_object) # create Drone instance else: # connect to physical drone through the Sky Controller # you can also connect to drone using Wifi using ip address 192.168.42.1 drone = olympe.Drone("192.168.53.1", logfile=file_object, mpp=True, drone_type=od.ARSDK_DEVICE_TYPE_ANAFI4K) # connect to the drone and check if connection was established response = drone.connection() if not response.OK: # if connection failed, exit print("Connection was not successful") exit() # set piloting source to controller, only when connecting through the Sky Controller
def test_physical_drone(): drone = olympe.Drone(DRONE_IP) drone.connect() drone.disconnect()
def test_photo(): with olympe.Drone(DRONE_IP, media_port=DRONE_MEDIA_PORT) as drone: main(drone)
set_photo_mode( cam_id=0, mode="burst", format="rectilinear", file_format="jpeg", burst="burst_14_over_1s", bracketing="preset_1ev", capture_interval=0.0, )).wait() def filecreation(): mydir = os.path.join(os.getcwd(), datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) try: os.makedirs(mydir) except OSError as e: if e.errno != errno.EEXIST: raise # This was not a "directory exist" error return (mydir) def main(drone): drone.connection() setup_photo_burst_mode(drone) take_photo_burst(drone) if __name__ == "__main__": with olympe.Drone(ANAFI_IP, loglevel=0) as drone: main(drone)
from __future__ import print_function import olympe from olympe.messages.ardrone3.PilotingSettings import MaxTilt # drone = olympe.Drone("10.202.0.1") drone = olympe.Drone("10.202.0.1", loglevel=1) drone.connection() maxTiltAction = drone(MaxTilt(10)).wait() if maxTiltAction.success(): print("MaxTilt(10) success") elif maxTiltAction.timedout(): print("MaxTilt(10) success") else: # If ".wait()" is called on the _maxTiltAction_ this shouldn't happen print("MaxTilt(10) is still in progress") maxTiltAction = drone(MaxTilt(1)).wait() if maxTiltAction.success(): print("MaxTilt(1) success") elif maxTiltAction.timedout(): print("MaxTilt(1) timedout") else: # If ".wait()" is called on the _maxTiltAction_ this shouldn't happen print("Maxtilt(1) is still in progress") drone.disconnection()
import olympe import olympe_deps as od from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing from olympe.messages.ardrone3.PilotingState import FlyingStateChanged # drone = olympe.Drone("10.202.0.1") drone = olympe.Drone("10.202.0.1", drone_type=od.ARSDK_DEVICE_TYPE_BEBOP_2, logfile=open("/tmp/drone_moveby.log", "a+")) drone.connection() drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)).wait() drone(moveBy(5, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() drone(Landing()).wait() drone.disconnection()
drone.connection() drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)).wait() """ Video Processing """ print("-----Video Processing-----") video_classification(drone) """ Landing """ write_stop_output() print("*****Landing*****") drone(Landing() >> FlyingStateChanged(state="landed", _timeout=5)).wait() #print("**** Total Flight Time: " + flight_time() + "*****") drone.disconnection() """ __main__ Initialise the drones IP to either the Skycontroller or the drone itself. Pass this as drone to the main function. """ if __name__ == "__main__": SkyCntrl_IP = "192.168.53.1" Anafi_IP = "192.168.42.1" Anafi_URL = "http://{}/".format(Anafi_IP) with olympe.Drone(SkyCntrl_IP) as drone: main(drone)
def __init__(self): self.flying=False self.drone = olympe.Drone(DRONE_IP)
import olympe from olympe.messages.ardrone3.Piloting import TakeOff, moveBy, Landing from olympe.messages.ardrone3.PilotingState import FlyingStateChanged drone = olympe.Drone("10.202.0.1") drone.connection() drone( TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() drone( moveBy(10, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() drone( moveBy(-10, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) ).wait() drone(Landing()).wait() drone.disconnection()
photo_progress(result="photo_saved", _policy="wait")) drone(take_photo(cam_id=0)).wait() if not photo_saved.wait(_timeout=30).success(): logger.error("Photo not saved: {}".format(photo_saved.explain())) assert media_listener.remote_resource_count == 14, "remote resource count = {}".format( media_listener.remote_resource_count) assert media_listener.local_resource_count == 14, "local resource count = {}".format( media_listener.local_resource_count) if __name__ == "__main__": # Here we want to demonstrate olympe.Media class usage as a standalone API # so we disable the drone object media autoconnection (we won't use # drone.media) and choose to instantiate the olympe.Media class ourselves with olympe.Drone(DRONE_IP, media_autoconnect=False, name="example_media_standalone") as drone: drone.connect() media = olympe.Media(DRONE_IP, name="example_media_standalone") media.connect() main(drone, media) media.shutdown() drone.disconnect() # By default, the drone instantiate an internal olympe.Media object (media_autoconnect=True # by default). This olympe.Media object is exposed through the Drone.media property. In this # case the connection to the remote media API endpoint is automatically handled by the olympe # drone controller class. with olympe.Drone(DRONE_IP, name="example_media_autoconnect") as drone: drone.connect() main(drone)
def _land(self): """Lands the drone""" print("Landing...") self.drone(Landing() >> FlyingStateChanged(state="landed", _timeout=5) ).wait() def move(self, joy_values): """ Move in the desired direction given the (normalized) Joystick values: [LeftThumbXAxis, LeftThumbYAxis, RightThumbXAxis, RightThumbYAxis, Select/Quit] """ # movements must be in [-100:100] left_right, front_back, turning, up_down = [ int(j * self.drone_speed) for j in joy_values ] self.drone.piloting_pcmd(left_right, -front_back, turning, -up_down, self.drone_mtime) if __name__ == "__main__": drone = olympe.Drone(JoystickTeleop.SIMULATED_IP, loglevel=0) try: x = JoystickTeleop(drone) x.start() except KeyboardInterrupt: x.stop() print("Teleoperating stopped\n") sys.exit(0)
import jsonrpclib import olympe import olympe_deps as od from olympe.messages.ardrone3.Piloting import TakeOff, Landing, Circle from olympe.messages.ardrone3.PilotingState import FlyingStateChanged sphinx_client = jsonrpclib.Server("http://127.0.0.1:8383") drone = olympe.Drone("10.202.0.1", od.ARSDK_DEVICE_TYPE_EVINRUDE) drone.connection() sphinx_client.TriggerAction( machine="disco", # this should match the drone name in the .drone file object="fixedwings_shake/handling", action="start") drone(TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5)).wait() drone(Circle(1) >> FlyingStateChanged(state="hovering", _timeout=5)).wait() drone(Landing()).wait() drone.disconnection()