Skip to content

Commit f644caa

Browse files
added camera and temporal data support
1 parent 7282d35 commit f644caa

2 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/HL/Car.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ def has_Crashed(self):
142142
def main(self):
143143
# récupération des données du lidar. On ne prend que les 1080 premières valeurs et on ignore la dernière par facilit" pour l'ia
144144

145-
lidar_data = self.lidar.rDistance[:1080]
146-
angle, vitesse = self.driving(lidar_data)
145+
lidar_data = self.lidar.rDistance
146+
raise NotImplementedError("Camera data is not implemented")
147+
camera_data = ...
148+
angle, vitesse = self.driving(lidar_data, camera_data)
147149
self.set_direction_degre(angle)
148150
self.set_vitesse_m_s(vitesse)
149151
if self.has_Crashed():
@@ -155,7 +157,7 @@ def main(self):
155157
log.basicConfig(level=log.INFO)
156158
bp2 = Button("GPIO6")
157159
try:
158-
Schumacher = Driver()
160+
Schumacher = Driver(128, 128)
159161
GR86 = Car(Schumacher.ai)
160162
log.info("Initialisation terminée")
161163
if input("Appuyez sur D pour démarrer ou tout autre touche pour quitter") in ("D", "d") or bp2.is_pressed:

src/HL/Driver.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import math
2+
import scipy as sp
23
from scipy.special import softmax
34
import numpy as np
45
import onnxruntime as ort
@@ -8,19 +9,49 @@
89

910

1011
class Driver:
11-
def __init__(self):
12+
def __init__(self, context_size, horizontal_size):
1213
self.ai_session = ort.InferenceSession(MODEL_PATH)
13-
14+
self.context = np.zeros([2, context_size, horizontal_size], dtype=np.float32)
15+
1416
def omniscent(self, lidar_data, camera_data):
1517
pass
16-
17-
def ai(self, lidar_data):
18-
return self.ai_update_lidar(lidar_data)
19-
18+
19+
def ai(self, lidar_data, camera_data):
20+
return self.ai_update_lidar_camera(lidar_data, camera_data)
21+
2022
def simple_minded(self, lidar_data):
2123
return self.farthest_distants(lidar_data)
22-
24+
25+
def ai_update_lidar_camera(self, lidar_data, camera_data):
26+
lidar_data = sp.ndimage.zoom(
27+
np.array(lidar_data, dtype=np.float32),
28+
128/len(lidar_data)
29+
)
30+
camera_data = sp.ndimage.zoom(
31+
np.array(camera_data, dtype=np.float32),
32+
128/len(camera_data)
33+
)
34+
35+
self.context = np.concatenate([
36+
self.context[:, 1:],
37+
[lidar_data[None], camera_data[None]]
38+
], axis=1)
39+
40+
# 2 vectors direction and speed. direction is between hard left at index 0 and hard right at index 1. speed is between min speed at index 0 and max speed at index 1
41+
vect = self.ai_session.run(None, {'input': self.context})[0][0]
42+
43+
vect_dir, vect_prop = vect[:16], vect[16:] # split the vector in 2
44+
vect_dir = softmax(vect_dir) # distribution de probabilité
45+
vect_prop = softmax(vect_prop)
46+
47+
angle = sum(SPEED_LOOKUP*vect_dir) # moyenne pondérée des angles
48+
# moyenne pondérée des vitesses
49+
vitesse = sum(ANGLE_LOOKUP*vect_prop)
50+
51+
return angle, vitesse
52+
2353
def ai_update_lidar(self, lidar_data):
54+
raise NotImplementedError("This method doesn't work anymore")
2455
lidar_data = np.array(lidar_data, dtype=np.float32)
2556
# 2 vectors direction and speed. direction is between hard left at index 0 and hard right at index 1. speed is between min speed at index 0 and max speed at index 1
2657
vect = self.ai_session.run(None, {'input': lidar_data[None]})[0][0]
@@ -88,5 +119,5 @@ def farthest_distants(self, lidar_data):
88119
print("error calculating angle:", e)
89120
else:
90121
steering_angle = 0
91-
92-
return steering_angle, speed
122+
123+
return steering_angle, speed

0 commit comments

Comments
 (0)