Carla: How to get the distance of the vehicle from the center of the lane and the angle between the vehicle orientation and the road tangent

Created on 26 Nov 2018  Â·  6Comments  Â·  Source: carla-simulator/carla

Thanks for Carla team hard work.
I want to train a reinforcement learning agent based on CARLA.
How to get the distance of the vehicle from the center of the lane and the angle between the vehicle orientation and the road tangent?

python stale support

Most helpful comment

Hi @YashBansod.
Regarding your questions:

How are waypoints represented in the Map

By its geometry that can be lines and arcs.

When you call get_waypoint(Location)...

get_waypoint(Location): Returns a Waypoint centered on the nearest lane.

How do I compute road curvature?

You can't currently, but we are planning to provide the road geometry on our Python API.

When we call map.generate_waypoints(distance)

It generates a graph of waypoints with approximately the provided distance between them.

When we call waypoint.next(distance)

Is it the distance along the route.

Hope it helps! We will add this to our docs soon :)

All 6 comments

Hi @HubFire.

Using 0.9.1 you are able to get a carla.Waypoint (based on the OpenDrive) using:

waypoint = client.get_world().get_map().get_waypoint(carla.Location, project_to_road=True)

As you have specified project_to_road=True, this waypoint will be on the center of the (nearest) road.
A carla.Waypoint have a carla.Transform that have a carla.Location and a carla.Rotation.
You can use this transform to get the distance of the center of the road and the orientation difference.

Cheers!

@marcgpuig I wanted to know more about the Waypoints. Here are my doubts on the matter:
(I do not expect direct answers to all of them, but it would be great if you could direct me to the relevant document / literature where I could find the answers).

  • How are waypoints represented in the Map.

  • When you call get_waypoint(Location):

    • Is the returned waypoint the nearest waypoint (from a list of waypoints in the map) to the Location?
      or
    • Is it the transform of the nearest waypoint (point normal to the nearest road network) ?
  • How do I compute road curvature?

    • My present idea is to get the next few waypoints, fit a cubic spline over these points and get the curvature.
    • But, If you can direct me to literature regarding the road network and the waypoints used, I think there might be a better way to go about it.
  • When we call map.generate_waypoints(distance):

    • Why aren't the waypoints generated near the vicinity of the vehicle / spectator. How to make that happen?
  • When we call waypoint.next(distance):

    • Is the new waypoint precisely that euclidean distance away from the present point or is it the distance along the route.

Hi @YashBansod.
Regarding your questions:

How are waypoints represented in the Map

By its geometry that can be lines and arcs.

When you call get_waypoint(Location)...

get_waypoint(Location): Returns a Waypoint centered on the nearest lane.

How do I compute road curvature?

You can't currently, but we are planning to provide the road geometry on our Python API.

When we call map.generate_waypoints(distance)

It generates a graph of waypoints with approximately the provided distance between them.

When we call waypoint.next(distance)

Is it the distance along the route.

Hope it helps! We will add this to our docs soon :)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@YashBansod Did you finally get through with the calculating the curvature ? If yes then maybe you could pass on the knowledge :)

I use this approximation method.

        def calcu_c_1(host_waypoint, route_distance):
            previous_waypoint = host_waypoint.previous(route_distance)[0]
            next_waypoint = host_waypoint.next(route_distance)[0]
            _transform = next_waypoint.transform
            _location, _rotation  = _transform.location, _transform.rotation
            x1, y1 = _location.x, _location.y
            yaw1 = _rotation.yaw

            _transform = previous_waypoint.transform
            _location, _rotation  = _transform.location, _transform.rotation
            x2, y2 = _location.x, _location.y
            yaw2 = _rotation.yaw

            c = 2*sin(radians((yaw1-yaw2)/2)) / sqrt((x1-x2)**2 + (y1-y2)**2)
            return c

std and mean with different route_distance.
Figure_1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qixiaoshuai0120 picture qixiaoshuai0120  Â·  3Comments

NYJiaxing picture NYJiaxing  Â·  3Comments

robertnishihara picture robertnishihara  Â·  4Comments

cstamatiadis picture cstamatiadis  Â·  3Comments

mhusseinsh picture mhusseinsh  Â·  3Comments