-
Notifications
You must be signed in to change notification settings - Fork 0
/
obst_avoid.py
47 lines (39 loc) · 946 Bytes
/
obst_avoid.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
import picar_4wd as fc
import time, math
import threading
from speed import Speed
from picar_4wd.servo import Servo
from picar_4wd.pwm import PWM
import cv2
speed = 20
def reset_servo(angle1):
ser = Servo(PWM("P0"))
ser.set_angle(angle1)
def main():
reset_servo(-65)
while True:
#reset_servo(-65)
scan_list = fc.scan_step(25)
if not scan_list:
continue
tmp = scan_list[3:7]
print(tmp)
if tmp == [2,2,2,2]:
fc.forward(speed)
# reset_servo(-65)
else:
fc.stop()
time.sleep(0.5)
fc.backward(100)
time.sleep(0.5)
fc.stop()
time.sleep(0.5)
fc.turn_right(50)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("stopped by User")
# ctrl+c
finally:
fc.stop()