Added example reward functions.
This commit is contained in:
33
reward-example-prevent-zig-zag.py
Normal file
33
reward-example-prevent-zig-zag.py
Normal file
@ -0,0 +1,33 @@
|
||||
def reward_function(params):
|
||||
'''
|
||||
Example of penalize steering, which helps mitigate zig-zag behaviors
|
||||
'''
|
||||
|
||||
# Read input parameters
|
||||
distance_from_center = params['distance_from_center']
|
||||
track_width = params['track_width']
|
||||
steering = abs(params['steering_angle']) # Only need the absolute steering angle
|
||||
|
||||
# Calculate 3 marks that are farther and father away from the center line
|
||||
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 center line 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
|
||||
|
||||
# Steering penality threshold, change the number based on your action space setting
|
||||
ABS_STEERING_THRESHOLD = 15
|
||||
|
||||
# Penalize reward if the car is steering too much
|
||||
if steering > ABS_STEERING_THRESHOLD:
|
||||
reward *= 0.8
|
||||
|
||||
return float(reward)
|
||||
Reference in New Issue
Block a user