Prod
This commit is contained in:
parent
d680fc0dfd
commit
9836e6058f
13
main.py
13
main.py
@ -36,10 +36,10 @@ def move_to_light():
|
|||||||
is_facing_light = False
|
is_facing_light = False
|
||||||
while not is_facing_light:
|
while not is_facing_light:
|
||||||
offset = light_sensor_1.read_u16() - light_sensor_2.read_u16()
|
offset = light_sensor_1.read_u16() - light_sensor_2.read_u16()
|
||||||
if offset > 100 and cur_deg > 0:
|
if offset > 50 and cur_deg > 0:
|
||||||
cur_deg = cur_deg - 1
|
cur_deg = cur_deg - 1
|
||||||
servo(cur_deg)
|
servo(cur_deg - 5)
|
||||||
elif offset < -100 and cur_deg < 180:
|
elif offset < -50 and cur_deg < 180:
|
||||||
cur_deg = cur_deg + 1
|
cur_deg = cur_deg + 1
|
||||||
servo(cur_deg)
|
servo(cur_deg)
|
||||||
else:
|
else:
|
||||||
@ -58,20 +58,21 @@ while True:
|
|||||||
while reset_button.value() == 1:
|
while reset_button.value() == 1:
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
led.high()
|
led.high()
|
||||||
|
continue
|
||||||
diff = light_sensor_1.read_u16() - light_sensor_2.read_u16()
|
diff = light_sensor_1.read_u16() - light_sensor_2.read_u16()
|
||||||
run_avg = shift_array(run_avg, diff)
|
run_avg = shift_array(run_avg, diff)
|
||||||
if calibrate_button.value() == 1:
|
if calibrate_button.value() == 1:
|
||||||
cal_threshold = int((light_sensor_1.read_u16() + light_sensor_2.read_u16()) / 2) - 50
|
cal_threshold = int((light_sensor_1.read_u16() + light_sensor_2.read_u16()) / 2) - 25
|
||||||
while calibrate_button.value() == 1:
|
while calibrate_button.value() == 1:
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
if light_sensor_1.read_u16() > cal_threshold and light_sensor_2.read_u16() > cal_threshold:
|
if cal_threshold == 0 or (light_sensor_1.read_u16() > cal_threshold and light_sensor_2.read_u16() > cal_threshold):
|
||||||
continue
|
continue
|
||||||
num_over = 0
|
num_over = 0
|
||||||
first_iter = True
|
first_iter = True
|
||||||
sign = True
|
sign = True
|
||||||
for i in run_avg:
|
for i in run_avg:
|
||||||
cur_num = i
|
cur_num = i
|
||||||
if abs(cur_num) > 150:
|
if abs(cur_num) > 75:
|
||||||
if first_iter:
|
if first_iter:
|
||||||
if cur_num >= 0:
|
if cur_num >= 0:
|
||||||
sign = True
|
sign = True
|
||||||
|
Loading…
Reference in New Issue
Block a user