Exemple #1
0
    def run(self):
        global isNextPathNeeded
        global nextPathSema
        global newLevelReached

        while 1:

            # if isNextPathNeeded:
            #     print self.threadName, "blocking"
            #     nextPathSema.acquire()

            locationTrackerLock.acquire()

            if newLevelReached and not self.isDone['nOffset']:
                print "Recalibrating compass!!!"
                self.calibrateNOffset()
                self.updateBaroData()
                self.updateGyroData()
                self.updateAccData()

            elif newLevelReached and self.isDone['nOffset']:
                print "\n\n Compass recalibrated!! \n\n"
                locationTracker.compass.prevHeadingInRad = self.calibrator.NOffsetAngle
                locationTracker.updateCurrHeading(45.0 / 180.0 * math.pi)
                newLevelReached = False

            else:
                self.updateAccData()
                self.updateMagData()
                self.updateBaroData()
                self.updateGyroData()

            locationTrackerLock.release()
Exemple #2
0
    def run(self):
        # magXrange = (-4328, 5605)
        # magYRange = (-5096, 5002)
        # magZRange = (-4618, 4655)
        # self.calibrator.inputManualRange(magZRange, magYRange, magXrange)
        userInputLock.acquire()

        global keypad
        global UISpeaker
        global data, data_single

        validInput = False
        while not validInput:
            # userInput = raw_input("Press enter to calibrate? y/n ")
            UISpeaker.speak(str("To calibrate gyroscope, press start."))
            userInput = keypad.get_binary_response()
            print userInput
            if not userInput:
                validInput = True
                for i in range(0, 3):
                    num = 3 - i
                    print num
                    UISpeaker.speak(str(num))
                    time.sleep(1)
                dataFeeder.serialPort.flushInput()
                dataFeeder.serialPort.flushOutput()

                data = [deque() for x in range(NUM_QUEUED_ID)]
                data_single = [0 for x in range(NUM_SINGLE_ID)]
                data.extend(data_single)

                userInputLock.release()

        print len(data[1])

        while not self.isDone['gyro']:
            self.calibrateGyro()

        userInputLock.acquire()

        # Update Gyro offset
        self.calibrationTools.initGyroOffset(self.calibrator.initGXOffset,
                                             self.calibrator.initGYOffset,
                                             self.calibrator.initGZOffset)

        temp = 'Gyro calibrated' + \
               str(self.calibrator.initGXOffset) + ' ' + \
               str(self.calibrator.initGYOffset) + ' ' + \
               str(self.calibrator.initGZOffset)
        print temp
        UISpeaker.speak(temp)

        validInput = False
        while not validInput:
            # userInput = raw_input("Press enter to calibrate? y/n ")

            UISpeaker.speak(str("To begin compass calibration, press start. To skip calibration, press back."))
            userInput = keypad.get_binary_response()
            print userInput

            # Determine if normal calibration
            UISpeaker.speak(str("Is this normal calibration."))
            self.normalCalib = not keypad.get_binary_response()

            if not userInput:
                validInput = True
            else:
                dataFeeder.serialPort.flushInput()
                dataFeeder.serialPort.flushOutput()

                data = [deque() for x in range(NUM_QUEUED_ID)]
                data_single = [0 for x in range(NUM_SINGLE_ID)]
                data.extend(data_single)

                userInputLock.release()
                return

        for i in range(0, 3):
            num = 3 - i
            print num
            UISpeaker.speak(str(num))
            time.sleep(1)

        # print 'Calibrating'

        data = [deque() for x in range(NUM_QUEUED_ID)]
        data_single = [0 for x in range(NUM_SINGLE_ID)]
        data.extend(data_single)

        dataFeeder.serialPort.flushInput()
        dataFeeder.serialPort.flushOutput()
        userInputLock.release()

        print len(data[1])

        while not self.isDone['tilt']:
            self.calibrateTilt()

        # Update pitch and roll
        locationTracker.pedometer.calibrate(self.calibrator.pitch, self.calibrator.roll)
        locationTracker.gyroCompass.calibrate(self.calibrator.pitch, self.calibrator.roll)

        while not self.isDone['nOffset']:
            self.calibrateNOffset()

        locationTracker.compass.prevHeadingInRad = self.calibrator.NOffsetAngle

        if not self.normalCalib:
            locationTracker.updateCurrHeading(0.0 - self.ABNORMAL_NORTH_OFFSET)

        userInputLock.acquire()
        temp = 'Your are ' + str(int(self.calibrator.getNOffsetAngle() / (2 * math.pi) * 360)) + ' from N. To continue, press start'
        print temp
        UISpeaker.speak(temp)
        while keypad.get_binary_response():
           pass
        dataFeeder.serialPort.flushInput()
        dataFeeder.serialPort.flushOutput()

        data = [deque() for x in range(NUM_QUEUED_ID)]
        data_single = [0 for x in range(NUM_SINGLE_ID)]
        data.extend(data_single)

        userInputLock.release()

        print len(data[1])
