-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhighbeam_main.py
More file actions
executable file
·70 lines (53 loc) · 1.85 KB
/
highbeam_main.py
File metadata and controls
executable file
·70 lines (53 loc) · 1.85 KB
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
#!/usr/bin/env python
import os
import time
import timer
import camera_interface
import car_interface
import unique_file_name
import subprocess
if __name__ == "__main__":
capture_state_params = [
(5.0,"off"), #0 - Out 0, In 0 - highbeams off for a while
(0.0,"on_edge"), #1 - Out 0, In 1 - highbeams just requested to turn on
(0.0,"off_edge"), #2 - Out 1, In 0 - highbeams just requested to turn off
(5.0,"on") #3 - Out 1, In 1 - highbeams on for a while
]
base_path = "/media/pi/highbeamUSB"
with \
camera_interface.CameraInterface() as cam, \
car_interface.CarInterface() as car:
highbeam_input = car.getHighbeamInput()
highbeam_output = highbeam_input
highbeam_delay_timer = timer.Timer()
capture_delay_timer = timer.Timer()
while True:
if car.getShutdownInput():
subprocess.call("sudo shutdown -h now", shell=True)
print("shutdown")
highbeam_input = car.getHighbeamInput()
switch_input = car.getSwitchInput()
#detect changes in the highbeam_input and reset the delay timer
if highbeam_input == highbeam_output:
highbeam_delay_timer.reset()
#[off delay, on delay]
if highbeam_delay_timer() > [3.0,5.0][highbeam_input]:
highbeam_output = highbeam_input
#Outputs
car.setHighbeamOutput(highbeam_output)
#there are 4 combinations of highbeam inputs and outputs.
state = 2*highbeam_output + highbeam_input
capture_delay_time,rel_path = capture_state_params[state]
if capture_delay_timer() > capture_delay_time and switch_input:
capture_delay_timer.reset()
try:
if os.path.isdir(base_path):
path = os.path.join(base_path,rel_path)
if not os.path.isdir(path):
os.mkdir(path)
fileName = unique_file_name.getUniqueFileName(path,"img_%05i.png")
print(fileName)
cam.capture(fileName)
except:
pass
time.sleep(0.0333)