Пример #1
0
    def test_config(self):
        with patch('osgar.drivers.logserial.serial.Serial') as mock:
            instance = mock.return_value
            instance.read = MagicMock(
                return_value=
                b'$GNGGA,182433.10,5007.71882,N,01422.50467,E,1,05,6.09,305.1,M,44.3,M,,*41'
            )

            config = {
                'modules': {
                    'gps': {
                        'driver': 'gps',
                        'out': ['position'],
                        'init': {}
                    },
                    'serial_gps': {
                        'driver': 'serial',
                        'out': ['raw'],
                        'init': {
                            'port': 'COM51',
                            'speed': 4800
                        }
                    }
                },
                'links': [('serial_gps.raw', 'gps.raw')]
            }
            logger = MagicMock(write=MagicMock(return_value=timedelta(
                seconds=135)))
            with Recorder(config=config, logger=logger) as recorder:
                self.assertEqual(len(recorder.modules), 2)
                self.assertEqual(
                    sum([
                        sum([len(q) for q in module.bus.out.values()])
                        for module in recorder.modules.values()
                    ]), 1)
Пример #2
0
    def test_config(self):
        with patch('osgar.drivers.logserial.serial.Serial') as mock:
            instance = mock.return_value
            instance.read = MagicMock(return_value=b'$GNGGA,182433.10,5007.71882,N,01422.50467,E,1,05,6.09,305.1,M,44.3,M,,*41')

            config = {
                    'modules': {
                        'gps': {
                            'driver': 'gps',
                            'out':['position'],
                            'init':{}
                        },
                        'serial_gps': {
                            'driver': 'serial',
                            'out':['raw'],
                            'init': {'port': 'COM51', 'speed': 4800}
                        }
                    },
                    'links': [('serial_gps.raw', 'gps.raw')]
            }
            logger = MagicMock()
            recorder = Recorder(config=config, logger=logger)
            self.assertEqual(len(recorder.modules), 2)
            self.assertEqual(sum([sum([len(q) for q in module.bus.out.values()])
                                  for module in recorder.modules.values()]), 1)
            recorder.start()
            time.sleep(0.1)
            recorder.update()
            recorder.finish()
Пример #3
0
    def test_spider_config(self):
        # first example with loop spider <-> serial
        with open(os.path.dirname(__file__) +
                  '/../config/test-spider.json') as f:
            config = json.loads(f.read())

        with patch('osgar.drivers.logserial.serial.Serial') as mock:
            logger = MagicMock()
            recorder = Recorder(config=config['robot'], logger=logger)
Пример #4
0
 def test_missing_init(self):
     # init section for modules is now optional
     mini_config = {
         'modules': {
             "dummy": {
                 "driver": "osgar.test_record:Sleeper"
             },
         },
         'links': []
     }
     with Recorder(config=mini_config, logger=MagicMock()) as recorder:
         pass
Пример #5
0
    def test_all_supported_config_files(self):
        supported = [
            'test-spider.json', 'test-gps-imu.json',
            'test-spider-gps-imu.json', 'test-windows-gps.json'
        ]

        with patch('osgar.drivers.logserial.serial.Serial') as mock:
            logger = MagicMock()
            for filename in supported:
                with open(
                        os.path.join(os.path.dirname(__file__), '..', 'config',
                                     filename)) as f:
                    config = json.loads(f.read())
                recorder = Recorder(config=config['robot'], logger=logger)
Пример #6
0
    def test_application(self):
        # plug-in external application
        with open(
                os.path.dirname(__file__) +
                '/../config/ro2018-spider-gps-imu.json') as f:
            config = json.loads(f.read())

        class DummyApp:
            def __init__(self, config, bus):
                self.bus = bus  # needed for linkage

        with patch('osgar.drivers.logserial.serial.Serial') as mock:
            logger = MagicMock()
            recorder = Recorder(config=config['robot'],
                                logger=logger,
                                application=DummyApp)
Пример #7
0
def main():
    import argparse
    from osgar.lib.config import load as config_load
    from osgar.record import Recorder
    from osgar.logger import LogWriter, LogReader

    parser = argparse.ArgumentParser(description='SubT Challenge')
    subparsers = parser.add_subparsers(help='sub-command help', dest='command')
    subparsers.required = True
    parser_run = subparsers.add_parser('run', help='run on real HW')
    parser_run.add_argument('config', nargs='+', help='configuration file')
    parser_run.add_argument('--note', help='add description')

    parser_replay = subparsers.add_parser('replay', help='replay from logfile')
    parser_replay.add_argument('logfile', help='recorded log file')
    parser_replay.add_argument('--force', '-F', dest='force', action='store_true', help='force replay even for failing output asserts')
    parser_replay.add_argument('--config', nargs='+', help='force alternative configuration file')
    args = parser.parse_args()

    if args.command == 'replay':
        from osgar.replay import replay
        args.module = 'app'
        game = replay(args, application=SubTChallenge)
        game.play()

    elif args.command == 'run':
        # To reduce latency spikes as described in https://morepypy.blogspot.com/2019/01/pypy-for-low-latency-systems.html.
        # Increased latency leads to uncontrolled behavior and robot either missing turns or hitting walls.
        # Disabled garbage collection needs to be paired with gc.collect() at place(s) that are not time sensitive.
        gc.disable()

        # support simultaneously multiple platforms
        prefix = os.path.basename(args.config[0]).split('.')[0] + '-'
        log = LogWriter(prefix=prefix, note=str(sys.argv))
        config = config_load(*args.config)
        log.write(0, bytes(str(config), 'ascii'))  # write configuration
        robot = Recorder(config=config['robot'], logger=log, application=SubTChallenge)
        game = robot.modules['app']  # TODO nicer reference
        robot.start()
        game.play()
        robot.finish()
