def do_left_sharp_turn(): driver.stop() driver.reset() driver.lr(-SHARP_TURN, SHARP_TURN, TURNING_SPEED) driver.block() driver.reset() driver.lr(FORWARD_SPEED, FORWARD_SPEED, FORWARD_SPEED) driver.block()
def centralize_axis(): driver.reset() driver.stop_action = 'hold' driver.lr(5, 5, 3) max_val, pos = 0, (0, 0) while driver.running(): val = 100 - ls.value() if val > max_val: max_val = val pos = driver.position driver.lr(*pos, speed=3) driver.block()
def fine_centralize(): driver.reset() driver.stop_action = 'hold' driver.lr(-circ / 6, circ / 6, FC_SPEED) pos, error = (0, 0), 100 while driver.running(): _, _, _, l, r, _, _, _ = lsa.values() new_error = abs(l - r) if new_error > error + 10: break if (l > T or r > T) and new_error < error: error = new_error pos = driver.position driver.lr(*pos, speed=FC_SPEED) return pos, error
def crossing(): right = 0 left = 0 back = 0 for i in range(10): detected_green = [i.is_green() for i in cs] if detected_green == [True, True]: back += 1 elif detected_green == [True, False]: left += 1 elif detected_green == [False, True]: right += 1 print(left, right, back) if left > 8: driver.stop() driver.reset() driver.lr(rs["color sensor y"], rs["color sensor y"], FORWARD_SPEED) driver.block() driver.reset() driver.lr(-SHARP_TURN, SHARP_TURN, TURNING_SPEED) driver.block() driver.reset() driver.lr(0.5, 0.5, FORWARD_SPEED) elif right > 8: driver.stop() driver.reset() driver.lr(rs["color sensor y"], rs["color sensor y"], FORWARD_SPEED) driver.block() driver.reset() driver.lr(SHARP_TURN, -SHARP_TURN, TURNING_SPEED) driver.block() driver.reset() driver.lr(0.5, 0.5, FORWARD_SPEED) elif back > 8: driver.stop() driver.reset() driver.lr(rs["color sensor y"], rs["color sensor y"], FORWARD_SPEED) driver.stop() driver.reset() driver.lr(2 * SHARP_TURN, -2 * SHARP_TURN, TURNING_SPEED)