drivetrain.set_drive_velocity(speed, PERCENT)
drivetrain.drive(REVERSE)
elapsed = 0.0 # ← FIX: initialize elapsed here
# FIX: Define start_time and elapsed BEFORE the while loop
start_time = round(float(brain.timer.time(SECONDS)),1)
wall_hit = False
log(“safe driving”)
while True:
# FIX: Update elapsed at the TOP of every loop iteration
# # --- Check bumper (wall hit) ---
# if bumper.pressing():
# drivetrain.stop(BRAKE)
# brain.screen.print("Wall hit! Stopping.")
# brain.screen.next_row()
# wall_hit = True
# break
# # --- Check encoder distance ---
# left_deg = abs(left_motor.position(DEGREES))
# right_deg = abs(right_motor.position(DEGREES))
# avg_deg = (left_deg + right_deg) / 2.0
# if avg_deg >= target_deg:
# drivetrain.stop(BRAKE)
# brain.screen.print("Distance reached.")
# brain.screen.next_row()
# break
# --- Safety timeout ---
elapsed = round(float(brain.timer.time(SECONDS)),1)
actual_time = elapsed - start_time
log(actual_time)
if actual_time >= timeout_sec:
drivetrain.stop(BRAKE)
brain.screen.print("Timeout. Stopping.")
brain.screen.next_row()
break
wait(20, MSEC)
return not wall_hit
The above python code does not move the robot after lifting the beam with 4 pins. what could be reason