-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-12.py
More file actions
38 lines (28 loc) · 792 Bytes
/
Copy path7-12.py
File metadata and controls
38 lines (28 loc) · 792 Bytes
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
#!/usr/bin/env pybricks-micropython
from common import *
import _thread
flg = 0
def detect_line(m, cs, lk):
global flg
m.run(360)
while True:
if cs.color() == Color.BLACK:
break
m.stop(Stop.BRAKE)
lk.acquire()
flg = flg + 1
lk.release()
return
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
left_color_sensor = ColorSensor(Port.S2)
right_color_sensor = ColorSensor(Port.S3)
lock = _thread.allocate_lock()
_thread.start_new_thread(detect_line, (left_motor, left_color_sensor, lock))
_thread.start_new_thread(detect_line, (right_motor, right_color_sensor, lock))
while flg < 2:
pass
wheel_diameter = 56
axle_track =123
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
robot.drive_time(0, 180, 500)