コード例 #1
0
ファイル: app.py プロジェクト: cadenai/byodr
def main():
    parser = argparse.ArgumentParser(description='Recorder.')
    parser.add_argument('--name',
                        type=str,
                        default='none',
                        help='Process name.')
    parser.add_argument('--sessions',
                        type=str,
                        default='/sessions',
                        help='Sessions directory.')
    parser.add_argument('--config',
                        type=str,
                        default='/config',
                        help='Config directory path.')
    args = parser.parse_args()

    sessions_dir = os.path.expanduser(args.sessions)
    assert os.path.exists(
        sessions_dir), "Cannot use sessions directory '{}'".format(
            sessions_dir)

    application = RecorderApplication(config_dir=args.config,
                                      sessions_dir=sessions_dir)
    quit_event = application.quit_event

    pilot = json_collector(url='ipc:///byodr/pilot.sock',
                           topic=b'aav/pilot/output',
                           event=quit_event)
    vehicle = json_collector(url='ipc:///byodr/vehicle.sock',
                             topic=b'aav/vehicle/state',
                             event=quit_event)
    ipc_chatter = json_collector(url='ipc:///byodr/teleop_c.sock',
                                 topic=b'aav/teleop/chatter',
                                 pop=True,
                                 event=quit_event)

    application.publisher = JSONPublisher(url='ipc:///byodr/recorder.sock',
                                          topic='aav/recorder/state')
    application.camera = CameraThread(url='ipc:///byodr/camera_0.sock',
                                      topic=b'aav/camera/0',
                                      event=quit_event)
    application.ipc_server = LocalIPCServer(url='ipc:///byodr/recorder_c.sock',
                                            name='recorder',
                                            event=quit_event)
    application.pilot = lambda: pilot.get()
    application.vehicle = lambda: vehicle.get()
    application.ipc_chatter = lambda: ipc_chatter.get()

    threads = [
        pilot, vehicle, ipc_chatter, application.camera, application.ipc_server
    ]
    if quit_event.is_set():
        return 0

    [t.start() for t in threads]
    application.run()

    logger.info("Waiting on threads to stop.")
    [t.join() for t in threads]
コード例 #2
0
def main():
    parser = argparse.ArgumentParser(description='Rover main.')
    parser.add_argument('--name',
                        type=str,
                        default='none',
                        help='Process name.')
    parser.add_argument('--config',
                        type=str,
                        default='/config',
                        help='Config directory path.')
    args = parser.parse_args()

    application = RoverApplication(config_dir=args.config)
    quit_event = application.quit_event

    pilot = json_collector(url='ipc:///byodr/pilot.sock',
                           topic=b'aav/pilot/output',
                           event=quit_event)
    teleop = json_collector(url='ipc:///byodr/teleop.sock',
                            topic=b'aav/teleop/input',
                            event=quit_event)
    ipc_chatter = json_collector(url='ipc:///byodr/teleop_c.sock',
                                 topic=b'aav/teleop/chatter',
                                 pop=True,
                                 event=quit_event)

    application.state_publisher = JSONPublisher(
        url='ipc:///byodr/vehicle.sock', topic='aav/vehicle/state')
    application.ipc_server = LocalIPCServer(url='ipc:///byodr/vehicle_c.sock',
                                            name='platform',
                                            event=quit_event)
    application.pilot = lambda: pilot.get()
    application.teleop = lambda: teleop.get()
    application.ipc_chatter = lambda: ipc_chatter.get()

    threads = [pilot, teleop, ipc_chatter, application.ipc_server]
    if quit_event.is_set():
        return 0

    [t.start() for t in threads]
    application.run()

    logger.info("Waiting on threads to stop.")
    [t.join() for t in threads]
コード例 #3
0
def main():
    parser = argparse.ArgumentParser(description='ROS2 rover node.')
    parser.add_argument('--name',
                        type=str,
                        default='none',
                        help='Process name.')
    parser.add_argument('--config',
                        type=str,
                        default='/config',
                        help='Config directory path.')
    args = parser.parse_args()

    application = RosApplication(config_dir=args.config)
    quit_event = application.quit_event
    logger = application.logger

    publisher = JSONPublisher(url='ipc:///byodr/ros.sock',
                              topic='aav/ros/input')
    pilot = json_collector(url='ipc:///byodr/pilot.sock',
                           topic=b'aav/pilot/output',
                           event=quit_event)
    ipc_chatter = json_collector(url='ipc:///byodr/teleop_c.sock',
                                 topic=b'aav/teleop/chatter',
                                 pop=True,
                                 event=quit_event)
    application.publish = lambda m: publisher.publish(m)
    application.pilot = lambda: pilot.get()
    application.ipc_chatter = lambda: ipc_chatter.get()
    threads = [pilot, ipc_chatter]
    if quit_event.is_set():
        return 0

    rclpy.init()
    [t.start() for t in threads]
    application.run()

    logger.info("Waiting on threads to stop.")
    [t.join() for t in threads]
    rclpy.shutdown()
