Example #1
0
    def __init__(self, drone_state_dict, pipe):
        self.pipe = pipe
        self.drone = ps_drone.Drone()
        self.modem = ec25_modem.Modem("/dev/ttyUSB2")
        self.gps = AGPS3mechanism()

        self.control_state = ControlState()
        self.drone_state = DroneState()
        self.drone_state_dict = drone_state_dict
        self.prev_data_count = 0
        self.app_connected = False
        self.app_disconnected_timer = None
        self.drone_connected = False
        self.drone_calibrated = False
        self.returning = False
        self.modem_connected = False
        self.gps_l80 = True
        self.autonomous_sigs = None

        self.running = True

        i = 0
        while os.path.exists(os.path.expanduser("~/dronelog/log_%s.csv") % i):
            i += 1
        self.logfile = open(
            os.path.expanduser("~/dronelog/log_%s.csv") % i, "w")
        self.logwriter = csv.writer(self.logfile)
Example #2
0
def init_drone():

    # Connect
    drone = ps_drone.Drone()
    drone.startup()

    # Reset
    drone.reset()

    while drone.getBattery()[0] == -1:
        time.sleep(0.1)

    time.sleep(0.5)

    # Calibrate
    drone.trim()
    drone.getSelfRotation(5)

    # Configure video
    cdc0 = drone.ConfigDataCount

    drone.setConfigAllID()
    drone.hdVideo()
    drone.frontCam()

    while drone.ConfigDataCount == cdc0:
        time.sleep(0.1)

    drone.startVideo()

    return drone, (drone.getBattery()[1] != 'empty')
Example #3
0
 def __init__(self):
     self.drone = ps_drone.Drone()
     self.connected = False
     self.altitude = 0
     self.speed = 0
     self.accel = 0
     self.battery = 0
Example #4
0
def main(**kwargs):

    options = {'smooth': False, 'time_lim': 30}
    options.update(kwargs)

    drone = ps_drone.Drone()
    drone.startup()
    drone.reset()

    while (drone.getBattery()[0] == -1):
        time.sleep(.01)

    print "Battery: " + str(drone.getBattery()[0]) + "%  " + str(
        drone.getBattery()[1])  # Gives a battery-status
    if drone.getBattery()[1] == "empty":
        return

    print('Initialized')

    if options['smooth']:
        smooth_flying(drone, options['time_lim'])
    else:
        rough_flying(drone, options['time_lim'])

    print('Finished Flying')

    return
Example #5
0
def main():
	drone = ps_drone.Drone()		#Drone object
	fdrone__init(drone)
	root = tk.Tk()
	root.geometry("900x600")		#GUI window dimensions
	drone_GUI = DCMainApp(root, drone)
	#root.protocol("WM_DELETE_WINDOW", drone_GUI.quit)
	root.mainloop()
Example #6
0
def attack_drone(payload):
    zombie = ps_drone.Drone()
    if zombie.startup() is False:
        return
    zombie.useDemoMode(False)
    if payload == 'land':
        zombie.shutdown()
    elif payload == 'demon':
        demon_drone(zombie)
Example #7
0
 def __init__(self):
     self.drone = ps_drone.Drone()
     self.drone.startup()
     self.drone.reset()
     while (self.drone.getBattery()[0] == -1):
         time.sleep(0.1)
     self.drone.useDemoMode(True)
     self.drone.getNDpackage(["demo", "altitude", "vision_detect", "time"])
     self.configure()
def initialize_drone():
    drone = ps_drone.Drone()
    drone.startup()
    drone.reset()

    #Wait for reset to complete
    while (drone.getBattery()[0] == -1):
        time.sleep(.01)

    return drone
Example #9
0
def start_drone():
    #Cresting drone instance and starting drone
    drone = ps_drone.Drone()
    drone.startup()

    # Start drone
    drone.trim()
    time.sleep(1)
    drone.takeoff()
    time.sleep(3)
