Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 922 Bytes

Follow the centerline.md

File metadata and controls

28 lines (22 loc) · 922 Bytes

Follow the Centerline

Sections the track into three reward zones. The farther the car strays from the centerline, the less it’s rewarded.

def reward_function(params):
    # Example of rewarding the agent to follow the centerline

    # Read input parameters
    track_width = params['track_width']
    distance_from_center = params['distance_from_center']

    # Calculate 3 markers that are at varying distances away from the centerline
    marker_1 = 0.1 * track_width
    marker_2 = 0.25 * track_width
    marker_3 = 0.5 * track_width

    # Give higher reward if the car is closer to the centerline and vice versa
    if distance_from_center <= marker_1:
        reward = 1.0
    elif distance_from_center <= marker_2:
        reward = 0.5
    elif distance_from_center <= marker_3:
        reward = 0.1
    else:
        reward = 1e-3  # likely crashed/close to off track

    return float(reward)