Exemplo n.º 1
0
    def test_json_metadata_writer(self):
        builder = self._get_metadata_builder()

        expected = {
            "type": "xviz/metadata",
            "data": {
                "version": "2.0.0",
                "streams": {
                    "/image/camera": {
                        "category": "PRIMITIVE",
                        "primitive_type": "IMAGE",
                    },
                    "/vehicle_pose": {
                        "category": "POSE",
                    },
                    "/point/lidar": {
                        "category": "PRIMITIVE",
                        "primitive_type": "POINT",
                        "stream_style": {
                            "radius_pixels": 1.0,
                        },
                        "coordinate": "VEHICLE_RELATIVE",
                    },
                },
            },
        }

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZJsonWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()
        data = json.loads(data.decode('ascii'))

        assert data == expected
        writer.close()
Exemplo n.º 2
0
    def test_json_normal_writer(self):
        builder = xb.XVIZBuilder()
        builder.pose()\
            .timestamp(2.000000000001)\
            .map_origin(4.4, 5.5, 6.6)\
            .position(44., 55., 66.)\
            .orientation(0.44, 0.55, 0.66)
        builder.primitive('/test_primitive').circle([0, 0, 0], 2)

        expected = {
            "type": "xviz/state_update",
            "data": {
                "update_type":
                "INCREMENTAL",
                "updates": [{
                    "timestamp": 2.0,
                    "poses": {
                        "/vehicle_pose": {
                            "timestamp": 2.0,
                            "map_origin": {
                                "longitude": 4.4,
                                "latitude": 5.5,
                                "altitude": 6.6
                            },
                            "position": [44.0, 55.0, 66.0],
                            "orientation": [0.44, 0.55, 0.66]
                        }
                    },
                    "primitives": {
                        "/test_primitive": {
                            "circles": [{
                                "center": [0.0, 0.0, 0.0],
                                "radius": 2.0
                            }]
                        }
                    }
                }]
            }
        }
        expected = json.dumps(expected, separators=(',', ':')).encode('ascii')

        source = xi.MemorySource(latest_only=True)
        writer = xi.XVIZJsonWriter(source)
        writer.write_message(builder.get_message())
        data = source.read()

        assert data == expected
        writer.close()
Exemplo n.º 3
0
    def test_message_index(self):
        metadata_builder = self._get_metadata_builder()
        builder = self._get_builder(circle=True)

        expected = {
            'timing': [[2.000000000001, 2.000000000001, 0, '2-frame']],
        }

        source = xi.MemorySource()
        data = source._data  # save a reference to dict since it gets deleted after close
        writer = xi.XVIZJsonWriter(source)
        writer.write_message(metadata_builder.get_message())
        writer.write_message(builder.get_message())
        writer.close()
        data = json.loads(data['0-frame.json'].decode('ascii'))

        assert data == expected
Exemplo n.º 4
0
import os
import shutil
import xviz_avs.io as xi
from circle import CircleScenario

scenario = CircleScenario(live=False)

OUTPUT = "web/output"

if not os.path.exists(OUTPUT):
    os.mkdir(OUTPUT)

#writer = xi.XVIZProtobufWriter(xi.DirectorySource(OUTPUT))
#writer = xi.XVIZGLBWriter(xi.DirectorySource(OUTPUT))
writer = xi.XVIZJsonWriter(xi.DirectorySource(OUTPUT))

writer.write_message(scenario.get_metadata_inner())
for t in range(0, 10):
    writer.write_message(scenario.get_message_inner(t / 10))

writer.close()

shutil.copy("data/0-frame.json", "web/output/0-frame.json")
Exemplo n.º 5
0
def main():
    if os.path.exists(OUTPUT):
        shutil.rmtree(OUTPUT)
    os.mkdir(OUTPUT)

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

        load_world_if_needed(client, "/Game/Carla/Maps/Town01")

        world = client.get_world()
        map = world.get_map()

        # 시작위치와 방향
        start_tf = carla.Transform(carla.Location(x=230, y=55.4, z=0.1),
                                   carla.Rotation(0, 180, 0))
        start_wp = map.get_waypoint(start_tf.location)

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

        vehicle = world.spawn_actor(bp, start_tf)
        vehicle.set_autopilot(True)
        print('created %s' % vehicle.type_id)
        # vehicle.set_velocity(carla.Vector3D(-10, 0, 0)) # 초기 속도를 지정할 수 있다.

        camera_rgb = world.spawn_actor(
            blueprint_library.find('sensor.camera.rgb'),
            carla.Transform(carla.Location(x=-5.5, z=2.8),
                            carla.Rotation(pitch=-15)),
            attach_to=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(30))
        lidar_sensor = world.spawn_actor(lidar_bp,
                                         carla.Transform(
                                             carla.Location(x=1.5, y=0,
                                                            z=2.4)),
                                         attach_to=vehicle)

        writer = xi.XVIZJsonWriter(xi.DirectorySource("output"))
        metadata = get_metadata()
        writer.write_message(metadata)

        with CarlaSyncMode(world, camera_rgb, lidar_sensor,
                           fps=30) as sync_mode:
            while True:
                curr_tf = vehicle.get_transform()
                curr_location = vehicle.get_location()

                snapshot, image_rgb, pointcloud = sync_mode.tick(timeout=2.0)
                print(snapshot.frame)

                spectator_loc = carla.Location(curr_location.x,
                                               curr_location.y,
                                               curr_location.z + 2.5)
                world.get_spectator().set_transform(
                    carla.Transform(spectator_loc, curr_tf.rotation))
                writer.write_message(
                    get_message(metadata, snapshot.frame, vehicle))

        print("success")

    finally:
        writer.close()
        print('writer closed')

        lidar_sensor.destroy()
        camera_rgb.destroy()

        print('destroying vehicle')
        vehicle.destroy()

        print('done.')