-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmission_5_11.py
55 lines (42 loc) · 1.69 KB
/
submission_5_11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Trained with OG DeepRacer car using Shanghai Sudu Training Track
## Top Evaluation on AWS Summit Raceway
## 00:00:35.457 100% Lap complete
## 00:00:37.045 100% Lap complete
import math
def reward_function(params):
'''
Example of rewarding the agent to stay inside the two borders of the track
'''
# Read input parameters
all_wheels_on_track = params['all_wheels_on_track']
distance_from_center = params['distance_from_center']
track_width = params['track_width']
steering = abs(params['steering_angle'])
direction_stearing=params['steering_angle']
speed = params['speed']
waypoints = params['waypoints']
closest_waypoints = params['closest_waypoints']
heading = params['heading']
# Give a very low reward by default
reward = 1e-8
# Give a high reward if no wheels go off the track and
# the agent is somewhere in between the track borders
if all_wheels_on_track and (0.5*track_width - distance_from_center) >= 0.05:
reward = 1.0
if all_wheels_on_track:
reward *= 1e-8
next_point = waypoints[closest_waypoints[1]]
prev_point = waypoints[closest_waypoints[0]]
track_direction = math.atan2(next_point[1] - prev_point[1], next_point[0] - prev_point[0])
track_direction = math.degrees(track_direction)
# Penalize the reward if the difference is too large
direction_diff = abs(track_direction - heading)
DIRECTION_THRESHOLD = 5.0
malus=1
if direction_diff > DIRECTION_THRESHOLD:
malus=1-(direction_diff/50)
if malus<0 or malus>1:
malus = 0
reward *= malus
# Always return a float value
return float(reward)