Example #10
0
def initDrone(drone):
    drone = ARDrone.Drone()
    drone.startup()
    drone.reset()
    time.sleep(1)
    drone.trim()
    drone.useDemoMode(False)
    # **FIX ME: Get time working
    # drone.getNDpackage(["demo","time"])
    drone.getNDpackage(["demo"])
    is_drone_flying = drone.NavData["demo"][0][2]

    return drone
Example #11
0
def start_up_drone():
    drone = ps_drone.Drone()  # Start using drone

    drone.startup()  # Connects to drone and starts subprocesses
    drone.reset()  # Always good, at start

    drone.useDemoMode(True)

    while drone.getBattery()[0] == -1:
        time.sleep(0.1)  # Waits until the drone has done its reset
    time.sleep(0.5)  # Give it some time to fully awake

    drone.printBlue("Battery: " + str(drone.getBattery()[0]) + "%  " +
                    str(drone.getBattery()[1]))  # Gives a battery-status
    return drone
Example #12
0
def get_drone(defaultSpeed=OPTIMAL_MVSPEED, videoOn=True):
    drone = ps_drone.Drone()
    drone.startup()
    drone.reset()
    # Wait till the drone fully resets
    time.sleep(2)

    # getBattery() returns (batValue percent), batStatus(OK or empty))
    while drone.getBattery()[0] == -1:
        time.sleep(0.1)

    # Give the drone some time to fully awake
    time.sleep(0.5)

    # "demo", "vision detect" and "chksum" packages of Navdata
    # are available 15 times per second
    drone.useDemoMode(True)

    # Recalibrate sensors
    drone.trim()
    drone.mtrim()

    # Set the speed of the drone
    drone.setSpeed(defaultSpeed)

    print_battery(drone)

    # Initialize the drone's video function
    if videoOn:
        # Need to switch drone to multi-configuration mode before using video
        drone.setConfigAllID()
        # Use lower resolution
        drone.sdVideo()
        # Use front camera
        drone.frontCam()

        # Activate the drone's video function
        drone.printYellow('Loading Video Function...')
        drone.startVideo()

        VIC = drone.VideoImageCount
        while VIC == drone.VideoImageCount:
            time.sleep(0.5)

        drone.showVideo()
        drone.printGreen('Video Function Loaded')

    return drone
Example #13
0
    def __init__(self, *args, **kwargs):
        self.drone = ps_drone.Drone()
        drone = self.drone
        drone.startup()

        drone.reset()
        #time.sleep(20)
        while (drone.getBattery()[0] == -1):
            time.sleep(0.1)
        print "Battery: " + str(drone.getBattery()[0]) + "%  " + str(
            drone.getBattery()[1])
        drone.useDemoMode(False)
        drone.setConfigAllID()
        drone.setMConfig("video:video_channel", "1")
        drone.setMConfig("video:video_codec", "128")
        drone.setMConfig("video:bitrate", 5000)
        drone.setMConfig("video:codec_fps", 5)

        CDC = drone.ConfigDataCount
        while CDC == drone.ConfigDataCount:
            time.sleep(0.0001)

        drone.startVideo()
        drone.showVideo()
        self.IMC = drone.VideoImageCount

        self.stop = False
        self.ground = True
        self.takeOff = False
        self.processingImage = False
        self.mostGreen = 1
        self.previousGreen = 0
        self.previousTally = 0
        self.currentTally = 0
        self.videoProcessing()
        self.startProcessing = False
        self.lostGreen = False
        self.red = 0
Example #14
0
# It shows the usage of the video-function of a Parrot AR.Drone 2.0 using the PS-Drone-API.
# The drone will stay on the ground.
# Dependencies: a POSIX OS, openCV2, PS-Drone-API 2.0 beta or higher.
# (w) J. Philipp de Graaff, www.playsheep.de, 2016
##########
# LICENCE:
#   Artistic License 2.0 as seen on http://opensource.org/licenses/artistic-license-2.0 (retrieved December 2014)
#   Visit www.playsheep.de/drone or see the PS-Drone-API-documentation for an abstract from the Artistic License 2.0.
###########

