Esempio n. 1
0
    def on_start(self):
        print("Starting GPS Reader.")

        # set up gps reader
        self.gps_queue = Queue(1)
        self.root.gps_queue = self.gps_queue
        self.gps_reader = GpsReader(self.gps_queue, "gps_log.csv", test)
        self.gps_reader.start()
Esempio n. 2
0
class VisApp(App):
    def build(self):
        root = Root()
        Clock.schedule_interval(root.update, 1.0 / 20.0)

        return root

    def on_start(self):
        print("Starting GPS Reader.")

        # set up gps reader
        self.gps_queue = Queue(1)
        self.root.gps_queue = self.gps_queue
        self.gps_reader = GpsReader(self.gps_queue, "gps_log.csv", test)
        self.gps_reader.start()

        #self.obdii_queue = Queue(1)
        #self.root.obdii_queue = self.obdii_queue
        #self.obdii_reader = ObdiiReader(self.obdii_queue, "obdii_log.csv", test)
        #self.obdii_reader.start()

    def on_stop(self):
        self.gps_reader.shutdown()
Esempio n. 3
0
class TestGps(unittest.TestCase):
    def setUp(self):
        self.gps_reader = GpsReader()
        self.gps_reader.setDaemon(True)
        self.gps_reader.start()

    def tearDown(self):
        self.gps_reader.running = False
        self.gps_reader.join(0.1)

    def test_should_return_hasfix_false_and_NaN_for_values_if_gps_has_no_fix(
            self):
        self.assertEqual(self.gps_reader.hasfix, False)
        self.assertTrue(isNaN(self.gps_reader.position.latitude))
        self.assertTrue(isNaN(self.gps_reader.position.longitude))
        self.assertEqual(self.gps_reader.position.long_error, 0)
        self.assertEqual(self.gps_reader.position.lat_error, 0)
        self.assertTrue(isNaN(self.gps_reader.track))
        self.assertTrue(isNaN(self.gps_reader.speed))
        self.assertTrue(isNaN(self.gps_reader.time))
        self.assertTrue(isNaN(self.gps_reader.speed_error))
        self.assertTrue(isNaN(self.gps_reader.track_error))

    def test_should_return_values_except_track_error_if_gps_has_fix(self):
        tries = 0
        while (not (self.gps_reader.hasfix) and tries < 100):
            tries = tries + 1
            time.sleep(0.1)
        self.assertLess(tries, 100, "GPS failed to get fix within 10 seconds")
        self.assertEqual(self.gps_reader.hasfix, True)
        self.assertIsInstance(self.gps_reader.position, Position)
        self.assertGreater(self.gps_reader.position.latitude, 0)
        self.assertLess(self.gps_reader.position.longitude, 0)
        self.assertGreater(self.gps_reader.position.long_error, 0)
        self.assertGreater(self.gps_reader.position.lat_error, 0)
        self.assertGreater(self.gps_reader.track, 0)
        self.assertGreater(self.gps_reader.speed, 0)
        self.assertGreater(self.gps_reader.time, 0)
        self.assertGreater(self.gps_reader.speed_error, 0)
Esempio n. 4
0
class TestGps(unittest.TestCase):
    def setUp(self):
        self.gps_reader = GpsReader()
        self.gps_reader.setDaemon(True)
        self.gps_reader.start()

    def tearDown(self):
        self.gps_reader.running = False
        self.gps_reader.join(0.1)

    def test_should_return_hasfix_false_and_NaN_for_values_if_gps_has_no_fix(self):
        self.assertEqual(self.gps_reader.hasfix, False)
        self.assertTrue(isNaN(self.gps_reader.position.latitude))
        self.assertTrue(isNaN(self.gps_reader.position.longitude))
        self.assertEqual(self.gps_reader.position.long_error, 0)
        self.assertEqual(self.gps_reader.position.lat_error, 0)
        self.assertTrue(isNaN(self.gps_reader.track))
        self.assertTrue(isNaN(self.gps_reader.speed))
        self.assertTrue(isNaN(self.gps_reader.time))
        self.assertTrue(isNaN(self.gps_reader.speed_error))
        self.assertTrue(isNaN(self.gps_reader.track_error))

    def test_should_return_values_except_track_error_if_gps_has_fix(self):
        tries = 0
        while not (self.gps_reader.hasfix) and tries < 100:
            tries = tries + 1
            time.sleep(0.1)
        self.assertLess(tries, 100, "GPS failed to get fix within 10 seconds")
        self.assertEqual(self.gps_reader.hasfix, True)
        self.assertIsInstance(self.gps_reader.position, Position)
        self.assertGreater(self.gps_reader.position.latitude, 0)
        self.assertLess(self.gps_reader.position.longitude, 0)
        self.assertGreater(self.gps_reader.position.long_error, 0)
        self.assertGreater(self.gps_reader.position.lat_error, 0)
        self.assertGreater(self.gps_reader.track, 0)
        self.assertGreater(self.gps_reader.speed, 0)
        self.assertGreater(self.gps_reader.time, 0)
        self.assertGreater(self.gps_reader.speed_error, 0)
