예제 #1
0
def _with_latest_from(*args: Union[Observable, Iterable[Observable]]) -> Observable:
    sources: List[Observable] = []

    if isinstance(args[0], Iterable):
        sources += list(args[0])
    else:
        sources += list(cast(Iterable[Observable], args))

    return ops.with_latest_from(sources[1:])(sources[0])
예제 #2
0
 def _pid(process):
     return process.pipe(
         # trace_observable("pid"),
         ops.with_latest_from(setpoint),
         # trace_observable("pid2"),
         ops.scan(_pid_step, seed=None),
         # trace_observable("pid3"),
         ops.map(lambda i: i.control_value),
     )
예제 #3
0
def submit(gate: str, keys: List[str], ui: Dict[str,
                                                QWidget]) -> rx.Observable:
    if isinstance(gate, str):
        gate = ui[gate]

    gate = _unwrap_subject(gate)
    items = [_unwrap_subject(ui[k]) for k in keys]

    combined = items[0].pipe(ops.combine_latest(*items[1:]),
                             ops.map(lambda vs: dict(zip(keys, vs))))

    return gate.pipe(ops.filter(lambda x: x), ops.with_latest_from(combined),
                     ops.map(lambda x: x[1]))
예제 #4
0
파일: __init__.py 프로젝트: chstan/daquiri
def submit(gate: Hashable, keys: List[Hashable], ui: Dict[Hashable, QWidget]) -> rx.Observable:
    try:
        gate = ui[gate]
    except (ValueError, TypeError):
        pass

    gate = _unwrap_subject(gate)
    items = [_unwrap_subject(ui[k]) for k in keys]

    combined = items[0].pipe(
        ops.combine_latest(*items[1:]), ops.map(lambda vs: dict(zip(keys, vs)))
    )

    return gate.pipe(
        ops.filter(lambda x: x),
        ops.with_latest_from(combined),
        ops.map(lambda x: x[1]),
    )
예제 #5
0
    def __init__(self):
        self.__rawPluginOutputStream = Subject()
        self.__connectionStatusStream = Subject()

        self.__speechStream = with_latest_from(
            self.__rawPluginOutputStream.pipe(
                map(lambda dehydratedMsgDict: rehydrateMessage(
                    dehydratedMsgDict))),
            self.__connectionStatusStream,
        ).pipe(
            map(lambda combinedTuple: {
                **combinedTuple[0],
                **combinedTuple[1]
            }),
            merge(self.__connectionStatusStream),
        )

        # TODO - need to trigger NVDA to startup, if it isn't already
        #      - first need to check if NVDA is installed + if the plugin is

        asyncio.create_task(self.__startListeningForOutput())
예제 #6
0
def main():

    try:
        client = carla.Client('localhost', 2000)
        client.set_timeout(2.0)

        world = client.get_world()

        blueprint_library = world.get_blueprint_library()
        bp = random.choice(blueprint_library.filter('vehicle'))
        rgb_bp = blueprint_library.find('sensor.camera.rgb')

        spawn_points = world.get_map().get_spawn_points()
        spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()

        vehicle = world.try_spawn_actor(bp, spawn_point)

        print('created %s' % vehicle.type_id)
        vehicle.set_autopilot(True)

        sensors = [make_sensor(world, vehicle, rgb_bp, config[0], config[1]) for config in CAMERA_CONFIGS]
        image_obs = [from_sensor(sensor, idx) for idx, sensor in enumerate(sensors)]

        rx.interval(1).pipe(
            ops.with_latest_from(*image_obs),
        ).subscribe(grid_draw)

        time.sleep(5)

    finally:
        print('finally')
        for sensor in sensors:
            sensor.stop()
            sensor.destroy()
        vehicle.destroy()
        print('done')
