Example #1
0
class GPS(Sensor):
    def __init__(self, sensor_id):
        super().__init__(sensor_id, 'i16', 'f', 'i16', 'f', 'f', 'f', 'f')

        self.gps_ref = MicropyGPS()

    def update(self, character):
        self.gps_ref.update(character)

    def update_data(self):
        self.data = \
            (self.gps_ref.latitude[0],
             self.gps_ref.latitude[1],
             self.gps_ref.longitude[0],
             self.gps_ref.longitude[1],

             self.gps_ref.speed[2],
             self.gps_ref.hdop,
             self.gps_ref.course)
Example #2
0
    def __init__(self, sensor_id, uart_bus, int_pin, timer_num):
        assert not (int_pin == timer_num == None)
        super().__init__(sensor_id, ['f', 'f', 'f', 'u8'])

        self.gps_ref = MicropyGPS()

        self.prev_lat = None
        self.prev_long = None
        self.lat = 0.0
        self.long = 0.0
        self.altitude = 0.0

        GPS.uart = pyb.UART(uart_bus, 9600, read_buf_len=1000)

        # using class variables because lists can't be created in callbacks
        # MicropyGPS creates a list in one of its functions
        GPS.pps_pin = int_pin
        GPS.ext_pin = pyb.ExtInt(GPS.pps_pin, pyb.ExtInt.IRQ_FALLING,
                                 pyb.Pin.PULL_UP, GPS.pps_callback)
        self.timer = pyb.Timer(timer_num, freq=1)
        self.timer.callback(lambda t: GPS.timer_callback(t))
Example #3
0
    def __init__(self, sensor_id, uart_bus, int_pin, timer_num):
        assert not (int_pin == timer_num == None)
        super().__init__(sensor_id, ['f', 'f', 'f', 'u8'])

        self.gps_ref = MicropyGPS()

        self.prev_lat = None
        self.prev_long = None
        self.lat = 0.0
        self.long = 0.0
        self.altitude = 0.0

        GPS.uart = pyb.UART(uart_bus, 9600, read_buf_len=1000)

        # using class variables because lists can't be created in callbacks
        # MicropyGPS creates a list in one of its functions
        GPS.pps_pin = int_pin
        GPS.ext_pin = pyb.ExtInt(GPS.pps_pin, pyb.ExtInt.IRQ_FALLING,
                                 pyb.Pin.PULL_UP, GPS.pps_callback)
        self.timer = pyb.Timer(timer_num, freq=1)
        self.timer.callback(lambda t: GPS.timer_callback(t))
Example #4
0
class GPS(Sensor):
    gps_indicator = pyb.LED(3)
    new_data = False
    uart = None
    pps_pin = None
    pps_timer = 0
    extint = None

    def __init__(self, sensor_id, uart_bus, int_pin, timer_num):
        assert not (int_pin == timer_num == None)
        super().__init__(sensor_id, ['f', 'f', 'f', 'u8'])

        self.gps_ref = MicropyGPS()

        self.prev_lat = None
        self.prev_long = None
        self.lat = 0.0
        self.long = 0.0
        self.altitude = 0.0

        GPS.uart = pyb.UART(uart_bus, 9600, read_buf_len=1000)

        # using class variables because lists can't be created in callbacks
        # MicropyGPS creates a list in one of its functions
        GPS.pps_pin = int_pin
        GPS.ext_pin = pyb.ExtInt(GPS.pps_pin, pyb.ExtInt.IRQ_FALLING,
                                 pyb.Pin.PULL_UP, GPS.pps_callback)
        self.timer = pyb.Timer(timer_num, freq=1)
        self.timer.callback(lambda t: GPS.timer_callback(t))

    def update_gps(self, character):
        self.gps_ref.update(character)

        def heading(self):
            if self.prev_lat is None and self.prev_long is None:
                self.prev_lat = self.lat
                self.prev_long = self.long
                return 0.0
            else:
                angle = math.atan2(self.long - self.prev_long,
                                   self.lat - self.prev_lat)
                self.prev_long = self.long
                self.prev_lat = self.lat
                return angle

    def update_data(self):
        self.lat = self.gps_ref.latitude[0] + self.gps_ref.latitude[1] / 60
        self.long = self.gps_ref.longitude[0] + self.gps_ref.longitude[1] / 60
        return (
            self.lat,
            -self.long,
            ##            self.gps_ref.geoid_height,
            self.gps_ref.altitude,
            self.gps_ref.satellites_in_view)

    def recved_data(self):
        GPS.pps_timer += 1
        if GPS.new_data and GPS.pps_timer < 500:
            while GPS.uart.any():
                self.update_gps(chr(GPS.uart.readchar()))
            GPS.new_data = False
            return True
        else:
            return False

    @staticmethod
    def timer_callback(line):
        if GPS.uart.any():
            GPS.new_data = True
            GPS.gps_indicator.toggle()

    @staticmethod
    def pps_callback(line):
        GPS.pps_timer = 0
Example #5
0
    def __init__(self, sensor_id):
        super().__init__(sensor_id, 'i16', 'f', 'i16', 'f', 'f', 'f', 'f')

        self.gps_ref = MicropyGPS()
Example #6
0
class GPS(Sensor):
    gps_indicator = pyb.LED(3)
    new_data = False
    uart = None
    pps_pin = None
    pps_timer = 0
    extint = None

    def __init__(self, sensor_id, uart_bus, int_pin, timer_num):
        assert not (int_pin == timer_num == None)
        super().__init__(sensor_id, ['f', 'f', 'f', 'u8'])

        self.gps_ref = MicropyGPS()

        self.prev_lat = None
        self.prev_long = None
        self.lat = 0.0
        self.long = 0.0
        self.altitude = 0.0

        GPS.uart = pyb.UART(uart_bus, 9600, read_buf_len=1000)

        # using class variables because lists can't be created in callbacks
        # MicropyGPS creates a list in one of its functions
        GPS.pps_pin = int_pin
        GPS.ext_pin = pyb.ExtInt(GPS.pps_pin, pyb.ExtInt.IRQ_FALLING,
                                 pyb.Pin.PULL_UP, GPS.pps_callback)
        self.timer = pyb.Timer(timer_num, freq=1)
        self.timer.callback(lambda t: GPS.timer_callback(t))

    def update_gps(self, character):
        self.gps_ref.update(character)

        def heading(self):
            if self.prev_lat is None and self.prev_long is None:
                self.prev_lat = self.lat
                self.prev_long = self.long
                return 0.0
            else:
                angle = math.atan2(self.long - self.prev_long,
                                   self.lat - self.prev_lat)
                self.prev_long = self.long
                self.prev_lat = self.lat
                return angle

    def update_data(self):
        self.lat = self.gps_ref.latitude[0] + self.gps_ref.latitude[1] / 60
        self.long = self.gps_ref.longitude[0] + self.gps_ref.longitude[1] / 60
        return (
            self.lat,
            -self.long,
            ##            self.gps_ref.geoid_height,
            self.gps_ref.altitude,
            self.gps_ref.satellites_in_view
        )

    def recved_data(self):
        GPS.pps_timer += 1
        if GPS.new_data and GPS.pps_timer < 500:
            while GPS.uart.any():
                self.update_gps(chr(GPS.uart.readchar()))
            GPS.new_data = False
            return True
        else:
            return False

    @staticmethod
    def timer_callback(line):
        if GPS.uart.any():
            GPS.new_data = True
            GPS.gps_indicator.toggle()

    @staticmethod
    def pps_callback(line):
        GPS.pps_timer = 0