Esempio n. 5
0
 def setUp(self):
     self.gps_reader = GpsReader()
     self.gps_reader.setDaemon(True)
     self.gps_reader.start()
Esempio n. 6
0
class Wiring():
    def __init__(self, gps=False, servo_port=SERVO_PORT):
        # devices
        self._gps = gps
        self.windsensor = WindSensor(I2C(WINDSENSOR_I2C_ADDRESS))
        self.compass = Compass(I2C(COMPASS_I2C_ADDRESS),
                               I2C(ACCELEROMETER_I2C_ADDRESS))
        self.red_led = GpioWriter(17, os)
        self.green_led = GpioWriter(18, os)

        # Navigation
        self.globe = Globe()
        self.timer = Timer()
        self.application_logger = self._rotating_logger(APPLICATION_NAME)
        self.position_logger = self._rotating_logger("position")
        self.exchange = Exchange(self.application_logger)
        self.timeshift = TimeShift(self.exchange, self.timer.time)
        self.event_source = EventSource(self.exchange, self.timer,
                                        self.application_logger,
                                        CONFIG['event source'])

        self.sensors = Sensors(self.gps, self.windsensor, self.compass,
                               self.timer.time, self.exchange,
                               self.position_logger, CONFIG['sensors'])
        self.gps_console_writer = GpsConsoleWriter(self.gps)
        self.rudder_servo = Servo(serial.Serial(servo_port),
                                  RUDDER_SERVO_CHANNEL, RUDDER_MIN_PULSE,
                                  RUDDER_MIN_ANGLE, RUDDER_MAX_PULSE,
                                  RUDDER_MAX_ANGLE)
        self.steerer = Steerer(self.rudder_servo, self.application_logger,
                               CONFIG['steerer'])
        self.helm = Helm(self.exchange, self.sensors, self.steerer,
                         self.application_logger, CONFIG['helm'])
        self.course_steerer = CourseSteerer(self.sensors, self.helm,
                                            self.timer,
                                            CONFIG['course steerer'])
        self.navigator = Navigator(self.sensors, self.globe, self.exchange,
                                   self.application_logger,
                                   CONFIG['navigator'])
        self.self_test = SelfTest(self.red_led, self.green_led, self.timer,
                                  self.rudder_servo, RUDDER_MIN_ANGLE,
                                  RUDDER_MAX_ANGLE)

        # Tracking
        self.tracking_logger = self._rotating_logger("track")
        self.tracking_sensors = Sensors(self.gps, self.windsensor,
                                        self.compass, self.timer.time,
                                        self.exchange, self.tracking_logger,
                                        CONFIG['sensors'])
        self.tracker = Tracker(self.tracking_logger, self.tracking_sensors,
                               self.timer)

    def _rotating_logger(self, appname):
        logHandler = TimedRotatingFileHandler("/var/log/pi-nav/" + appname,
                                              when="midnight",
                                              backupCount=30)
        logHandler.setFormatter(logging.Formatter(LOGGING_FORMAT))
        logger = logging.getLogger(appname)
        logger.addHandler(logHandler)
        logger.setLevel(CONFIG['wiring']['logging level'])
        return logger

    @property
    def gps(self):
        if not self._gps:
            self._gps = GpsReader()
            self._gps.setDaemon(True)
            self._gps.start()
        return self._gps

    def showgps(self):
        try:
            self.timer.call(self.gps_console_writer.write).every(5)
        except (KeyboardInterrupt, SystemExit):
            self.gps.running = False
            self.gps.join()

    def follow(self, waypoints):
        self.application_logger.info(
            '**************************************************************')
        self.application_logger.info(
            '*** Pi-Nav starting navigation: ' +
            datetime.datetime.now().strftime("%Y-%m-%d"))
        self.application_logger.info(
            '**************************************************************')
        self.self_test.run()
        self.rudder_servo.set_position(0)
        self.follower = Follower(self.exchange, waypoints,
                                 self.application_logger)
        self.event_source.start()

    def track(self):
        self.self_test.run()
        self.tracker.track(10)