Exemple #3
0
    def run(self):
        # magXrange = (-4328, 5605)
        # magYRange = (-5096, 5002)
        # magZRange = (-4618, 4655)
        # self.calibrator.inputManualRange(magZRange, magYRange, magXrange)
        userInputLock.acquire()

        global data, data_single

        validInput = False
        while not validInput:
            # userInput = raw_input("Press enter to calibrate? y/n ")

            # UISpeaker.speak(str("To calibrate gyroscope, press start."))
            userInput = raw_input("To calibrate gyroscope, press y.")
            if userInput == "y":
                validInput = True
                for i in range(0, 3):
                    num = 3 - i
                    print num
                    time.sleep(1)
                dataFeeder.serialPort.flushInput()
                dataFeeder.serialPort.flushOutput()

                data = [deque() for x in range(NUM_QUEUED_ID)]
                data_single = [0 for x in range(NUM_SINGLE_ID)]
                data.extend(data_single)

                userInputLock.release()

        print len(data[1])

        while not self.isDone["gyro"]:
            self.calibrateGyro()

        userInputLock.acquire()

        # Update Gyro offset
        self.calibrationTools.initGyroOffset(
            self.calibrator.initGXOffset, self.calibrator.initGYOffset, self.calibrator.initGZOffset
        )

        temp = (
            "Gyro calibrated"
            + str(self.calibrator.initGXOffset)
            + " "
            + str(self.calibrator.initGYOffset)
            + " "
            + str(self.calibrator.initGZOffset)
        )

        print temp

        validInput = False
        while not validInput:
            # userInput = raw_input("Press enter to calibrate? y/n ")

            userInput = raw_input("To begin compass calibration, press y")

            response = raw_input("Is this normal calibration. Press y")

            if response == "y":
                self.normalCalib = True
            else:
                self.normalCalib = False

            if userInput == "y":
                validInput = True
            elif userInput == "n":
                dataFeeder.serialPort.flushInput()
                dataFeeder.serialPort.flushOutput()

                data = [deque() for x in range(NUM_QUEUED_ID)]
                data_single = [0 for x in range(NUM_SINGLE_ID)]
                data.extend(data_single)

                userInputLock.release()
                return

        for i in range(0, 3):
            num = 3 - i
            print num
            # UISpeaker.speak(str(num))
            time.sleep(1)

        # print 'Calibrating'

        data = [deque() for x in range(NUM_QUEUED_ID)]
        data_single = [0 for x in range(NUM_SINGLE_ID)]
        data.extend(data_single)

        dataFeeder.serialPort.flushInput()
        dataFeeder.serialPort.flushOutput()
        userInputLock.release()

        print len(data[1])

        while not self.isDone["tilt"]:
            self.calibrateTilt()

        # Update pitch and roll
        locationTracker.pedometer.calibrate(self.calibrator.pitch, self.calibrator.roll)
        locationTracker.gyroCompass.calibrate(self.calibrator.pitch, self.calibrator.roll)

        while not self.isDone["nOffset"]:
            self.calibrateNOffset()

        locationTracker.compass.prevHeadingInRad = self.calibrator.NOffsetAngle

        if not self.normalCalib:
            locationTracker.updateCurrHeading(0.0 - self.ABNORMAL_NORTH_OFFSET)

        userInputLock.acquire()
        temp = (
            "Your are "
            + str(int(self.calibrator.getNOffsetAngle() / (2 * math.pi) * 360))
            + " from N. To continue, press start"
        )
        raw_input(temp)
        dataFeeder.serialPort.flushInput()
        dataFeeder.serialPort.flushOutput()

        data = [deque() for x in range(NUM_QUEUED_ID)]
        data_single = [0 for x in range(NUM_SINGLE_ID)]
        data.extend(data_single)

        userInputLock.release()

        print len(data[1])