예제 #7
0
def main():

    detr = DETRdemo(num_classes=91)
    state_dict = torch.hub.load_state_dict_from_url(
        url='https://dl.fbaipublicfiles.com/detr/detr_demo-da2a99e9.pth',
        map_location='cpu',
        check_hash=True)
    detr.load_state_dict(state_dict)
    detr.eval()
    detr.to('cuda:0')

    transform = T.Compose([
        T.Resize(800),
        T.ToTensor(),
        T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

    try:
        pygame.init()
        pygame.font.init()
        print(pygame.font.get_default_font())
        myfont = pygame.font.Font(pygame.font.get_default_font(), 16)

        pygame_scheduler = PyGameScheduler(pygame)

        display = pygame.display.set_mode((WIDTH, HEIGHT),
                                          pygame.HWSURFACE | pygame.DOUBLEBUF)

        client = carla.Client('localhost', 2000)
        client.set_timeout(5.0)
        #client.load_world("/Game/Carla/Maps/Town10HD")

        world = client.get_world()

        blueprint_library = world.get_blueprint_library()
        bp = random.choice(blueprint_library.filter('vehicle'))
        rgb_bp = blueprint_library.find('sensor.camera.rgb')

        spawn_points = world.get_map().get_spawn_points()
        spawn_point = random.choice(
            spawn_points) if spawn_points else carla.Transform()

        vehicle = world.try_spawn_actor(bp, spawn_point)

        print('created %s' % vehicle.type_id)
        vehicle.set_autopilot(True)

        sensor = make_sensor(
            world, vehicle, rgb_bp,
            carla.Transform(carla.Location(x=1.5, y=0, z=2.4),
                            carla.Rotation(yaw=0)), 120)
        image_ob = from_sensor(sensor)

        def grid_draw(params):
            print(threading.get_ident(), datetime.now(), "grid_draw")
            frame = params[0]
            image = params[1]
            scores, boxes = detect(Image.fromarray(image), detr, transform)
            #print(scores)
            surface = pygame.surfarray.make_surface(image.swapaxes(0, 1))
            display.blit(surface, (0, 0))
            #for box in boxes:
            #    pygame.draw.rect(surface, (255,0,0), (box[0], box[1], box[2]-box[0], box[3]-box[1]), 2)
            plot_results(display, myfont, scores, boxes)

            pygame.display.flip()

        rx.interval(0.1).pipe(ops.with_latest_from(image_ob),
                              ops.observe_on(pygame_scheduler),
                              ops.do_action(grid_draw)).subscribe()

        clock = pygame.time.Clock()
        running = True
        while running:
            clock.tick_busy_loop(60)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False

            print(threading.get_ident(), datetime.now(), "main")
            pygame_scheduler.run()

    except Exception as ex:
        print(ex)

    finally:
        print('finally')
        sensor.stop()
        sensor.destroy()
        vehicle.destroy()

        pygame.quit()
        print('done')
 def create():
     return e1.pipe(
         ops.with_latest_from(e2),
         ops.map(sum),
     )
 def create():
     return e1.pipe(
         ops.with_latest_from(e2),
         ops.map(lambda xy: _raise(ex)),
     )
 def create():
     return e1.pipe(
         ops.with_latest_from(e2),
         ops.map(sum),
         )
 def create():
     return e1.pipe(
         ops.with_latest_from(e2),
         ops.map(lambda xy: _raise(ex)),
         )
예제 #12
0
def game_loop(args):
    pygame.init()
    pygame.font.init()

    scheduler = PyGameScheduler(pygame)

    world = None
    actor_list = []

    try:
        client = carla.Client(args.host, args.port)
        client.set_timeout(2.0)
        world = client.get_world()
        map = world.get_map()

        blueprint_library = world.get_blueprint_library()
        bp = blueprint_library.find('vehicle.jeep.wrangler_rubicon')

        spawn_points = map.get_spawn_points()
        spawn_point = random.choice(
            spawn_points) if spawn_points else carla.Transform()
        vehicle = world.try_spawn_actor(bp, spawn_point)
        vehicle.set_autopilot(True)
        actor_list.append(vehicle)

        lidar_bp = world.get_blueprint_library().find('sensor.lidar.ray_cast')
        lidar_bp.set_attribute('range', str(200))
        lidar_bp.set_attribute('channels', str(32))
        lidar_bp.set_attribute('rotation_frequency', str(10))
        lidar_bp.set_attribute('points_per_second', str(360 * 10 * 10 * 32))
        lidar_sensor = world.spawn_actor(lidar_bp,
                                         carla.Transform(
                                             carla.Location(x=1.5, y=0,
                                                            z=2.4)),
                                         attach_to=vehicle)
        actor_list.append(lidar_sensor)
        print('created %s' % lidar_sensor.type_id)

        display = pygame.display.set_mode((args.width, args.height),
                                          pygame.OPENGL | pygame.DOUBLEBUF)

        lidar_obs = from_sensor(lidar_sensor)

        ctx = moderngl.create_context()
        prog = ctx.program(
            vertex_shader='''
                #version 330
                uniform mat4 Mvp;

                in vec3 in_vert;
                out vec4 frag_color;
                void main() {
                    frag_color = mix(vec4(0.0, 0.0, 1.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), abs(sin(in_vert.z)));
                    gl_Position = Mvp * vec4(in_vert, 1.0);
                }
            ''',
            fragment_shader='''
                #version 330
                in vec4 frag_color;
                out vec4 f_color;
                void main() {
                    f_color = frag_color;
                    //f_color = vec4(0.1, 0.1, 0.1, 1.0);
                }
            ''',
        )
        mvp = prog['Mvp']

        camera = Camera(args.width / args.height)

        def lidar_draw(params):
            frame = params[0]
            xyz = params[1]

            ctx.clear(1.0, 1.0, 1.0)
            ctx.enable(moderngl.DEPTH_TEST)

            vbo = ctx.buffer(xyz.astype('f4').tobytes())
            vao = ctx.simple_vertex_array(prog, vbo, 'in_vert')
            mvp.write((camera.mat_projection *
                       camera.mat_lookat).astype('f4').tobytes())
            vao.render(moderngl.POINTS)

            pygame.display.flip()

        rx.interval(0.033).pipe(
            ops.with_latest_from(lidar_obs),
            ops.observe_on(scheduler),
        ).subscribe(lidar_draw)

        clock = pygame.time.Clock()
        running = True
        while running:
            clock.tick_busy_loop(60)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            scheduler.run()

    finally:
        print('destroying actors')
        actor_list.reverse()
        for actor in actor_list:
            print('destroy %s' % actor.type_id)
            if (isinstance(actor, carla.Sensor)):
                print('stop %s' % actor.type_id)
                actor.stop()
            actor.destroy()
        print('done.')

        pygame.quit()
예제 #13
0
def main():

    try:
        pygame.init()
        pygame.font.init()
        pygame_scheduler = PyGameScheduler(pygame)

        display = pygame.display.set_mode(
            (WIDTH, HEIGHT),
            pygame.HWSURFACE | pygame.DOUBLEBUF)


        client = carla.Client('localhost', 2000)
        client.set_timeout(5.0)
        client.load_world("/Game/Carla/Maps/Town10HD")

        world = client.get_world()

        blueprint_library = world.get_blueprint_library()
        bp = random.choice(blueprint_library.filter('vehicle'))
        rgb_bp = blueprint_library.find('sensor.camera.rgb')

        spawn_points = world.get_map().get_spawn_points()
        spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()

        vehicle = world.try_spawn_actor(bp, spawn_point)

        print('created %s' % vehicle.type_id)
        vehicle.set_autopilot(True)

        sensors = [make_sensor(world, vehicle, rgb_bp, config[0], config[1]) for config in CAMERA_CONFIGS]
        image_obs = [from_sensor(sensor, idx) for idx, sensor in enumerate(sensors)]

        def grid_draw(params):
            frame = params[0]
            images = params[1:]
            for idx, image in enumerate(images):
                display.blit(image, GRID_ORIGINS[idx])
            pygame.display.flip()

        rx.interval(0.033).pipe(
            ops.with_latest_from(*image_obs),
            ops.observe_on(pygame_scheduler),
        ).subscribe(grid_draw)

        clock = pygame.time.Clock()
        running = True
        while running:
            clock.tick_busy_loop(60)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            pygame_scheduler.run()


    finally:
        print('finally')
        for sensor in sensors:
            sensor.stop()
            sensor.destroy()
        vehicle.destroy()

        pygame.quit()
        print('done')