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?
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):
How do I compute road curvature?
When we call map.generate_waypoints(distance):
When we call waypoint.next(distance):
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.

Most helpful comment
Hi @YashBansod.
Regarding your questions:
By its geometry that can be lines and arcs.
get_waypoint(Location): Returns a Waypoint centered on the nearest lane.You can't currently, but we are planning to provide the road geometry on our Python API.
It generates a graph of waypoints with approximately the provided distance between them.
Is it the distance along the route.
Hope it helps! We will add this to our docs soon :)