예제 #1
0
def main():
    controller = Controller()

    kwargs = {"num_workers": 1, "pin_memory": True} if FLAGS.CUDA else {}
    train_loader = DataLoader(
        datasets.Omniglot(
            "data",
            train=True,
            download=True,
            transform=transforms.Compose([
                transforms.ToTensor(),
                # transforms.Normalize(mean, std) should add for better performance, + other transforms
            ])),
        batch_sizer=FLAGS.BATCH_SIZE,
        shuffle=True,
        **kwargs)

    test_loader = DataLoader(
        datasets.Omniglot(
            "data",
            train=False,
            transform=transforms.Compose([
                transforms.ToTensor(),
                # transforms.Normalize(mean, std) should add for better performance, + other transforms
            ])),
        batch_sizer=FLAGS.BATCH_SIZE,
        shuffle=True,
        **kwargs)

    if FLAGS.TRAIN:
        train(controller, train_loader)
    else:
        test(controller, test_loader)
예제 #2
0
async def start(websocket, path):
    ctrl = Controller()
    setup = Setup()

    p_rate = CONF.GUI['web_socket_pulse_rate']
    w_rate = CONF.GUI['web_socket_wait_rate']

    SCRfield = setup.field()
    SCRenv = setup.env(SCRfield=SCRfield, roll='WS')

    GUIraw = copy(CONF.GUI['GUIraw'])
    SCRenv['log'].output(lv='INFO', log='new conection.')

    try:
        while True:
            time.sleep(p_rate)
            send_json, GUIraw = ctrl.websocket_chaser(SCRfield=SCRfield,
                                                      GUIenv=SCRenv,
                                                      GUIraw=GUIraw)
            if (len(send_json.keys()) == 0):
                time.sleep(w_rate)
                await websocket.send('check')
            else:
                await websocket.send(json.dumps(send_json))
    except websockets.exceptions.ConnectionClosedError:
        SCRenv['log'].output(lv='INFO', log='close conection.')
        GUIraw = {}
예제 #3
0
    def __init__(self):
        self.script_path = os.path.dirname(os.path.realpath(__file__))

        self.arguments = ArgumentParser(self.script_path)

        if self.arguments.quiet:
            self.output = PrintOutput(self.arguments.color)
        else:
            self.output = CLIOutput(self.arguments.color)

        self.controller = Controller(self.script_path, self.arguments,
                                     self.output)
예제 #4
0
def main():
    '''
    需要安装'crawlergo','dirsearch','oneforall','xray_linux_amd64'到tools目录
    定义是自动下载,但是由于github问题可能经常会出错;出错的话手动下载解压最好;
    具体链接在download_tools.py里有
    '''
    if not os.path.exists(os.path.join(TOOLS_DIR, 'install.lock')):
        print('tools not exists; downloading ...')
        time.sleep(3)
        from lib.download_tools import download
        download()

    arguments = ArgumentParser()
    controller = Controller(arguments)
    controller.assign_task()
예제 #5
0
def main():
    try:

        _loader = ConfigLoader(Level.INFO)
        filename = 'config.yaml'
        _config = _loader.configure(filename)
        _queue = MessageQueue(Level.INFO)

        _ifs = IntegratedFrontSensor(_config, _queue, Level.INFO)
        _motors = Motors(_config, None, None, Level.INFO)

        # configure Controller and Arbitrator
        _controller = Controller(_config, _ifs, _motors, _callback_shutdown,
                                 Level.INFO)
        _arbitrator = Arbitrator(_config, _queue, _controller, Level.WARN)

        print(Fore.RED + 'roam...' + Style.RESET_ALL)
        _ifs.enable()
        _arbitrator.start()
        #       _controller.enable()
        _roam = RoamBehaviour(_motors, Level.INFO)
        _roam.roam()
        while _roam.is_roaming():
            print(Fore.BLACK + Style.DIM + '(roaming)' + Style.RESET_ALL)
            time.sleep(1.0)

        print(Fore.YELLOW + 'complete: closing...' + Style.RESET_ALL)
        _motors.close()
        print(Fore.YELLOW + 'closed.' + Style.RESET_ALL)
        sys.exit(0)

    except KeyboardInterrupt:
        print('test complete')
        sys.exit(0)
    except Exception as e:
        print(Fore.RED + Style.BRIGHT +
              'error in PID controller: {}'.format(e))
        traceback.print_exc(file=sys.stdout)
        sys.exit(1)
예제 #6
0
def main():
    app = Flask(__name__)
    controller = Controller(config.controller['leds'],
                            config.controller['neopixel_gpio_pin'],
                            config.controller['neopixel_frequency'],
                            config.controller['neopixel_dma'],
                            config.controller['neopixel_invert'],
                            config.controller['neopixel_brightness'],
                            config.controller['neopixel_channel'],
                            config.controller['neopixel_strip'])
    db = TinyDB('data/database.json')
    query = Query()

    app.config['SECRET_KEY'] = os.urandom(24)

    CSRFProtect(app)

    main.color = Color(0, 0, 0)
    main.brightness = 255
    main.state = False
    main.effects = []

    @app.before_first_request
    def init():
        if db.search(query.color != ''):
            result = db.get(query.color != '')['color'].split(',')
            main.color = Color(int(result[0]), int(result[1]), int(result[2]))

        if db.search(query.brightness != ''):
            result = db.get(query.brightness != '')
            main.brightness = result['brightness']

        if db.search(query.state != ''):
            result = db.get(query.state != '')
            main.state = bool(result['state'])

        if main.state:
            controller.color(main.color)
            controller.brightness(main.brightness)

        main.effects = controller.effects()

    @app.route('/', methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            data = request.form

            main.color = Color(int(data['red']), int(data['green']),
                               int(data['blue']))
            main.brightness = int(data['brightness'])

            controller.brightness(main.brightness)

            if data['submit'] == 'apply':
                main.state = True
                controller.clear()
                controller.color(main.color)
                controller.brightness(main.brightness)

            elif data['submit'] == 'effect':
                main.state = True
                controller.clear()
                controller.brightness(main.brightness)

                if data['effect'] in main.effects:
                    controller.start_effect(
                        data['effect'],
                        Color(int(data['red']), int(data['green']),
                              int(data['blue'])))
            elif data['submit'] == 'off':
                main.state = False
                controller.clear()

            if main.state:
                db.update({'color': main.color.__str__()}, query.color != '')
                db.update({'brightness': main.brightness},
                          query.brightness != '')

            db.update({'state': main.state}, query.state != '')

            return redirect(url_for('index'))

        return render_template('index.html',
                               effects=main.effects,
                               color=main.color,
                               brightness=main.brightness)

    @app.route('/api/v1.0/state/<string:state>', methods=['GET'])
    def state(state):
        if not state:
            abort(400)

        main.state = True if state == 'true' else False
        db.update({'state': main.state}, query.state != '')
        controller.clear()

        if main.state:
            controller.color(main.color)
            controller.brightness(main.brightness)

        return jsonify({'state': main.state}), 201

    @app.route('/api/v1.0/color/<int:red>/<int:green>/<int:blue>',
               methods=['GET'])
    def color(red, green, blue):
        if not red or not green or not blue:
            abort(400)

        main.state = True
        main.color = Color(int(red), int(green), int(blue))
        controller.color(main.color)
        db.update({'color': main.color.__str__()}, query.color != '')

        return jsonify({'color': main.color.__str__()}), 201

    @app.route('/api/v1.0/brightness/<int:brightness>', methods=['GET'])
    def brightness(brightness):
        if not brightness:
            abort(400)

        main.state = True
        main.brightness = int(brightness)
        controller.brightness(main.brightness)
        db.update({'brightness': main.brightness}, query.brightness != '')

        return jsonify({'brightness': main.brightness}), 201

    app.run(host='0.0.0.0', port=5000)
    db.close()
    atexit.register(controller.__exit__)
예제 #7
0
def api_rest(env):
    g_c = Controller()
    json = g_c.get_json(path=env['PATH_INFO'])
    headers = [('Content-Type', 'text/json; charset=utf-8')]
    return '200 OK', headers, [bytes(json, encoding='utf-8')]
예제 #8
0
def main():
    """
    Prepara las ventanas, define modelos, controlador y vista y corre el programa.
    :return: void
    """

    # Se obtiene el checksum del juego
    checksum = [
        path_checksum('lib', VERBOSE),
        '8e1fd1c03d2bfe89d7dbdab8b0c4c69a'.upper(),
        path_checksum('bin', VERBOSE)
    ]

    # Se cargan las configuraciones
    control_config = Configloader(DIR_CONFIG + 'control.ini', verbose=VERBOSE)
    game_config = Configloader(DIR_CONFIG + 'game.ini', verbose=VERBOSE)
    map_config = Configloader(DIR_CONFIG + 'map.ini', verbose=VERBOSE)
    score_config = Configloader(DIR_CONFIG + 'scoreboard.ini', verbose=VERBOSE)
    user_config = Configloader(DIR_CONFIG + 'user.ini', verbose=VERBOSE)
    view_config = Configloader(DIR_CONFIG + 'view.ini', verbose=VERBOSE)
    window_config = Configloader(DIR_CONFIG + 'window.ini', verbose=VERBOSE)
    world_config = Configloader(DIR_CONFIG + 'world.ini', verbose=VERBOSE)

    # Se carga el idioma
    lang = langs.Langloader(game_config.getValue('LANG'))

    # Se carga la información de la pantalla del cliente
    display_info = pygame.display.Info()

    # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo
    if not username.validate(user_config.getValue('NAME')):
        new_name = username.request(lang.get(111), lang.get(112))
        if new_name is not username.NO_VALID_NAME:
            user_config.setParameter('NAME', new_name)
            user_config.export()
        else:
            utils.destroy_process()

    # Creación de ventana
    window = Window(window_config, lang.get(10),
                    pygame.image.load(getIcons('icon')), display_info)
    clock = pygame.time.Clock()  # Reloj
    fps = int(game_config.getValue('FPS'))  # FPS a dibujar

    # Se crea el mundo
    world = World(world_config,
                  map_config,
                  window,
                  checksum,
                  score_config,
                  user_config,
                  lang,
                  game_config,
                  verbose=VERBOSE)
    # world.load_map(1)

    # Se crean los menús de inicio y pause
    menus = Createuimenu(lang, window, world, game_config, user_config,
                         view_config, window_config, world_config, map_config)

    # Se crea la vista
    vista = View(window, clock, world, lang, view_config, menus)
    menus.addView(vista)

    # Se crea el controlador
    control = Controller(world,
                         clock,
                         lang,
                         control_config,
                         window,
                         menus,
                         verbose=VERBOSE)
    menus.addController(control)
    vista.add_controller(control)

    # Se lanza el mainloop
    while True:
        clock.tick(fps)
        vista.draw(control.event_loop())
예제 #9
0
    def configure(self, arguments):
        '''
        Provided with a set of configuration arguments, configures ROS based on
        both KD01/KR01 standard hardware as well as optional features, the 
        latter based on devices showing up (by address) on the I²C bus. Optional
        devices are only enabled at startup time via registration of their feature
        availability.
        '''
        self._log.heading('configuration', 'configuring ros...',
                          '[1/2]' if arguments.start else '[1/1]')
        self._log.info('application log level: {}'.format(
            self._log.level.name))
        # configuration from command line arguments
        self._using_mocks = False
        self._permit_mocks = arguments.mock
        self._enable_camera = arguments.camera  # TODO
        # read YAML configuration
        _loader = ConfigLoader(self._log.level)
        _config_file = arguments.config_file if arguments.config_file is not None else 'config.yaml'
        self._config = _loader.configure(_config_file)
        # scan I2C bus
        self._log.info('scanning I²C address bus...')
        scanner = I2CScanner(self._log.level)
        self._addresses = scanner.get_int_addresses()
        _hex_addresses = scanner.get_hex_addresses()
        self._addrDict = dict(
            list(map(lambda x, y: (x, y), self._addresses, _hex_addresses)))
        #       for i in range(len(self._addresses)):
        for _address in self._addresses:
            _device_name = self.get_device_for_address(_address)
            self._log.info('found device at I²C address 0x{:02X}: {}'.format(
                _address, _device_name) + Style.RESET_ALL)
            # TODO look up address and make assumption about what the device is
        # establish basic subsumption components
        self._log.info('configure application messaging...')
        self._message_factory = MessageFactory(self._log.level)
        self._message_bus = MessageBus(self._log.level)
        self._log.info('configuring system clock...')
        self._clock = Clock(self._config, self._message_bus,
                            self._message_factory, Level.WARN)
        self.add_feature(self._clock)

        # standard devices ...........................................
        self._log.info('configure default features...')

        self._log.info('configure CPU temperature check...')
        _temperature_check = Temperature(self._config, self._clock,
                                         self._log.level)
        if _temperature_check.get_cpu_temperature() > 0:
            self.add_feature(_temperature_check)
        else:
            self._log.warning('no support for CPU temperature.')

        motors_enabled = not arguments.no_motors and (0x15 in self._addresses)
        if motors_enabled:  # then configure motors
            self._log.debug(Fore.CYAN + Style.BRIGHT +
                            '-- ThunderBorg available at 0x15' +
                            Style.RESET_ALL)
            _motor_configurer = MotorConfigurer(self._config, self._clock,
                                                self._log.level)
            self._motors = _motor_configurer.get_motors()
            self.add_feature(self._motors)
            self._set_feature_available('motors', motors_enabled)
        elif self._permit_mocks:
            self._using_mocks = True
            self._log.debug(Fore.RED + Style.BRIGHT +
                            '-- no ThunderBorg available, using mocks.' +
                            Style.RESET_ALL)
            from mock.motor_configurer import MockMotorConfigurer
            _motor_configurer = MockMotorConfigurer(self._config, self._clock,
                                                    self._log.level)
            self._motors = _motor_configurer.get_motors()
            self.add_feature(self._motors)
            self._set_feature_available('motors', motors_enabled)

        ifs_available = (0x0E in self._addresses)
        if ifs_available:
            self._log.info('configuring integrated front sensor...')
            self._ifs = IntegratedFrontSensor(self._config, self._clock,
                                              self._log.level)
            self.add_feature(self._ifs)
        elif self._permit_mocks:
            self._using_mocks = True
            self._log.info(
                'integrated front sensor not available; loading mock sensor.')
            from mock.ifs import MockIntegratedFrontSensor
            self._ifs = MockIntegratedFrontSensor(self._message_bus,
                                                  exit_on_complete=False,
                                                  level=self._log.level)
            self._message_bus.set_ifs(self._ifs)
            self.add_feature(self._ifs)
        else:
            self._ifs = None
            self._log.warning('no integrated front sensor available.')

#       ultraborg_available = ( 0x36 in self._addresses )
#       if ultraborg_available:
#           self._log.debug(Fore.CYAN + Style.BRIGHT + '-- UltraBorg available at 0x36.' + Style.RESET_ALL)
#       else:
#           self._log.debug(Fore.RED + Style.BRIGHT + '-- no UltraBorg available at 0x36.' + Style.RESET_ALL)
#       self._set_feature_available('ultraborg', ultraborg_available)

#       # optional devices ...........................................
        self._log.info('configure optional features...')
        self._gamepad_enabled = arguments.gamepad and self._config['ros'].get(
            'gamepad').get('enabled')

        #       # the 5x5 RGB Matrix is at 0x74 for port, 0x77 for starboard
        #       rgbmatrix5x5_stbd_available = ( 0x74 in self._addresses )
        #       if rgbmatrix5x5_stbd_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + '-- RGB Matrix available at 0x74.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + '-- no RGB Matrix available at 0x74.' + Style.RESET_ALL)
        #       self._set_feature_available('rgbmatrix5x5_stbd', rgbmatrix5x5_stbd_available)
        #       rgbmatrix5x5_port_available = ( 0x77 in self._addresses )
        #       if rgbmatrix5x5_port_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + '-- RGB Matrix available at 0x77.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + '-- no RGB Matrix available at 0x77.' + Style.RESET_ALL)
        #       self._set_feature_available('rgbmatrix5x5_port', rgbmatrix5x5_port_available)

        #       if rgbmatrix5x5_stbd_available or rgbmatrix5x5_port_available:
        #           self._log.info('configure rgbmatrix...')
        #           self._rgbmatrix = RgbMatrix(Level.INFO)
        #           self.add_feature(self._rgbmatrix) # FIXME this is added twice

        #       # ............................................
        #       # the 11x7 LED matrix is at 0x75 for starboard, 0x77 for port. The latter
        #       # conflicts with the RGB LED matrix, so both cannot be used simultaneously.
        #       matrix11x7_stbd_available = ( 0x75 in self._addresses )
        #       if matrix11x7_stbd_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + '-- 11x7 Matrix LEDs available at 0x75.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + '-- no 11x7 Matrix LEDs available at 0x75.' + Style.RESET_ALL)
        #       self._set_feature_available('matrix11x7_stbd', matrix11x7_stbd_available)

        #       # device availability ........................................

        #       bno055_available = ( 0x28 in self._addresses )
        #       if bno055_available:
        #           self._log.info('configuring BNO055 9DoF sensor...')
        #           self._bno055 = BNO055(self._config, self.get_message_queue(), Level.INFO)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + 'no BNO055 orientation sensor available at 0x28.' + Style.RESET_ALL)
        #       self._set_feature_available('bno055', bno055_available)

        #       # NOTE: the default address for the ICM20948 is 0x68, but this conflicts with the PiJuice
        #       icm20948_available = ( 0x69 in self._addresses )
        #       if icm20948_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + 'ICM20948 available at 0x69.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + 'no ICM20948 available at 0x69.' + Style.RESET_ALL)
        #       self._set_feature_available('icm20948', icm20948_available)

        #       lsm303d_available = ( 0x1D in self._addresses )
        #       if lsm303d_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + 'LSM303D available at 0x1D.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + 'no LSM303D available at 0x1D.' + Style.RESET_ALL)
        #       self._set_feature_available('lsm303d', lsm303d_available)
        #
        #       vl53l1x_available = ( 0x29 in self._addresses )
        #       if vl53l1x_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + 'VL53L1X available at 0x29.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + 'no VL53L1X available at 0x29.' + Style.RESET_ALL)
        #       self._set_feature_available('vl53l1x', vl53l1x_available)

        #       as7262_available = ( 0x49 in self._addresses )
        #       if as7262_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + '-- AS7262 Spectrometer available at 0x49.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + '-- no AS7262 Spectrometer available at 0x49.' + Style.RESET_ALL)
        #       self._set_feature_available('as7262', as7262_available)

        #       pijuice_available = ( 0x68 in self._addresses )
        #       if pijuice_available:
        #           self._log.debug(Fore.CYAN + Style.BRIGHT + 'PiJuice hat available at 0x68.' + Style.RESET_ALL)
        #       else:
        #           self._log.debug(Fore.RED + Style.BRIGHT + 'no PiJuice hat available at 0x68.' + Style.RESET_ALL)
        #       self._set_feature_available('pijuice', pijuice_available)

        self._log.info(Fore.YELLOW + 'configure subsumption support...')

        # configure the MessageQueue, Controller and Arbitrator
        self._log.info('configuring message queue...')
        self._queue = MessageQueue(self._message_bus, self._log.level)
        self._message_bus.add_handler(Message, self._queue.handle)
        self._log.info('configuring controller...')
        self._controller = Controller(self._config, self._ifs, self._motors,
                                      self._callback_shutdown, self._log.level)
        self._log.info('configuring arbitrator...')
        self._arbitrator = Arbitrator(self._config, self._queue,
                                      self._controller, self._log.level)
        self._log.info('configured.')
예제 #10
0
from lib.controller import Controller, PlayerDeath
import json
import random

game = Controller()
game.start_game()

# beginning scene
begin_file = open('txt/begin.txt', 'r')
begin_dialogue = list(begin_file)
print(begin_dialogue[0])

envs = open('lib/environment.json')
data = json.loads(envs.read())
episodes = data['episodes']

def view(episode):
    print(episode['desc'])
    actions = list(episode['actions'].keys())
    possible_choices = range(len(actions))
    action_map = dict(zip(possible_choices, actions))
    for i in possible_choices:
        key = action_map[i]
        print("{0}: {1}".format(i, key))
    return action_map

def play_episode(episode, choice, action_map):
    action = action_map[choice]
    scenario = episode['actions'][action]
    result = scenario[1]
    if result == 'walk':
예제 #11
0
파일: ros.py 프로젝트: bopopescu/ros
    def run(self):
        '''
            This first disables the Pi's status LEDs, establishes the
            message queue arbitrator, the controller, enables the set
            of features, then starts the main OS loop.
        '''
        super(AbstractTask, self).run()
        loop_count = 0

        self._disable_leds = self._config['pi'].get('disable_leds')
        if self._disable_leds:
            # disable Pi LEDs since they may be distracting
            self._set_pi_leds(False)

        self._log.info('enabling features...')
        for feature in self._features:
            self._log.info('enabling feature {}...'.format(feature.name()))
            feature.enable()

        __enable_player = self._config['ros'].get('enable_player')
        if __enable_player:
            self._log.info('configuring sound player...')
            self._player = Player(Level.INFO)
        else:
            self._player = None

        vl53l1x_available = True  # self.get_property('features', 'vl53l1x')
        self._log.critical('vl53l1x_available? {}'.format(vl53l1x_available))
        ultraborg_available = True  # self.get_property('features', 'ultraborg')
        self._log.critical(
            'ultraborg available? {}'.format(ultraborg_available))
        if vl53l1x_available and ultraborg_available:
            self._log.critical('starting scanner tool...')
            self._lidar = Lidar(self._config, self._player, Level.INFO)
            self._lidar.enable()
        else:
            self._log.critical(
                'scanner tool does not have necessary dependencies.')

        # wait to stabilise features?

        # configure the Controller and Arbitrator
        self._log.info('configuring controller...')
        self._controller = Controller(Level.INFO, self._config, self._switch,
                                      self._infrareds, self._motors,
                                      self._rgbmatrix, self._lidar,
                                      self._callback_shutdown)

        self._log.info('configuring arbitrator...')
        self._arbitrator = Arbitrator(_level, self._queue, self._controller,
                                      self._mutex)

        flask_enabled = self._config['flask'].get('enabled')
        if flask_enabled:
            self._log.info('starting flask web server...')
            self.configure_web_server()
        else:
            self._log.info(
                'not starting flask web server (suppressed from command line).'
            )

        self._log.warning('Press Ctrl-C to exit.')

        wait_for_button_press = self._config['ros'].get(
            'wait_for_button_press')
        self._controller.set_standby(wait_for_button_press)

        # begin main loop ..............................

        #       self._log.info('starting battery check thread...')
        #       self._battery_check.enable()

        self._log.info('starting button thread...')
        self._button.start()

        #       self._log.info('enabling bno055 sensor...')
        #       self._bno055.enable()

        self._log.info('enabling bumpers...')
        self._bumpers.enable()

        #       self._log.info('starting info thread...')
        #       self._info.start()

        #       self._log.info('starting blinky thread...')
        #       self._rgbmatrix.enable(DisplayType.RANDOM)

        # enable arbitrator tasks (normal functioning of robot)

        main_loop_delay_ms = self._config['ros'].get('main_loop_delay_ms')
        self._log.info(
            'begin main os loop with {:d}ms delay.'.format(main_loop_delay_ms))
        _loop_delay_sec = main_loop_delay_ms / 1000
        self._arbitrator.start()
        while self._arbitrator.is_alive():
            #           The sensors and the flask service sends messages to the message queue,
            #           which forwards those messages on to the arbitrator, which chooses the
            #           highest priority message to send on to the controller. So the timing
            #           of this loop is inconsequential; it exists solely as a keep-alive.
            time.sleep(_loop_delay_sec)
            # end application loop .........................

        if not self._closing:
            self._log.warning('closing following loop...')
            self.close()
예제 #12
0
 def test_controller_init(self):
     controller = Controller(ControllerTestCase.path)
     self.assertEqual(ControllerTestCase.plateaubounds, (controller.x_plateau_lower,
                                                         controller.y_plateau_lower,
                                                         controller.x_plateau_upper,
                                                         controller.y_plateau_upper))
예제 #13
0
#!/usr/bin/env python3.8
from lib.views.Frames import topView
from lib.controller import Controller
import wx

if __name__ == "__main__":
    app = wx.App(False)
    controller = Controller(app)
    app.MainLoop()
예제 #14
0
def api_index(env):
    g_c = Controller()
    html = g_c.get_index()
    headers = [('Content-Type', 'text/html; charset=utf-8')]
    return '200 OK', headers, html
예제 #15
0
파일: ros.py 프로젝트: SiChiTong/ros-1
    def run(self):
        '''
            This first disables the Pi's status LEDs, establishes the
            message queue arbitrator, the controller, enables the set
            of features, then starts the main OS loop.
        '''
        super(AbstractTask, self).run()
        loop_count = 0
        # display banner!
        _banner = '\n' \
                  'ros\n' \
                  'ros                         █▒▒▒▒▒▒▒     █▒▒▒▒▒▒     █▒▒▒▒▒▒    █▒▒  \n' \
                + 'ros                         █▒▒   █▒▒   █▒▒   █▒▒   █▒▒         █▒▒  \n' \
                + 'ros                         █▒▒▒▒▒▒     █▒▒   █▒▒    █▒▒▒▒▒▒    █▒▒  \n' \
                + 'ros                         █▒▒  █▒▒    █▒▒   █▒▒         █▒▒        \n' \
                + 'ros                         █▒▒   █▒▒    █▒▒▒▒▒▒     █▒▒▒▒▒▒    █▒▒  \n' \
                + 'ros\n'
        self._log.info(_banner)

        self._disable_leds = self._config['pi'].get('disable_leds')
        if self._disable_leds:
            # disable Pi LEDs since they may be distracting
            self._set_pi_leds(False)

        self._log.info('enabling features...')
        for feature in self._features:
            self._log.info('enabling feature {}...'.format(feature.name()))
            feature.enable()

#       __enable_player = self._config['ros'].get('enable_player')
#       if __enable_player:
#           self._log.info('configuring sound player...')
#           self._player = Player(Level.INFO)
#       else:
#           self._player = None

#       i2c_slave_address = config['ros'].get('i2c_master').get('device_id') # i2c hex address of I2C slave device

        vl53l1x_available = True  # self.get_property('features', 'vl53l1x')
        ultraborg_available = True  # self.get_property('features', 'ultraborg')
        if vl53l1x_available and ultraborg_available:
            self._log.critical('starting scanner tool...')
            self._lidar = Lidar(self._config, Level.INFO)
            self._lidar.enable()
        else:
            self._log.critical(
                'lidar scanner tool does not have necessary dependencies.')

        # wait to stabilise features?

        # configure the Controller and Arbitrator
        self._log.info('configuring controller...')
        self._controller = Controller(self._config, self._ifs, self._motors,
                                      self._callback_shutdown, Level.INFO)

        self._log.info('configuring arbitrator...')
        self._arbitrator = Arbitrator(self._config, self._queue,
                                      self._controller, Level.WARN)

        _flask_enabled = self._config['flask'].get('enabled')
        if _flask_enabled:
            self._log.info('starting flask web server...')
            self.configure_web_server()
        else:
            self._log.info(
                'not starting flask web server (suppressed from command line).'
            )

        # bluetooth gamepad controller
        if self._gamepad_enabled:
            self._connect_gamepad()

        self._log.warning('Press Ctrl-C to exit.')

        _wait_for_button_press = self._config['ros'].get(
            'wait_for_button_press')
        self._controller.set_standby(_wait_for_button_press)

        # begin main loop ..............................

        self._log.info('starting button thread...')
        self._button.start()

        #       self._log.info('enabling bno055 sensor...')
        #       self._bno055.enable()

        #       self._bumpers.enable()

        self._indicator = Indicator(Level.INFO)
        # add indicator as message consumer
        self._queue.add_consumer(self._indicator)

        self._log.info(Fore.MAGENTA + 'enabling integrated front sensor...')
        self._ifs.enable()
        #       self._log.info('starting info thread...')
        #       self._info.start()

        #       self._log.info('starting blinky thread...')
        #       self._rgbmatrix.enable(DisplayType.RANDOM)

        # enable arbitrator tasks (normal functioning of robot)

        main_loop_delay_ms = self._config['ros'].get('main_loop_delay_ms')
        self._log.info(
            'begin main os loop with {:d}ms delay.'.format(main_loop_delay_ms))
        _loop_delay_sec = main_loop_delay_ms / 1000
        _main_loop_count = 0
        self._arbitrator.start()
        self._active = True
        while self._active:
            #           The sensors and the flask service sends messages to the message queue,
            #           which forwards those messages on to the arbitrator, which chooses the
            #           highest priority message to send on to the controller. So the timing
            #           of this loop is inconsequential; it exists solely as a keep-alive.
            _main_loop_count += 1
            self._log.debug(Fore.BLACK + Style.DIM +
                            '[{:d}] main loop...'.format(_main_loop_count))
            time.sleep(_loop_delay_sec)
            # end application loop .........................

        if not self._closing:
            self._log.warning('closing following loop...')
            self.close()
예제 #16
0
파일: depdep.py 프로젝트: kamaal44/depdep
#!/usr/bin/python

try:
        import sys
        from lib.controller import Controller
        from lib.core.common import *
        from lib.core.version import *
except ImportError,e:
        import sys
        sys.stdout.write("%s\n" %e)
        print exit_message
        sys.exit(1)


##
### Main ...
##

if __name__ == "__main__":

	try:
       		controller = Controller()
       		controller.run()
	except Exception, err_mess:
		print err_mess
		print exit_message	
		sys.exit(2)
 
예제 #17
0
def main():
    app = Controller()
    app.run_app()