Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

velocity of ego agent #377

Open
Draupadin opened this issue Jan 21, 2022 · 2 comments
Open

velocity of ego agent #377

Draupadin opened this issue Jan 21, 2022 · 2 comments

Comments

@Draupadin
Copy link

Draupadin commented Jan 21, 2022

Hi, I'm trying to retrieve the velocity of the ego vehicle with the function get_ego_as_agent(). However, this only implements the controid, yaw and extend. Is there any way to get the velocity integraded into this function aswell? Or can you hint me to any other way to get the true velocity? I can see from the centroid position, that the vehicle should be moving and I could calculate the approximate speed with use of the timestamps, but I guess that won't be very exact.

Could you please help me with getting the ego speed? Please also let me know, if you need any additional info.

@thversfelt
Copy link

thversfelt commented Mar 4, 2022

This is how I calculate the true (global) velocity:

from l5kit.geometry.transform import transform_point

# The timestep during this frame.
timestep = 0.1

# Get the ego reference system to world reference system transformation matrix.
world_from_ego = data_batch["world_from_agent"][scene_index].cpu().numpy()
        
# Get the current local position of the ego in the scene.
local_position = data_batch["history_positions"][scene_index][0].cpu().numpy()
        
# Transform the position to the world reference system.
position = transform_point(local_position, world_from_ego)

# Get the previous position of the ego in the scene.
previous_local_position = data_batch["history_positions"][scene_index][1].cpu().numpy()
        
# Transform the position to the world reference system.
previous_position = transform_point(previous_local_position, world_from_ego)
        
# Calculate the ego's velocity.
velocity = (position - previous_position) / timestep

Hope it helps :)

@thversfelt
Copy link

Also, if you want to get the speed from the velocity:

# The magnitude of the velocity vector is the speed.
speed = np.linalg.norm(velocity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants