Skip to content

Conversation

@eugenevinitsky
Copy link

Accel is being cut in half for no reason

Accel is being cut in half for no reason
@greptile-apps
Copy link

greptile-apps bot commented Nov 13, 2025

Greptile Overview

Greptile Summary

Removed the erroneous 0.5f factor from the acceleration integration in the CLASSIC dynamics model.

  • The CLASSIC dynamics model uses simple Euler integration: speed = speed + acceleration * dt
  • The previous code incorrectly halved the acceleration: speed = speed + 0.5f * acceleration * dt
  • This is distinct from the JERK dynamics model (line 1657), which correctly uses the trapezoidal rule: v_new = signed_v + 0.5f * (a_long_new + agent->a_long) * dt (averaging old and new acceleration)
  • The fix corrects the physics simulation, making vehicles respond with the intended acceleration values defined in ACCELERATION_VALUES (ranging from -4.0 to 4.0 m/s²)

Confidence Score: 5/5

  • This PR is safe to merge - it fixes a clear physics integration bug with no side effects
  • The change corrects an obvious error in the physics simulation. The 0.5 factor was inappropriately applied to simple Euler integration in the CLASSIC dynamics model, effectively halving all acceleration values. This was likely introduced accidentally in commit c5e6b58 (GigaFlow Dynamics) when the JERK model was added, possibly through confusion with the trapezoidal integration used in that model. The fix is minimal, well-scoped, and mathematically correct.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
pufferlib/ocean/drive/drive.h 5/5 Removed erroneous 0.5 factor from acceleration update in CLASSIC dynamics model, correcting the physics integration

Sequence Diagram

sequenceDiagram
    participant Action as Action Input
    participant MD as move_dynamics()
    participant Agent as Agent State
    participant Clip as clipSpeed()
    
    Action->>MD: action_idx (accel, steering)
    MD->>MD: Extract acceleration & steering<br/>from action values
    MD->>Agent: Read current state<br/>(x, y, vx, vy, heading)
    MD->>MD: Calculate speed = sqrt(vx² + vy²)
    MD->>MD: Update speed:<br/>speed = speed + accel * dt
    Note right of MD: Fixed: Was 0.5*accel*dt<br/>Now correctly: accel*dt
    MD->>Clip: clipSpeed(speed)
    Clip-->>MD: clipped_speed
    MD->>MD: Compute yaw_rate using<br/>speed and steering
    MD->>MD: Calculate new velocities<br/>(new_vx, new_vy)
    MD->>MD: Update position:<br/>x += new_vx * dt<br/>y += new_vy * dt<br/>heading += yaw_rate * dt
    MD->>Agent: Write updated state<br/>(x, y, vx, vy, heading)
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@eugenevinitsky eugenevinitsky merged commit c26b245 into main Nov 14, 2025
13 checks passed
@eugenevinitsky eugenevinitsky deleted the eugenevinitsky-patch-1 branch November 14, 2025 02:27
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

Successfully merging this pull request may close these issues.

3 participants