コード例 #4
0
def main():
    parser = argparse.ArgumentParser(description='Inference server.')
    parser.add_argument('--config',
                        type=str,
                        default='/config',
                        help='Config directory path.')
    parser.add_argument('--internal',
                        type=str,
                        default='/models',
                        help='Directory with the default inference models.')
    parser.add_argument('--user',
                        type=str,
                        default='/user_models',
                        help='Directory with the user inference models.')
    parser.add_argument('--routes',
                        type=str,
                        default='/routes',
                        help='Directory with the navigation routes.')
    args = parser.parse_args()

    application = InferenceApplication(config_dir=args.config,
                                       internal_models=args.internal,
                                       user_models=args.user,
                                       navigation_routes=args.routes)
    quit_event = application.quit_event

    teleop = json_collector(url='ipc:///byodr/teleop.sock',
                            topic=b'aav/teleop/input',
                            event=quit_event)
    pilot = json_collector(url='ipc:///byodr/pilot.sock',
                           topic=b'aav/pilot/output',
                           event=quit_event)
    ipc_chatter = json_collector(url='ipc:///byodr/teleop_c.sock',
                                 topic=b'aav/teleop/chatter',
                                 pop=True,
                                 event=quit_event)

    application.publisher = JSONPublisher(url='ipc:///byodr/inference.sock',
                                          topic='aav/inference/state')
    application.camera = CameraThread(url='ipc:///byodr/camera_0.sock',
                                      topic=b'aav/camera/0',
                                      event=quit_event)
    application.ipc_server = LocalIPCServer(
        url='ipc:///byodr/inference_c.sock',
        name='inference',
        event=quit_event)
    application.teleop = lambda: teleop.get()
    application.pilot = lambda: pilot.get()
    application.ipc_chatter = lambda: ipc_chatter.get()

    threads = [
        teleop, pilot, ipc_chatter, application.camera, application.ipc_server
    ]
    if quit_event.is_set():
        return 0

    [t.start() for t in threads]
    application.run()

    logger.info("Waiting on threads to stop.")
    [t.join() for t in threads]
コード例 #5
0
def main():
    parser = argparse.ArgumentParser(description='Teleop sockets server.')
    parser.add_argument('--name',
                        type=str,
                        default='none',
                        help='Process name.')
    parser.add_argument('--config',
                        type=str,
                        default='/config',
                        help='Config directory path.')
    parser.add_argument('--routes',
                        type=str,
                        default='/routes',
                        help='Directory with the navigation routes.')
    args = parser.parse_args()

    route_store = ReloadableDataSource(
        FileSystemRouteDataSource(directory=args.routes,
                                  fn_load_image=_load_nav_image,
                                  load_instructions=False))
    route_store.load_routes()

    application = TeleopApplication(event=quit_event, config_dir=args.config)
    application.setup()

    camera_front = CameraThread(url='ipc:///byodr/camera_0.sock',
                                topic=b'aav/camera/0',
                                event=quit_event)
    camera_rear = CameraThread(url='ipc:///byodr/camera_1.sock',
                               topic=b'aav/camera/1',
                               event=quit_event)
    pilot = json_collector(url='ipc:///byodr/pilot.sock',
                           topic=b'aav/pilot/output',
                           event=quit_event)
    vehicle = json_collector(url='ipc:///byodr/vehicle.sock',
                             topic=b'aav/vehicle/state',
                             event=quit_event)
    inference = json_collector(url='ipc:///byodr/inference.sock',
                               topic=b'aav/inference/state',
                               event=quit_event)
    recorder = json_collector(url='ipc:///byodr/recorder.sock',
                              topic=b'aav/recorder/state',
                              event=quit_event)

    threads = [camera_front, camera_rear, pilot, vehicle, inference, recorder]
    if quit_event.is_set():
        return 0

    [t.start() for t in threads]

    teleop_publisher = JSONPublisher(url='ipc:///byodr/teleop.sock',
                                     topic='aav/teleop/input')
    external_publisher = JSONPublisher(url='ipc:///byodr/external.sock',
                                       topic='aav/external/input')
    chatter = JSONPublisher(url='ipc:///byodr/teleop_c.sock',
                            topic='aav/teleop/chatter')
    zm_client = JSONZmqClient(urls=[
        'ipc:///byodr/pilot_c.sock', 'ipc:///byodr/inference_c.sock',
        'ipc:///byodr/vehicle_c.sock', 'ipc:///byodr/relay_c.sock',
        'ipc:///byodr/recorder_c.sock', 'ipc:///byodr/camera_c.sock'
    ])

    def on_options_save():
        chatter.publish(dict(time=timestamp(), command='restart'))
        application.setup()

    def list_process_start_messages():
        return zm_client.call(dict(request='system/startup/list'))

    def list_service_capabilities():
        return zm_client.call(dict(request='system/service/capabilities'))

    def get_navigation_image(image_id):
        return route_store.get_image(image_id)

    def teleop_publish(cmd):
        # We are the authority on route state.
        cmd['navigator'] = dict(route=route_store.get_selected_route())
        teleop_publisher.publish(cmd)

    def override_publish(nav_request):
        # We are the authority on route state.
        if nav_request is not None:
            external_publisher.publish(nav_request)

    try:
        main_redirect_url = '/index.htm?v=0.55.02'
        main_app = web.Application([
            (r"/ws/ctl", ControlServerSocket, dict(fn_control=teleop_publish)),
            (r"/ws/log", MessageServerSocket,
             dict(fn_state=(lambda: (pilot.get(), vehicle.get(), inference.get(
             ), recorder.get())))),
            (r"/ws/cam/front", CameraMJPegSocket,
             dict(image_capture=(lambda: camera_front.capture()))),
            (r"/ws/cam/rear", CameraMJPegSocket,
             dict(image_capture=(lambda: camera_rear.capture()))),
            (r'/ws/nav', NavImageHandler,
             dict(fn_get_image=(
                 lambda image_id: get_navigation_image(image_id)))),
            (r"/api/user/options", ApiUserOptionsHandler,
             dict(user_options=(UserOptions(
                 application.get_user_config_file())),
                  fn_on_save=on_options_save)),
            (r"/api/system/state", JSONMethodDumpRequestHandler,
             dict(fn_method=list_process_start_messages)),
            (r"/api/system/capabilities", JSONMethodDumpRequestHandler,
             dict(fn_method=list_service_capabilities)),
            (r"/api/navigation/routes", JSONNavigationHandler,
             dict(route_store=route_store)),
            (r"/ext/v10/direct/navigate", SimpleRequestNavigationHandler,
             dict(route_store=route_store, fn_override=override_publish)),
            (r"/", web.RedirectHandler,
             dict(url=main_redirect_url, permanent=False)),
            (r"/(.*)", web.StaticFileHandler, {
                'path': os.path.join(os.path.sep, 'app', 'htm')
            })
        ])
        http_server = HTTPServer(main_app, xheaders=True)
        http_server.bind(8080)
        http_server.start()
        logger.info("Web services started on port 8080.")
        io_loop.start()
    except KeyboardInterrupt:
        quit_event.set()

    route_store.quit()

    logger.info("Waiting on threads to stop.")
    [t.join() for t in threads]