Esempio n. 7
0
 def gps(self):
     if not self._gps:
         self._gps = GpsReader()
         self._gps.setDaemon(True)
         self._gps.start()
     return self._gps
Esempio n. 8
0
 def gps(self):
     if not self._gps:
         self._gps = GpsReader()
         self._gps.setDaemon(True)
         self._gps.start()
     return self._gps
Esempio n. 9
0
class Wiring():
    def __init__(self,gps=False,servo_port=SERVO_PORT):
        # devices
        self._gps = gps
        self.windsensor = WindSensor(I2C(WINDSENSOR_I2C_ADDRESS))
        self.compass = Compass(I2C(COMPASS_I2C_ADDRESS),I2C(ACCELEROMETER_I2C_ADDRESS))
        self.red_led = GpioWriter(17,os)
        self.green_led = GpioWriter(18,os)

        # Navigation
        self.globe = Globe()
        self.timer = Timer()
        self.application_logger = self._rotating_logger(APPLICATION_NAME)
        self.position_logger = self._rotating_logger("position")
        self.exchange = Exchange(self.application_logger)
        self.timeshift = TimeShift(self.exchange,self.timer.time)
        self.event_source = EventSource(self.exchange,self.timer,self.application_logger,CONFIG['event source'])

        self.sensors = Sensors(self.gps,self.windsensor,self.compass,self.timer.time,self.exchange,self.position_logger,CONFIG['sensors'])
        self.gps_console_writer = GpsConsoleWriter(self.gps)
        self.rudder_servo = Servo(serial.Serial(servo_port),RUDDER_SERVO_CHANNEL,RUDDER_MIN_PULSE,RUDDER_MIN_ANGLE,RUDDER_MAX_PULSE,RUDDER_MAX_ANGLE)
        self.steerer = Steerer(self.rudder_servo,self.application_logger,CONFIG['steerer'])
        self.helm = Helm(self.exchange,self.sensors,self.steerer,self.application_logger,CONFIG['helm'])
        self.course_steerer = CourseSteerer(self.sensors,self.helm,self.timer,CONFIG['course steerer'])
        self.navigator = Navigator(self.sensors,self.globe,self.exchange,self.application_logger,CONFIG['navigator'])
        self.self_test = SelfTest(self.red_led,self.green_led,self.timer,self.rudder_servo,RUDDER_MIN_ANGLE,RUDDER_MAX_ANGLE)

        # Tracking
        self.tracking_logger = self._rotating_logger("track")
        self.tracking_sensors = Sensors(self.gps,self.windsensor,self.compass,self.timer.time,self.exchange,self.tracking_logger,CONFIG['sensors'])
        self.tracker = Tracker(self.tracking_logger,self.tracking_sensors,self.timer)

    def _rotating_logger(self,appname):
        logHandler = TimedRotatingFileHandler("/var/log/pi-nav/" + appname,when="midnight",backupCount=30)
        logHandler.setFormatter(logging.Formatter(LOGGING_FORMAT))
        logger = logging.getLogger(appname)
        logger.addHandler( logHandler )
        logger.setLevel( CONFIG['wiring']['logging level'])
        return logger

    @property
    def gps(self):
        if not self._gps:
            self._gps = GpsReader()
            self._gps.setDaemon(True)
            self._gps.start()
        return self._gps

    def showgps(self):
        try:
            self.timer.call(self.gps_console_writer.write).every(5)
        except (KeyboardInterrupt, SystemExit):
            self.gps.running = False
            self.gps.join()

    def follow(self,waypoints):
        self.application_logger.info('**************************************************************')
        self.application_logger.info('*** Pi-Nav starting navigation: ' + datetime.datetime.now().strftime("%Y-%m-%d"))
        self.application_logger.info('**************************************************************')
        self.self_test.run()
        self.rudder_servo.set_position(0)
        self.follower = Follower(self.exchange,waypoints,self.application_logger)
        self.event_source.start()

    def track(self):
        self.self_test.run()
        self.tracker.track(10)
Esempio n. 10
0
 def setUp(self):
     self.gps_reader = GpsReader()
     self.gps_reader.setDaemon(True)
     self.gps_reader.start()