forked from cdthompson/deepracer-k1999-race-lines
-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_reward_full_dubai_open_ccw-1000-4-2024-04-29-145904.py
323 lines (309 loc) · 17.8 KB
/
example_reward_full_dubai_open_ccw-1000-4-2024-04-29-145904.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def get_racing_line_waypoints():
#waypoints will be inserted by the race line calc notebook
return [[ 3.95092851, -3.69079913, 3.95508939, -3.15741547, 3.94676763,
-4.22418279, 3.95092851, -3.69079913],
[ 4.08092403, -3.6918776 , 4.08508492, -3.158494 , 4.07676315,
-4.22526121, 4.09471152, -3.69187952],
[ 4.21092057, -3.6928272 , 4.21508145, -3.15944356, 4.20675968,
-4.22621083, 4.26708466, -3.69301105],
[ 4.38236022, -3.69407952, 4.38573122, -3.16069007, 4.37898922,
-4.22746897, 4.46716131, -3.6942045 ],
[ 4.68379998, -3.69568753, 4.68616199, -3.16229296, 4.68143797,
-4.22908211, 4.7099199 , -3.69545878],
[ 4.98524189, -3.69674945, 4.98695278, -3.16335201, 4.983531 ,
-4.23014688, 4.98989195, -3.69663583],
[ 5.28668547, -3.69762146, 5.28799295, -3.16422296, 5.28537798,
-4.23101997, 5.28653602, -3.69630386],
[ 5.58812833, -3.69822752, 5.58863783, -3.16482806, 5.58761883,
-4.23162699, 5.57991216, -3.68659232],
[ 5.88957238, -3.69819796, 5.88777781, -3.16480088, 5.89136696,
-4.23159504, 5.86039942, -3.65977271],
[ 6.19100904, -3.69620001, 6.18165493, -3.16288209, 6.20036316,
-4.22951794, 6.12109081, -3.61061051],
[ 6.49231291, -3.68762589, 6.45562792, -3.15548897, 6.5289979 ,
-4.2197628 , 6.35655988, -3.53633229],
[ 6.79175901, -3.65479243, 6.69036484, -3.13111806, 6.89315319,
-4.1784668 , 6.5629507 , -3.43642716],
[ 7.08147049, -3.57358301, 6.86156511, -3.08762288, 7.30137587,
-4.05954313, 6.73709344, -3.31142493],
[ 7.33252501, -3.41031945, 6.9403162 , -3.04881191, 7.72473383,
-3.77182698, 6.87403927, -3.16121425],
[ 7.47401094, -3.14833403, 6.96297407, -2.99550509, 7.98504782,
-3.30116296, 6.96663959, -2.98565444],
[ 7.49972034, -2.85015547, 6.97623396, -2.95251489, 8.02320671,
-2.74779606, 7.00015071, -2.78399482],
[ 7.36394691, -2.58431995, 6.91690493, -2.87529993, 7.8109889 ,
-2.29333997, 6.99232989, -2.56858179],
[ 7.17398763, -2.35028195, 6.75859308, -2.68489099, 7.58938217,
-2.01567292, 6.94564599, -2.34288482],
[ 6.98576736, -2.11483604, 6.56440496, -2.44189811, 7.40712976,
-1.78777397, 6.86351962, -2.10997602],
[ 6.80436516, -1.87408853, 6.37719011, -2.19352102, 7.2315402 ,
-1.55465603, 6.74870002, -1.87229006],
[ 6.62472606, -1.63201803, 6.19625521, -1.94971001, 7.05319691,
-1.31432605, 6.60126623, -1.63363713],
[ 6.44528627, -1.389799 , 6.01784277, -1.70887196, 6.87272978,
-1.07072604, 6.42853137, -1.40453879],
[ 6.26408958, -1.1488941 , 5.83928919, -1.47147799, 6.68888998,
-0.82631022, 6.23917499, -1.19437955],
[ 6.08068347, -0.9096649 , 5.65864086, -1.23584902, 6.50272608,
-0.58348078, 6.03841808, -1.00577194],
[ 5.89541698, -0.67187601, 5.47761011, -1.00346804, 6.31322384,
-0.34028399, 5.82927059, -0.83839186],
[ 5.7059145 , -0.4374548 , 5.29788399, -0.78100461, 6.11394501,
-0.093905 , 5.61331877, -0.69191079],
[ 5.50722766, -0.2108255 , 5.12965918, -0.58759791, 5.88479614,
0.1659469 , 5.39153432, -0.56630097],
[ 5.28124356, -0.01185896, 4.97248793, -0.4468137 , 5.5899992 ,
0.42309579, 5.16458445, -0.46178087],
[ 5.01920509, 0.13565019, 4.82663822, -0.36177671, 5.21177197,
0.63307709, 4.93246121, -0.38147229],
[ 4.72664952, 0.20291816, 4.69250584, -0.32938799, 4.76079321,
0.73522431, 4.69526189, -0.32937223],
[ 4.42793393, 0.17358151, 4.55753279, -0.343835 , 4.29833508,
0.69099802, 4.45364948, -0.31124035],
[ 4.15021658, 0.05846509, 4.40884018, -0.40804249, 3.89159298,
0.52497268, 4.21074051, -0.31671627],
[ 3.90516257, -0.11627901, 4.25189114, -0.52161211, 3.55843401,
0.2890541 , 3.96820596, -0.33918117],
[ 3.69444454, -0.3314298 , 4.10540915, -0.67146462, 3.28347993,
0.00860502, 3.72668159, -0.37308124],
[ 3.52287757, -0.5782313 , 3.95871711, -0.885737 , 3.08703804,
-0.27072561, 3.48618176, -0.41425034],
[ 3.3475554 , -0.82308134, 3.73799992, -1.18649399, 2.95711088,
-0.4596687 , 3.25851857, -0.4563168 ],
[ 3.11719096, -1.01441106, 3.3273499 , -1.50466502, 2.90703201,
-0.52415711, 3.03173805, -0.48293769],
[ 2.82346296, -1.04889432, 2.7580719 , -1.57827103, 2.88885403,
-0.5195176 , 2.80805014, -0.47975046],
[ 2.54256952, -0.94230883, 2.30542803, -1.42009497, 2.77971101,
-0.46452269, 2.59555905, -0.42818765],
[ 2.28716701, -0.78262673, 1.981058 , -1.21944797, 2.59327602,
-0.3458055 , 2.39756431, -0.33910791],
[ 2.04977697, -0.59696692, 1.70798695, -1.00647295, 2.39156699,
-0.1874609 , 2.21460221, -0.2201144 ],
[ 1.82463044, -0.39657445, 1.46084797, -0.7866745 , 2.1884129 ,
-0.00647439, 2.04675241, -0.07593308],
[ 1.60901552, -0.18594094, 1.22938704, -0.56063777, 1.988644 ,
0.1887559 , 1.89346056, 0.08952141],
[ 1.401214 , 0.0324149 , 1.00834203, -0.32837209, 1.79408598,
0.39320189, 1.75437155, 0.27372636],
[ 1.20131192, 0.25802 , 0.75179178, -0.02911647, 1.65083206,
0.54515648, 1.62878984, 0.47438717],
[ 1.08334062, 0.52811529, 0.55300528, 0.47101769, 1.61367595,
0.58521289, 1.51563654, 0.68933505],
[ 1.14198229, 0.8214657 , 0.6340726 , 0.98438698, 1.64989197,
0.65854442, 1.4133313 , 0.91632558],
[ 1.26583302, 1.09621689, 0.76189601, 1.27103996, 1.76977003,
0.92139381, 1.31977485, 1.15289243],
[ 1.33831775, 1.38693154, 0.80608749, 1.42224002, 1.87054801,
1.35162306, 1.23278473, 1.39665707],
[ 1.30485621, 1.68480748, 0.79297048, 1.53484595, 1.81674194,
1.83476901, 1.15040326, 1.64553353],
[ 1.17211488, 1.95400941, 0.72147173, 1.66863894, 1.62275803,
2.23937988, 1.0690337 , 1.90190429],
[ 0.98513961, 2.18957096, 0.51553822, 1.93660796, 1.454741 ,
2.44253397, 0.9818879 , 2.15228401],
[ 0.89159447, 2.47442544, 0.36428499, 2.39404798, 1.41890395,
2.55480289, 0.88381773, 2.39084895],
[ 0.89603347, 2.7749635 , 0.36264491, 2.77146792, 1.42942202,
2.77845907, 0.77011565, 2.61123473],
[ 0.88763717, 3.07609499, 0.35983831, 2.99899793, 1.41543603,
3.15319204, 0.63735391, 2.80717658],
[ 0.81039998, 3.36386502, 0.3512339 , 3.09242105, 1.26956606,
3.63530898, 0.48338508, 2.97289129],
[ 0.59585932, 3.56991589, 0.34410751, 3.09966397, 0.84761113,
4.04016781, 0.30621499, 3.10197168],
[ 0.30313905, 3.63471258, 0.25009939, 3.10395598, 0.3561787 ,
4.16546917, 0.10208966, 3.1822727 ],
[ 0.00275667, 3.62911141, 0.09641779, 3.1039989 , -0.09090446,
4.15422392, -0.12105939, 3.21900533],
[-0.28106949, 3.53050542, -0.08685328, 3.03372002, -0.47528571,
4.02729082, -0.35559219, 3.21416456],
[-0.55741185, 3.41007602, -0.34441441, 2.92104912, -0.77040929,
3.89910293, -0.59280805, 3.17070652],
[-0.83380392, 3.28975999, -0.62146789, 2.80044508, -1.04613996,
3.77907491, -0.82530966, 3.09322648],
[-1.11047089, 3.17007804, -0.89990473, 2.67999911, -1.32103705,
3.66015697, -1.04871452, 2.98767156],
[-1.38772553, 3.05176306, -1.17920601, 2.56081009, -1.59624505,
3.54271603, -1.26068661, 2.85844847],
[-1.66538149, 2.934394 , -1.45970404, 2.4422431 , -1.87105894,
3.4265449 , -1.46050258, 2.7096243 ],
[-1.94398451, 2.8192935 , -1.74042797, 2.326262 , -2.14754105,
3.312325 , -1.6482381 , 2.54438895],
[-2.22254407, 2.70435953, -1.92263603, 2.26325798, -2.52245212,
3.14546108, -1.82407488, 2.36494761],
[-2.42921454, 2.49032247, -1.97658598, 2.208112 , -2.88184309,
2.77253294, -1.9874256 , 2.17218429],
[-2.53141403, 2.20784009, -2.01305604, 2.0820601 , -3.04977202,
2.33362007, -2.13703166, 1.96645913],
[-2.57013845, 1.90922749, -2.03789902, 1.874066 , -3.10237789,
1.94438899, -2.27541564, 1.75159128],
[-2.57103348, 1.60792053, -2.03815103, 1.63140404, -3.10391593,
1.58443701, -2.40492483, 1.5305719 ],
[-2.54363441, 1.30783451, -2.01077294, 1.331797 , -3.07649589,
1.28387201, -2.52827818, 1.30590726],
[-2.54398751, 1.00650811, -2.01069808, 0.99564028, -3.07727695,
1.01737595, -2.64812865, 1.07940245],
[-2.555915 , 0.70531955, -2.02335 , 0.67548388, -3.08848 ,
0.73515522, -2.76266818, 0.86009643],
[-2.57770443, 0.40467535, -2.04836392, 0.338992 , -3.10704494,
0.4703587 , -2.88506379, 0.64799867],
[-2.62985647, 0.10895125, -2.13980699, -0.1016842 , -3.11990595,
0.31958669, -3.02244901, 0.44980385],
[-2.80696392, -0.13024795, -2.47253489, -0.54578751, -3.14139295,
0.28529161, -3.18218252, 0.27281392],
[-3.07982254, -0.2527128 , -2.94729209, -0.76938611, -3.21235299,
0.26396051, -3.37409824, 0.12790501],
[-3.37937403, -0.27682261, -3.35243797, -0.80954212, -3.40631008,
0.2558969 , -3.59078177, 0.00927375],
[-3.68074501, -0.28307021, -3.6661129 , -0.81626952, -3.69537711,
0.2501291 , -3.82635977, -0.08837839],
[-3.98201263, -0.29336024, -3.96137404, -0.82636088, -4.00265121,
0.2396404 , -4.07509713, -0.17100399],
[-4.28317332, -0.3063966 , -4.25735378, -0.83917141, -4.30899286,
0.2263782 , -4.33035331, -0.24608395],
[-4.5841825 , -0.32254265, -4.55166006, -0.85495031, -4.61670494,
0.209865 , -4.59202549, -0.32798352],
[-4.88491821, -0.34315486, -4.84418821, -0.87499762, -4.92564821,
0.18868791, -4.85023644, -0.41516505],
[-5.18528509, -0.36857671, -5.13464117, -0.89956713, -5.23592901,
0.1624137 , -5.10393182, -0.50858236],
[-5.48503828, -0.40039261, -5.42129278, -0.92996991, -5.54878378,
0.12918469, -5.35204052, -0.60906989],
[-5.78377342, -0.44061699, -5.69301701, -0.96623939, -5.87452984,
0.08500542, -5.59331297, -0.71752047],
[-6.07855749, -0.50286677, -5.93593597, -1.01684594, -6.22117901,
0.01111241, -5.82614457, -0.83501859],
[-6.363204 , -0.60139593, -6.153193 , -1.09171295, -6.57321501,
-0.1110789 , -6.04854153, -0.96279139],
[-6.63085461, -0.73941924, -6.34907722, -1.19231796, -6.91263199,
-0.28652051, -6.2584017 , -1.1019006 ],
[-6.87291098, -0.91851395, -6.52116919, -1.31950402, -7.22465277,
-0.51752388, -6.4515503 , -1.25471832],
[-7.08201361, -1.13516814, -6.6700201 , -1.47395599, -7.49400711,
-0.79638028, -6.62374047, -1.42272681],
[-7.25425816, -1.38227701, -6.77439022, -1.61517704, -7.73412609,
-1.14937699, -6.76899934, -1.60715871],
[-7.34139347, -1.66906601, -6.82139778, -1.78789604, -7.86138916,
-1.55023599, -6.87980473, -1.80710506],
[-7.38773537, -1.96689993, -6.85950994, -2.04101992, -7.91596079,
-1.89277995, -6.96660621, -2.01447785],
[-7.42515492, -2.2660079 , -6.89554977, -2.32952189, -7.95476007,
-2.20249391, -7.02608182, -2.22765802],
[-7.45952201, -2.56548548, -6.93064022, -2.63476396, -7.9884038 ,
-2.496207 , -7.0543996 , -2.44411715],
[-7.50342798, -2.8635695 , -6.97006989, -2.87027502, -8.03678608,
-2.85686398, -7.0468974 , -2.66005958],
[-7.46728349, -3.16058052, -6.9648962 , -2.98135304, -7.96967077,
-3.33980799, -6.99604447, -2.86911904],
[-7.30739641, -3.41320848, -6.92565298, -3.04066706, -7.68913984,
-3.78574991, -6.89329252, -3.06028769],
[-7.05801153, -3.57969952, -6.83166885, -3.09670401, -7.28435421,
-4.06269503, -6.72751215, -3.21263262],
[-6.76963234, -3.6650691 , -6.67337084, -3.14042711, -6.86589384,
-4.18971109, -6.53121521, -3.33890357],
[-6.46961164, -3.68764687, -6.45449209, -3.15446091, -6.4847312 ,
-4.22083282, -6.30973147, -3.44068439],
[-6.16821861, -3.682096 , -6.17764616, -3.14877892, -6.15879107,
-4.21541309, -6.06684192, -3.51920833],
[-5.86681938, -3.67699099, -5.87545681, -3.14366102, -5.85818195,
-4.21032095, -5.80674027, -3.57703119],
[-5.5654161 , -3.67233312, -5.57326412, -3.13899112, -5.55756807,
-4.20567513, -5.53308776, -3.61701708],
[-5.26400709, -3.6681211 , -5.27106524, -3.13476801, -5.25694895,
-4.20147419, -5.24905532, -3.64220825],
[-4.96259356, -3.66435552, -4.96886206, -3.13099194, -4.95632505,
-4.1977191 , -4.95716253, -3.65538549],
[-4.66117454, -3.66103601, -4.66665316, -3.12766409, -4.65569592,
-4.19440794, -4.66000354, -3.66011656],
[-4.35975051, -3.65816355, -4.36443901, -3.12478399, -4.35506201,
-4.1915431 , -4.35972984, -3.65998904],
[-4.05832148, -3.65573704, -4.0622201 , -3.12235093, -4.05442286,
-4.18912315, -4.05829131, -3.65840177],
[-3.75688744, -3.6537571 , -3.75999594, -3.1203661 , -3.75377893,
-4.18714809, -3.75684954, -3.65710361],
[-3.45544803, -3.65222299, -3.45776701, -3.11882806, -3.45312905,
-4.18561792, -3.45540475, -3.65607477],
[-3.1540041 , -3.65113604, -3.15553308, -3.11773801, -3.15247512,
-4.18453407, -3.15395715, -3.65529925],
[-2.85255444, -3.65049458, -2.8532939 , -3.11709499, -2.85181499,
-4.18389416, -2.85250677, -3.65477662],
[-2.55110002, -3.65030003, -2.55104995, -3.11689997, -2.55115008,
-4.18370008, -2.55105362, -3.65450941],
[-2.24964046, -3.65055144, -2.24880004, -3.11715198, -2.25048089,
-4.1839509 , -2.24959775, -3.65449987],
[-1.94817597, -3.65124953, -1.94654596, -3.11785197, -1.94980597,
-4.18464708, -1.94813924, -3.65474919],
[-1.64670599, -3.65239453, -1.64429998, -3.11899996, -1.64911199,
-4.18578911, -1.64667903, -3.65517128],
[-1.34523147, -3.65397012, -1.34231198, -3.12057805, -1.34815097,
-4.18736219, -1.34521642, -3.65585243],
[-1.0437575 , -3.65569496, -1.04066598, -3.12230396, -1.04684901,
-4.18908596, -1.04375166, -3.65679193],
[-0.74228591, -3.6574645 , -0.739115 , -3.12407398, -0.74545681,
-4.19085503, -0.74228517, -3.65798844],
[-0.44081685, -3.65927899, -0.43756691, -3.12588906, -0.44406679,
-4.19266891, -0.44081763, -3.65943942],
[-0.1393502 , -3.66113853, -0.1360212 , -3.12774897, -0.1426792 ,
-4.1945281 , -0.1393502 , -3.66113853],
[ 0.1621139 , -3.66304207, 0.1655219 , -3.12965298, 0.15870591,
-4.19643116, 0.1621139 , -3.66304207],
[ 0.46357554, -3.66499054, 0.46706259, -3.13160205, 0.46008849,
-4.19837904, 0.46357554, -3.66499054],
[ 0.76503477, -3.66698408, 0.76860082, -3.13359594, 0.76146871,
-4.20037222, 0.76503477, -3.66698408],
[ 1.06649148, -3.66902137, 1.07013702, -3.13563395, 1.06284595,
-4.20240879, 1.06649148, -3.66902137],
[ 1.36794603, -3.67110407, 1.37167001, -3.13771701, 1.36422205,
-4.20449114, 1.36794603, -3.67110407],
[ 1.66939747, -3.67323136, 1.67320096, -3.13984489, 1.66559398,
-4.20661783, 1.66939747, -3.67323136],
[ 1.97084647, -3.67540288, 1.97472894, -3.14201689, 1.96696401,
-4.20878887, 1.97084647, -3.67540288],
[ 2.27229345, -3.67761958, 2.27625489, -3.14423394, 2.268332 ,
-4.21100521, 2.27229345, -3.67761958],
[ 2.5737375 , -3.6798805 , 2.5777781 , -3.14649606, 2.5696969 ,
-4.21326494, 2.5737375 , -3.6798805 ],
[ 2.87517941, -3.68218601, 2.87929893, -3.14880204, 2.87105989,
-4.21556997, 2.87517941, -3.68218601],
[ 3.17661893, -3.68453646, 3.18081689, -3.15115309, 3.17242098,
-4.21791983, 3.17661893, -3.68453646],
[ 3.47805548, -3.68693149, 3.48233795, -3.15354896, 3.473773 ,
-4.22031403, 3.47805548, -3.68693149],
[ 3.77948999, -3.68937683, 3.78386593, -3.15599489, 3.77511406,
-4.22275877, 3.77948999, -3.68937683],
[ 3.95092851, -3.69079913, 3.95508939, -3.15741547, 3.94676763,
-4.22418279, 3.95092851, -3.69079913]]
import numpy as np
def dist(point1, point2):
return ((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) ** 0.5
def get_waypoints_ordered_in_driving_direction(params, waypoints):
# waypoints are always provided in counter clock wise order
if params['is_reversed']: # driving clock wise.
return list(reversed(waypoints))
else: # driving counter clock wise.
return waypoints
def reward_function(params):
'''
Example of being near the nearest racing line
'''
waypoints_input = np.array(get_racing_line_waypoints())
racing_line = waypoints_input[:,6:8]
waypoints = params["waypoints"]
ordered_racing_line = get_waypoints_ordered_in_driving_direction(params, racing_line)
ordered_waypoints = get_waypoints_ordered_in_driving_direction(params, waypoints)
car = [params['x'], params['y']]
distances = [dist(p, car) for p in ordered_waypoints]
min_dist = min(distances)
i_closest = distances.index(min_dist)
#find the distance to the racing line point for the closest waypoint you are at
dist_from_racingline = dist(car, ordered_racing_line[i_closest])
#check for divide by 0 and then limit the reward to between 1 and 0.001 normally
if dist_from_racingline == 0:
#if it is exactly on the racing line give it an extra point
reward = 2
else:
reward = (np.clip(1/dist_from_racingline, 0.01, 10))/10
return reward