コード例 #6
0
ファイル: app.py プロジェクト: cadenai/byodr
def main():
    parser = argparse.ArgumentParser(description='Pilot.')
    parser.add_argument('--name',
                        type=str,
                        default='none',
                        help='Process name.')
    parser.add_argument('--config',
                        type=str,
                        default='/config',
                        help='Config directory path.')
    parser.add_argument('--routes',
                        type=str,
                        default='/routes',
                        help='Directory with the navigation routes.')
    args = parser.parse_args()

    _relay = SearchUsbRelayFactory().get_relay()
    logger.info("The USB Relay is {} attached.".format(
        'well' if _relay.is_attached() else 'not'))

    if _relay.is_attached():
        _holder = StaticChannelRelayHolder(relay=_relay, channel=0)
        monitoring_relay = RealMonitoringRelay(relay=_holder,
                                               config_dir=args.config)
    else:
        monitoring_relay = NoopRelay()

    try:
        route_store = ReloadableDataSource(
            FileSystemRouteDataSource(directory=args.routes,
                                      load_instructions=True))
        application = PilotApplication(processor=CommandProcessor(route_store),
                                       relay=monitoring_relay,
                                       config_dir=args.config)
        quit_event = application.quit_event

        teleop = json_collector(url='ipc:///byodr/teleop.sock',
                                topic=b'aav/teleop/input',
                                event=quit_event)
        external = json_collector(url='ipc:///byodr/external.sock',
                                  topic=b'aav/external/input',
                                  hwm=10,
                                  pop=True,
                                  event=quit_event)
        ros = json_collector(url='ipc:///byodr/ros.sock',
                             topic=b'aav/ros/input',
                             hwm=10,
                             pop=True,
                             event=quit_event)
        vehicle = json_collector(url='ipc:///byodr/vehicle.sock',
                                 topic=b'aav/vehicle/state',
                                 event=quit_event)
        inference = json_collector(url='ipc:///byodr/inference.sock',
                                   topic=b'aav/inference/state',
                                   event=quit_event)
        ipc_chatter = json_collector(url='ipc:///byodr/teleop_c.sock',
                                     topic=b'aav/teleop/chatter',
                                     pop=True,
                                     event=quit_event)

        application.teleop = lambda: teleop.get()
        application.external = lambda: external.get()
        application.ros = lambda: ros.get()
        application.vehicle = lambda: vehicle.get()
        application.inference = lambda: inference.get()
        application.ipc_chatter = lambda: ipc_chatter.get()
        application.publisher = JSONPublisher(url='ipc:///byodr/pilot.sock',
                                              topic='aav/pilot/output')
        application.ipc_server = LocalIPCServer(
            url='ipc:///byodr/pilot_c.sock', name='pilot', event=quit_event)
        threads = [
            teleop, external, ros, vehicle, inference, ipc_chatter,
            application.ipc_server
        ]
        if quit_event.is_set():
            return 0

        [t.start() for t in threads]
        application.run()

        route_store.quit()

        logger.info("Waiting on threads to stop.")
        [t.join() for t in threads]
    finally:
        monitoring_relay.quit()