-
Notifications
You must be signed in to change notification settings - Fork 0
/
car_main.py
executable file
·54 lines (38 loc) · 1.08 KB
/
car_main.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
from easygopigo3 import EasyGoPiGo3
from curve_detection import get_lane_curve
import webcam
import movement
from time import sleep
GPG = EasyGoPiGo3()
port = "AD2"
sensor = GPG.init_ultrasonic_sensor(port)
sensor.set_safe_distance(120)
def car_main():
img_vid = webcam.get_vid(display=False)
curve_val = get_lane_curve(img_vid, 0)
sensitivity = 0.35 # Sensitivity for Left turns
speed = 0.35
if curve_val > 0:
sensitivity = 0.35 # Sensitivity for Right turns
if curve_val < 0.05:
curve_val = 0
else:
if curve_val > -0.05:
curve_val = 0
total_curve = curve_val * sensitivity
print(total_curve)
movement.direction(speed, total_curve, 0.05)
### For use with a working Ultrasonic Sensor ###
# if sensor.is_too_close() == True:
# Usensor = 0
# sleep(0.1)
# else:
# Usensor = 1
# sleep(0.1)
# if Usensor == 1:
# Movement.stop
# else:
# Movement.direction (speed,total_curve,0.05)
if __name__ == '__main__':
while True:
car_main()