Beispiel #1
0
def map_dynamic_actor(actor: carla.Actor,
                      world_map: carla.Map) -> DynamicActor:
    location: carla.Location = actor.get_location()
    gnss: carla.GeoLocation = world_map.transform_to_geolocation(location)
    velocity: carla.Vector3D = actor.get_velocity()
    acceleration: carla.Vector3D = actor.get_acceleration()
    color: str = str(
        actor.attributes['color']) if 'color' in actor.attributes else None
    extent: carla.Vector3D = actor.bounding_box.extent

    transform: carla.Transform = carla.Transform(
        rotation=actor.get_transform().rotation)

    transformed_extent: Tuple[carla.Location, carla.Location, carla.Location,
                              carla.Location] = (
                                  transform.transform(
                                      carla.Location(+extent.x, +extent.y, 0)),
                                  transform.transform(
                                      carla.Location(+extent.x, -extent.y, 0)),
                                  transform.transform(
                                      carla.Location(-extent.x, -extent.y, 0)),
                                  transform.transform(
                                      carla.Location(-extent.x, +extent.y, 0)),
                              )

    bbox: Tuple[Point2D, Point2D, Point2D, Point2D] = cast(
        Tuple[Point2D, Point2D, Point2D, Point2D],
        tuple(
            map(
                lambda t: geoloc2point2d(
                    world_map.transform_to_geolocation(
                        carla.Vector3D(location.x + t.x, location.y + t.y,
                                       location.z))), transformed_extent)))

    return DynamicActor(
        id=actor.id,
        type=UncertainProperty(1., resolve_carla_type(actor.type_id)),
        type_id=actor.type_id,
        location=UncertainProperty(1.,
                                   Point3D(location.x, location.y,
                                           location.z)),
        gnss=UncertainProperty(
            1., Point3D(gnss.latitude, gnss.longitude, gnss.altitude)),
        dynamics=ActorDynamics(velocity=UncertainProperty(
            1., Point3D(velocity.x, velocity.y, velocity.z)),
                               acceleration=UncertainProperty(
                                   1.,
                                   Point3D(acceleration.x, acceleration.y,
                                           acceleration.z))),
        props=ActorProperties(color=UncertainProperty(1., color),
                              extent=UncertainProperty(
                                  1., Point3D(extent.x, extent.y, extent.z)),
                              bbox=UncertainProperty(1., bbox)))
Beispiel #2
0
def get_speed(actor: carla.Actor) -> float:
    """in km/h"""
    vector: carla.Vector3D = actor.get_velocity()
    MPS_TO_KMH = 3.6
    return MPS_TO_KMH * math.sqrt(vector.x**2 + vector.y**2 + vector.z**2)
def speed(actor: carla.Actor) -> float:
    """Returns the speed of the given actor in km/h."""
    return 3.6 * vector_norm(actor.get_velocity())