This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated README, updated base reward func, updated startup/stop script…
…s, default track now reinvent_base
- Loading branch information
Showing
7 changed files
with
97 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,25 @@ | ||
def reward_function(params): | ||
''' | ||
Example of rewarding the agent to stay inside two borders | ||
and penalizing getting too close to the objects in front | ||
Example of rewarding the agent to follow center line | ||
''' | ||
|
||
all_wheels_on_track = params['all_wheels_on_track'] | ||
distance_from_center = params['distance_from_center'] | ||
# Read input parameters | ||
track_width = params['track_width'] | ||
objects_distance = params['objects_distance'] | ||
_, next_object_index = params['closest_objects'] | ||
objects_left_of_center = params['objects_left_of_center'] | ||
is_left_of_center = params['is_left_of_center'] | ||
|
||
# Initialize reward with a small number but not zero | ||
# because zero means off-track or crashed | ||
reward = 1e-3 | ||
distance_from_center = params['distance_from_center'] | ||
|
||
# Reward if the agent stays inside the two borders of the track | ||
if all_wheels_on_track and (0.5 * track_width - distance_from_center) >= 0.05: | ||
reward_lane = 1.0 | ||
# Calculate 3 markers that are at varying distances 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_lane = 1e-3 | ||
|
||
# Penalize if the agent is too close to the next object | ||
reward_avoid = 1.0 | ||
|
||
# Distance to the next object | ||
distance_closest_object = objects_distance[next_object_index] | ||
# Decide if the agent and the next object is on the same lane | ||
is_same_lane = objects_left_of_center[next_object_index] == is_left_of_center | ||
|
||
if is_same_lane: | ||
if 0.5 <= distance_closest_object < 0.8: | ||
reward_avoid *= 0.5 | ||
elif 0.3 <= distance_closest_object < 0.5: | ||
reward_avoid *= 0.2 | ||
elif distance_closest_object < 0.3: | ||
reward_avoid = 1e-3 # Likely crashed | ||
|
||
# Calculate reward by putting different weights on | ||
# the two aspects above | ||
reward += 1.0 * reward_lane + 4.0 * reward_avoid | ||
reward = 1e-3 # likely crashed/ close to off track | ||
|
||
return reward | ||
return float(reward) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters