When relying on the same bumper to trigger multiple events, all events trigger instantly even though a timer is used
def start(): wait_until_bumper_is_pressed(perception) control.start_robot() control.stand_up() if perception.is_upper_camera_used(): perception.use_lower_camera()
def shutdown(): control.sit_down() control.turn_motors_off()
def perform_until_bumper_is_pressed(function, *args):
while not perception.is_left_bumper_pressed () and
not perception.is_right_bumper_pressed ():
function(args)
time.sleep(INPUT_SLEEP_TIME)
def count_until_bumper_is_pressed(perception):
"""
Waits until one of the bumpers are pressed
:param perception: the perception object that is used to sense
"""
wait_time = 0.0
while not perception.is_left_bumper_pressed () and
not perception.is_right_bumper_pressed ():
time.sleep(INPUT_SLEEP_TIME)
wait_time = wait_time + INPUT_SLEEP_TIME
return wait_time
def calibrate_1_meter(): start() wait_until_bumper_is_pressed(perception) time.sleep(1) control.walk_forward(0.5) time_taken = count_until_bumper_is_pressed(perception) control.stop() print(str(time_taken)) control.say_blocking(str(time_taken)) shutdown()