Пример #8
0
 def test_dummy_usage(self):
     empty_config = {'modules': {}, 'links': []}
     with Recorder(config=empty_config, logger=MagicMock()) as recorder:
         pass
Пример #9
0
                               nargs='+',
                               help='force alternative configuration file')
    args = parser.parse_args()

    if args.command == 'replay':
        from osgar.replay import replay
        args.module = 'app'
        game = replay(args, application=SubTChallenge)
        game.play()

    elif args.command == 'run':
        # To reduce latency spikes as described in https://morepypy.blogspot.com/2019/01/pypy-for-low-latency-systems.html.
        # Increased latency leads to uncontrolled behavior and robot either missing turns or hitting walls.
        # Disabled garbage collection needs to be paired with gc.collect() at place(s) that are not time sensitive.
        gc.disable()

        # support simultaneously multiple platforms
        prefix = os.path.basename(args.config[0]).split('.')[0] + '-'
        log = LogWriter(prefix=prefix, note=str(sys.argv))
        config = config_load(*args.config)
        log.write(0, bytes(str(config), 'ascii'))  # write configuration
        robot = Recorder(config=config['robot'],
                         logger=log,
                         application=SubTChallenge)
        game = robot.modules['app']  # TODO nicer reference
        robot.start()
        game.play()
        robot.finish()

# vim: expandtab sw=4 ts=4
Пример #10
0
    subparsers.required = True
    parser_run = subparsers.add_parser('run', help='run on real HW')
    parser_run.add_argument('config', nargs='+', help='configuration file')
    parser_run.add_argument('--note', help='add description')

    parser_replay = subparsers.add_parser('replay', help='replay from logfile')
    parser_replay.add_argument('logfile', help='recorded log file')
    parser_replay.add_argument('--force', '-F', dest='force', action='store_true', help='force replay even for failing output asserts')
    parser_replay.add_argument('--config', nargs='+', help='force alternative configuration file')
    parser_replay.add_argument('--verbose', '-v', help="verbose mode", action='store_true')
    args = parser.parse_args()

    if args.command == 'replay':
        from replay import replay
        args.module = 'app'
        game = replay(args, application=SICKRobot2018)
        game.verbose = args.verbose
        game.play()

    elif args.command == 'run':
        log = LogWriter(prefix='eduro-', note=str(sys.argv))
        config = config_load(*args.config)
        log.write(0, bytes(str(config), 'ascii'))  # write configuration
        robot = Recorder(config=config['robot'], logger=log, application=SICKRobot2018)
        game = robot.modules['app']  # TODO nicer reference
        robot.start()
        game.play()
        robot.finish()

# vim: expandtab sw=4 ts=4
Пример #11
0
        '-F',
        dest='force',
        action='store_true',
        help='force replay even for failing output asserts')
    parser_replay.add_argument('--config',
                               nargs='+',
                               help='force alternative configuration file')
    args = parser.parse_args()

    if args.command == 'replay':
        from replay import replay
        args.module = 'app'
        game = replay(args, application=RoboOrienteering2018)
        game.play()

    elif args.command == 'run':
        log = LogWriter(prefix='ro2018-', note=str(sys.argv))
        config = config_load(*args.config)
        log.write(0, bytes(str(config), 'ascii'))  # write configuration
        recorder = Recorder(config=config['robot'],
                            logger=log,
                            application=RoboOrienteering2018)
        game = robot.modules['app']  # TODO nicer reference
        robot.start()
        game.play()
        recorder.finish()
    else:
        assert False, args.command  # unsupported command

# vim: expandtab sw=4 ts=4
Пример #12
0
 def test_dummy_usage(self):
     empty_config = {'modules': {}, 'links':[]}
     recorder = Recorder(config=empty_config, logger=None)
     recorder.start()
     recorder.update()
     recorder.finish()
Пример #13
0
 def test_dummy_usage(self):
     empty_config = {'modules': {}, 'links': []}
     recorder = Recorder(config=empty_config, logger=None)
     recorder.start()
     recorder.update()
     recorder.finish()