Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ dmypy.json
# Cython debug symbols
cython_debug/

# ROAR competition run instrumentation
competition_code/telemetry/runs/
experiment_results/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
Expand Down
42 changes: 42 additions & 0 deletions competition_code/LateralController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import numpy as np
import math


def normalize_rad(rad: float):
return rad % (2 * np.pi)


class LatController:
def run(self, vehicle_location, vehicle_rotation, next_waypoint) -> float:
"""
Calculates the steering command using the pure pursuit algorithm.

Args:
vehicle_location (np.array): Current vehicle location [x, y].
vehicle_rotation (float): Current vehicle rotation (yaw) in radians.
next_waypoint (Waypoint): Next waypoint to track.

Returns:
steering_command (float): Steering command in radians.
"""

# Calculate vector pointing from vehicle to next waypoint
waypoint_vector = np.array(next_waypoint.location) - np.array(vehicle_location)

# Project waypoint vector onto heading vector to find lookahead point
distance_to_waypoint = np.linalg.norm(waypoint_vector)
if distance_to_waypoint == 0:
return 0 # Prevent division by zero

waypoint_vector_normalized = waypoint_vector / distance_to_waypoint

# Calculate steering command
alpha = normalize_rad(vehicle_rotation[2]) - normalize_rad(
math.atan2(waypoint_vector_normalized[1], waypoint_vector_normalized[0])
)

steering_command = 1.5 * math.atan2(
2.0 * 4.7 * math.sin(alpha) / distance_to_waypoint, 1.0
)

return float(steering_command)
9 changes: 9 additions & 0 deletions competition_code/SpeedData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SpeedData:
def __init__(
self, distance_to_section, current_speed, target_speed, recommended_speed
):
self.current_speed = current_speed
self.distance_to_section = distance_to_section
self.target_speed_at_distance = target_speed
self.recommended_speed_now = recommended_speed
self.speed_diff = current_speed - recommended_speed
Loading