-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleLEDPattern_noback_dim.py
184 lines (165 loc) · 6.64 KB
/
SimpleLEDPattern_noback_dim.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
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 21 21:22:19 2019
@author: soenk
"""
import logging
"""
Computing the central LED that has to light up representing the respective car.
veh = Vehicle from the Vehicle-class
step = the angle-"distances" between each pixel
f_pixels = Why is that in there? :D
returns the central pixel as int
"""
def led_position_back(veh, step_back, LED_DEGREES):
return int((veh.e_a - LED_DEGREES/2) / step_back)
"""
Annoyingly written function for a simple LED pattern which is shown for the
front of the LEDs, meaning where the location of the pixel is supposed to
accurately represent the one of the car.
Two aspects are regarded in this pattern: The angle, represented by the
location of the pixel(s) lighting up, as well as the distance to the ego car.
THe latter one is represented by the number of pixels lighting up as well as
how strongly they are lighting up.
"""
def main(vehicles, PIXEL_COUNT, LED_DEGREES):
def led_position_front(veh, step, LED_DEGREES, step_rr, step_r, step_l, step_ll):
logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug(str(veh.e_a))
logging.debug(str(LED_DEGREES/2))
if angle_to_bar_r <= veh.e_a <= LED_DEGREES/2:
relative_ea = veh.e_a
relative_led_degr = (LED_DEGREES/2)
logging.debug('rr ' + str(int(((relative_led_degr) - relative_ea) / step_rr)))
return int(((relative_led_degr) - relative_ea) / step_rr)
elif 0 <= veh.e_a < angle_to_bar_r:
logging.debug('r '+ str(69 + int((angle_to_bar_r - veh.e_a) / step_r)))
return 69 + int((angle_to_bar_r - veh.e_a) / step_r)
elif (360 - angle_to_bar_l) <= veh.e_a <= 360:
logging.debug('l ' + str(103 + int(-(veh.e_a - 360) / step_l)))
return 103 + int(-(veh.e_a - 360) / step_l)
elif (360 - LED_DEGREES/2) <= veh.e_a:
#relative_ea =
#relative_led_degr =
logging.debug('ll' + str(121 + int((-(veh.e_a - 360)-angle_to_bar_l) / step_ll)))
return 121 + int((-(veh.e_a - 360)-angle_to_bar_l) / step_ll)
else:
return None
"""
Change Light unsurprisingly changes a light, well, a pixel.
add_val: value to be added to pixel
f_pixels: the array of front pixels, to be changed
led_pos: The CENTRAL pixel of the car-representation
led_ord: The order of the value, so +- around the central pixel.
Returns the changed front pixel array
"""
def change_light(add_val, f_pixels, c_pixels, led_pos, led_ord, dist):
def change_c_pix(c_pix, pos):
if c_pix[pos] == 0 or c_pix[pos] > dist:
c_pix[pos] = dist
return c_pix
if add_val <= 0:
return f_pixels, c_pixels
elif add_val >= 1:
if led_ord == 0:
try:
f_pixels[led_pos] = 1
c_pixels = change_c_pix(c_pixels, led_pos)
except IndexError:
pass
return f_pixels, c_pixels
else:
try:
f_pixels[led_pos + led_ord] += 1
c_pixels = change_c_pix(c_pixels, led_pos + led_ord)
except IndexError:
pass
try:
f_pixels[led_pos - led_ord] += 1
c_pixels = change_c_pix(c_pixels, led_pos - led_ord)
except IndexError:
pass
return f_pixels, c_pixels
else:
if led_ord == 0:
try:
f_pixels[led_pos] += add_val
c_pixels = change_c_pix(c_pixels, led_pos)
except IndexError:
pass
return f_pixels, c_pixels
else:
try:
f_pixels[led_pos + led_ord] += add_val
c_pixels = change_c_pix(c_pixels, led_pos + led_ord)
except IndexError:
pass
try:
f_pixels[led_pos - led_ord] += add_val
c_pixels = change_c_pix(c_pixels, led_pos - led_ord)
except IndexError:
pass
return f_pixels, c_pixels
# Noof pixels representing back of car on every side
b_pixels = 0
# Noof front pixels can be calculated from all of the parameters
f_pixels = PIXEL_COUNT - b_pixels * 2
# Pixel vector for the front pixels
pix_vec = [0] * f_pixels
pix_vec_back = [0] * (2 * b_pixels)
color_vec_f = [0] * f_pixels
# The distance, from which on a car is represented on the screen
threshold = 200
angle_to_bar_r = 55
angle_to_bar_l = 35
#
step = LED_DEGREES / f_pixels
step_rr = (LED_DEGREES/2 - angle_to_bar_r) / 69
step_r = angle_to_bar_r / 34
step_l = angle_to_bar_l / 18
step_ll = (LED_DEGREES/2 - angle_to_bar_l) / 71
#step_back = (360 - LED_DEGREES) / (2 * b_pixels)
led_pref = [
[200, 60],
[150, 45],
[100, 30],
[60, 20],
[30, 10],
[18, 0]
]
vehicles.pop(0)
for i in vehicles:
if i.e_d <= threshold and i.e_d > 0:
led_c = led_position_front(i, step, LED_DEGREES, step_rr, step_r, step_l, step_ll)
if led_c != None:
bright_list = []
for j in led_pref:
bright_list.append((j[0] - i.e_d) / (j[0] - j[1]))
print(bright_list)
for j in range(len(bright_list)):
"""
bright_list j =
pix vec = Total vectors of pixels used for LED strip
ledc = the central LED position
j = diversion from ledc
"""
pix_vec, color_vec_f = change_light(bright_list[j], pix_vec, color_vec_f, led_c, j, i.e_d)
"""
else:
led_c = led_position_back(i, step_back, LED_DEGREES)
bright_list = []
for j in led_pref:
bright_list.append((j[0] - i.e_d) / (j[0] - j[1]))
for j in range(len(bright_list)):
pix_vec_back = change_light(bright_list[j], pix_vec_back, led_c, j)
"""
"""
pix_vec_b_r = pix_vec_back[:b_pixels]
pix_vec_b_r.reverse()
pix_vec_b_l = pix_vec_back[b_pixels:]
pix_vec_b_l.reverse()
"""
vec_vec = [[], pix_vec, []]
col_vec = [[], color_vec_f, []]
print(vec_vec)
return vec_vec, col_vec