##### Suggested clean drone startup sequence #####
import time, sys
import ps_drone  # Import PS-Drone-API
import cv2  # Import OpenCV

drone = ps_drone.Drone()  # Start using drone
drone.startup()  # Connects to drone and starts subprocesses

drone.reset()  # Sets drone's status to good (LEDs turn green when red)
while (drone.getBattery()[0] == -1):
    time.sleep(0.1)  # Waits until drone has done its reset
print "Battery: " + str(drone.getBattery()[0]) + "%  " + str(
    drone.getBattery()[1])  # Gives a battery-status
drone.useDemoMode(
    True)  # Just give me 15 basic dataset per second (is default anyway)

##### Mainprogram begin #####
drone.setConfigAllID()  # Go to multiconfiguration-mode
drone.sdVideo()  # Choose lower resolution (hdVideo() for...well, guess it)
drone.frontCam()  # Choose front view
CDC = drone.ConfigDataCount
Example #15
0
    drone.sdVideo()
    drone.groundCam()
    CDC = drone.ConfigDataCount
    while CDC == drone.ConfigDataCount:
        time.sleep(0.0001)
    print "Taking off..."
    #drone.takeoff()
    time.sleep(5)
    #basic_movements()
    drone.startVideo()
    drone.getNDpackage(["demo"])
    root.title("Autonomous Flight Control Center")
    root.geometry("650x365")


drone = ps_drone.Drone()
root = tk.Tk()
setup(drone)
lmain = tk.Label(root)
lmain.pack()
IMC = drone.VideoImageCount
centered = False
average = 0
counter = 0
prevAngle = 0
centeredOverRedCircle = True


def show_frame():
    global y
    global ySeconds
Example #16
0
        print('\n Rotation\n ')
        #read the serial data first
        deg = data()
        if deg > 0.0:
            drone.turnLeft()  # Drone moves full speed to the left...
            time.sleep(3)  # ... for two seconds
            drone.stop()  # Drone stops
            time.sleep(2)
        else:
            drone.turnRight()  # Drone moves full speed to the left...
            time.sleep(3)  # ... for two seconds
            drone.stop()  # Drone stops
            time.sleep(2)


drone = ps_drone.Drone()  # Initializes the PS-Drone-API
drone.startup()  # Connects to the drone and starts subprocesses

try:
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(6, GPIO.RISING, callback=my_callback)
    GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(23, GPIO.RISING, callback=my_callback)
    GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(24, GPIO.RISING, callback=my_callback)

    message = raw_input('\nPress any key to exit.\n')

finally:
    GPIO.cleanup()
Example #17
0
import time
import ps_drone as ARDrone

drone = ARDrone.Drone()
drone.startup()
drone.reset()
time.sleep(1)
print "Battery: " + str(drone.getBattery()[0]) + "%  " + str(
    drone.getBattery()[1])
