simple_flightscript.py 1.04 KB
Newer Older
1
#!/usr/bin/env python3
2 3 4

import logging
import time
5
import sys
6 7 8 9 10

import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander

11 12 13 14 15 16 17 18 19 20 21 22 23
URI = ''

if len(sys.argv) >= 2:
    if sys.argv[1] == 'radio':
        URI = 'radio://0/80/2M'
    elif sys.argv[1] == 'prrt':
        URI = 'prrt://10.8.0.208:5000'
    elif sys.argv[1] == 'serial':
        URI = 'serial://pi'
    else:
        sys.exit('Give a valid argument.')
else:
    sys.exit('Give a commandline argument.')
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)

if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)

    with SyncCrazyflie(URI) as scf:
        # We take off when the commander is created
        with MotionCommander(scf) as mc:
            print('Taking off!')
            time.sleep(0.1)
            # We land when the MotionCommander goes out of scope
            print('Landing!')