You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prevents zig-zag behavior by penalizing steering and encouraging the car to stay close to the centerline.
defreward_function(params):
# Example of penalizing steering, which helps mitigate zig-zag behaviors# Read input parametersdistance_from_center=params['distance_from_center']
track_width=params['track_width']
abs_steering=abs(params['steering_angle']) # Only need the absolute steering angle# Calculate 3 marks that are farther and farther away from the center linemarker_1=0.1*track_widthmarker_2=0.25*track_widthmarker_3=0.5*track_width# Give higher reward if the car is closer to the centerline and vice versaifdistance_from_center<=marker_1:
reward=1.0elifdistance_from_center<=marker_2:
reward=0.5elifdistance_from_center<=marker_3:
reward=0.1else:
reward=1e-3# likely crashed/close to off track# Steering penalty threshold, change the number based on your action space settingABS_STEERING_THRESHOLD=15# Penalize reward if the car is steering too muchifabs_steering>ABS_STEERING_THRESHOLD:
reward*=0.8returnfloat(reward)