Example #18
0
def main():
    #path = [(0.3,0.3),(0.6,0),(0.9,0.3),(1.2,0.3),(1.2,0.6),(1.5,0.6),-1]
    path = [(0.3, 0.3), (1.5, 0.3), -1]

    # tag id with positions
    tags = {
        "0": (0, 0),
        "1": (0.3, 0),
        "2": (0.6, 0),
        "3": (0.9, 0),
        "4": (1.2, 0),
        "5": (1.5, 0),
        "6": (1.8, 0),
        "7": (0, 0.3),
        "8": (0.3, 0.3),
        "9": (0.6, 0.3),
        "10": (0.9, 0.3),
        "11": (1.2, 0.3),
        "12": (1.5, 0.3),
        "13": (1.8, 0.3),
        "14": (0, 0.6),
        "15": (0.3, 0.6),
        "16": (0.6, 0.6),
        "17": (0.9, 0.6),
        "18": (1.2, 0.6),
        "19": (1.5, 0.6),
        "20": (1.8, 0.6),
        "21": (0, 0.9),
        "22": (0.3, 0.9),
        "23": (0.6, 0.9),
        "24": (0.9, 0.9),
        "25": (1.2, 0.9),
        "26": (1.5, 0.9),
        "27": (1.8, 0.9)
    }

    # drone's current position, point count, target point, and detection
    curPos = (0.0, 0.0)
    pointCount = 0
    targetPoint = path[0]
    detection = {'tags': []}

    # init drone
    drone = ps_drone.Drone()
    drone.startup()

    drone.reset()
    while (drone.getBattery()[0] == -1):
        time.sleep(0.1)
    print("Battery: " + str(drone.getBattery()[0]) + "%  " +
          str(drone.getBattery()[1]))
    drone.useDemoMode(True)
    drone.setConfigAllID()
    drone.sdVideo()
    drone.groundCam()
    drone.stopVideo()

    ON_POSIX = 'posix' in sys.builtin_module_names

    video = Popen(
        ['apriltags/build/bin/drone_demo', '-D', '-1', '-c', '-s', '3'],
        stdout=PIPE,
        bufsize=1,
        close_fds=ON_POSIX)
    q = Queue()
    t = Thread(target=enqueue_output, args=(video.stdout, q))
    t.daemon = True
    t.start()
    detection = {'tags': []}

    # show frame
    image = numpy.zeros((360, 640))
    cv2.namedWindow('image', cv2.WINDOW_AUTOSIZE)
    cv2.imshow('image', image)

    # take off
    print("taking off...")
    drone.takeoff()
    time.sleep(15)

    # loop
    for count in range(10000):

        # manual control of landing for safety
        key = drone.getKey()
        if key == " ":
            drone.land()

        if video.poll() is None:
            try:
                raw = q.get_nowait()
            except Empty:
                print('no output yet')
            else:
                if raw.startswith('#'):
                    detection = json.loads(raw[1:])
        else:
            video = Popen([
                'apriltags/build/bin/drone_demo', '-D', '-1', '-c', '-s', '3'
            ],
                          stdout=PIPE,
                          bufsize=1,
                          close_fds=ON_POSIX)
            detection = {'tags': []}
            drone.hover()

        # calculate current position from detected tags
        if 'image' in detection and len(detection['tags']):
            curPos = getCurPosfromTags(detection, tags)
            #pprint(curPos)
        else:
            drone.stop()
        #cv2.waitKey(500)
        # move to the target point
        path, curPos, pointCount, targetPoint = moveToTargetPoint(
            drone, path, curPos, pointCount, targetPoint)
