Example #1
0
class App:
    def __init__(self, car, inputs, droneClass):
        self.car = car
        self.inputs = inputs
        self.drone = None

        self.droneClass = droneClass
        self.isTicking = False
        atexit.register(self.destroy)

    def start(self):
        if self.droneClass:
            self.drone = MyARDrone(self.droneClass())
            # JRTODO - for connection check, might need to wait a few sec
            #            if self.drone.connected():
            print "[DEBUG] Connected to Drone"
            self.drone.reset()
        #            else:
        #                print "[ERROR] Not connected to drone. Is the wifi connected?"
        #                import sys
        #                sys.exit(1)
        else:
            print "[DEBUG] No drone class selected. Not connecting to drone."

        if self.car:
            self.car.connect()
            print "[DEBUG] Connected to Car"

            self.cs = DroneStateControl(self.inputs, self.drone)

            self.car.registerListener(self.cs.received_input)

    def startTicking(self, args=None):
        self.isTicking = True
        if self.drone:
            while self.isTicking:
                self.cs.tick()
                time.sleep(STATE_TICK_SPEED)
        else:
            print "[WARNING] No drone connected, so not ticking drone states."
            while self.isTicking:
                time.sleep(0.001)
        print "NO TICK"

    def destroy(self):
        print "---------------- SHUTDOWN ---------------- "
        self.isTicking = False

        if self.drone:
            self.drone.land()
            self.drone.halt()

        if self.car:
            self.car.disconnect()
Example #2
0
    def start(self):
        if self.droneClass:
            self.drone = MyARDrone(self.droneClass())
            # JRTODO - for connection check, might need to wait a few sec
            #            if self.drone.connected():
            print "[DEBUG] Connected to Drone"
            self.drone.reset()
        #            else:
        #                print "[ERROR] Not connected to drone. Is the wifi connected?"
        #                import sys
        #                sys.exit(1)
        else:
            print "[DEBUG] No drone class selected. Not connecting to drone."

        if self.car:
            self.car.connect()
            print "[DEBUG] Connected to Car"

            self.cs = DroneStateControl(self.inputs, self.drone)

            self.car.registerListener(self.cs.received_input)