Example #19
0
def originalDroneController(video=False):
    #import time
    import ps_drone

    drone = ps_drone.Drone()  # Start using drone
    drone.printBlue("Battery: ")

    drone.startup()  # Connects to drone and starts subprocesses
    drone.reset()  # Always good, at start

    while drone.getBattery()[0] == -1:
        tme.sleep(0.1)  # Waits until the drone has done its reset
    tme.sleep(0.5)  # Give it some time to fully awake

    drone.printBlue("Battery: " + str(drone.getBattery()[0]) + "%  " +
                    str(drone.getBattery()[1]))  # Gives a battery-status
    drone.setSpeed(0.05)
    '''
	if video:
		##### Video begin #####
		drone.setConfigAllID()                              # Go to multiconfiguration-mode
		drone.sdVideo()                                     # Choose lower resolution (try hdVideo())
		drone.frontCam()                                    # Choose front view
		CDC = drone.ConfigDataCount
		while CDC==drone.ConfigDataCount: tme.sleep(0.001) # Wait until it is done (after resync)
		drone.startVideo()                                  # Start video-function
		drone.showVideo()                                   # Display the video
		IMC =    drone.VideoImageCount 						# Number of encoded videoframes
	'''

    ##### Controller variables ######
    opposite = {2: 8, 4: 6, 6: 4, 8: 2, 0: 0}
    otherkey = {2: [4, 6], 4: [2, 8], 6: [2, 8], 8: [4, 6], 0: [2, 4, 6, 8]}
    pressedKey = None
    keypress = False
    previousPrediction = 0
    prevPreviousPrediction = 0
    gotfive = 0
    gotopposite = 0
    gotother = 0
    #gotfive = 0
    blinks = 0
    lastTime = datetime.now()
    brainz = True

    print("Setup finished")
    stop = False
    #keyboard.hook(print_pressed_keys)
    while not stop:
        '''
		if video:
			while drone.VideoImageCount==IMC: tme.sleep(0.01) # Wait until the next video-frame
			IMC = drone.VideoImageCount
		'''

        key = drone.getKey()

        if (key == " ") or (blinks >= 3):
            if drone.NavData["demo"][0][2] and not drone.NavData["demo"][0][3]:
                drone.takeoff()
            else:
                drone.land()
            blinks = 0

        elif key == "z":
            if brainz:
                brainz = False
                print("No longer flying with brainz")
                #drone.land()
            else:
                brainz = True
                print("Flying by brain, GO!")
                blinks = 0
                print("waiting for lock")
                with glb.predictionslock:
                    print("got lock")
                    #del glb.predictions[:]
                    try:
                        glb.predictionsQueue.queue.clear()
                    except:
                        pass

                print("Finished clearing predictions queue")

        elif key == "0":
            drone.hover()
        elif key == "w":
            drone.moveForward()
        elif key == "s":
            drone.moveBackward()
        elif key == "a":
            drone.moveLeft()
        elif key == "d":
            drone.moveRight()
        elif key == "q":
            drone.turnLeft()
        elif key == "e":
            drone.turnRight()
        elif key == "7":
            drone.turnAngle(-10, 1)
        elif key == "9":
            drone.turnAngle(10, 1)
        elif key == "4":
            drone.turnAngle(-45, 1)
        elif key == "6":
            drone.turnAngle(45, 1)
        elif key == "1":
            drone.turnAngle(-90, 1)
        elif key == "3":
            drone.turnAngle(90, 1)
        elif key == "8":
            drone.moveUp()
        elif key == "2":
            drone.moveDown()
        elif key == "*":
            drone.doggyHop()
        elif key == "+":
            drone.doggyNod()
        elif key == "-":
            drone.doggyWag()
        elif key != "":
            stop = True
            print("Exiting")
        #elif key == "other":	stop = True

        if brainz:
            blinks, opposite, otherkey, pressedKey, keypress, previousPrediction, prevPreviousPrediction, gotfive, gotother, gotopposite, lastTime\
            = stateMachine(blinks, opposite, otherkey, pressedKey, keypress, previousPrediction, prevPreviousPrediction, gotfive, gotother, gotopposite, lastTime, drone)

            tme.sleep(0.01)

    print "Batterie: " + str(drone.getBattery()[0]) + "%  " + str(
        drone.getBattery()[1])  # Gives a battery-status
Example #20
0
import ps_drone

drone1 = ps_drone.Drone()
drone2 = ps_drone.Drone()
print "1"

drone1.DroneIP = "192.168.1.101"
drone2.DroneIP = "192.168.1.102"
print "2"

drone1.startup()
print "3"
drone2.startup()
print "4"

drone1.reset()
drone2.reset()
print "5"

while (drone1.getBattery()[0] == -1):
    time.sleep(0.1)  #Reset completed?
while (drone2.getBattery()[0] == -1):
    time.sleep(0.1)  #Reset completed?
print "6"

print "Drone1 battery: " + str(drone1.getBattery()[0]) + "% " + str(
    drone1.getBattery()[1])
print "Drone2 battery: " + str(drone2.getBattery()[0]) + "%" + str(
    drone2.getBattery()[1])
print "7"