You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Unexpected behavior after KeyboardInterrupt #526
Describe the bug KeyboardInterrupt can be used to drop into the REPL, which can be useful for debugging.
The problem is that pbsys_user_program_unprepare is being run before entering the REPL. This resets a few things that shouldn't be reset. For example, it changes the stop button back to the Center button, and does a full reset of the motors via pbio_stop_all.
There's a comment that says we are currently doing this because:
// Need to unprepare, otherwise SystemExit could be raised during print.
pbsys_user_program_unprepare();
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
Is there maybe a way to achieve this without resetting everything else?
It could still be useful to keep some hook there (just not this one), because it is still nice to stop all motors (just not fully reset them).
To reproduce
The more prominent case is with motors, but the stop button case can be demonstrated without:
frompybricks.hubsimportThisHubfrompybricks.toolsimportwaithub=ThisHub()
hub.system.set_stop_button(None)
wait(5000)
raiseKeyboardInterrupt# We drop into the REPL here. Stop button# should still be none, but isn't.
pbio_dcmotor_stop_all(false) will just stop motors but you can continue using them.
pbio_dcmotor_stop_all(true) stops and resets everything.
Currently pbio_stop_all calls the latter, as it should.
But since pbio_stop_all is currently also triggered by user_program_unprepare as explained above, motors can't currently be used after a KeyboardInterrupt.
Button.BLUETOOTH no longer works as stop button after entering REPL
drive_base.drive(500, 0) fails with EPERM because pbio was reset before entering REPL
When starting resources in REPL, >>> left_motor.run(500), it doesn't stop when clicking stop again.
This is easy to fix now because main/stm32 no longer runs in an infinite loop with a goto. Control always yields back to pbsys, so we can do most of the hardware stop/reset there.
Activity
laurensvalk commentedon Nov 11, 2021
This is now solved for motors another way. This actually relies on keepingpbsys_user_program_unpreparethe way it is.And since the button thing isn't all that critical,I think we can keep this as-is for the upcoming releases.pbio/servo: Don't reset connection state on stop.
laurensvalk commentedon Nov 30, 2021
For motors, we now have:
pbio_dcmotor_stop_all(false)will just stop motors but you can continue using them.pbio_dcmotor_stop_all(true)stops and resets everything.Currently
pbio_stop_allcalls the latter, as it should.But since
pbio_stop_allis currently also triggered byuser_program_unprepareas explained above, motors can't currently be used after a KeyboardInterrupt.pbio/servo: Don't reset connection state on stop.
pbio/servo: Don't reset connection state on stop.
pbio/servo: Don't reset connection state on stop.
laurensvalk commentedon Aug 23, 2022
A fix is in progress as part of an extension to pybricks/pybricks-micropython#109
To reproduce current issue:
This has three bugs:
Button.BLUETOOTHno longer works as stop button after entering REPLdrive_base.drive(500, 0)fails with EPERM because pbio was reset before entering REPL>>> left_motor.run(500), it doesn't stop when clicking stop again.This is easy to fix now because
main/stm32no longer runs in an infinite loop with a goto. Control always yields back topbsys, so we can do most of the hardware stop/reset there.pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.
pbsys: Refactor user program start and stop.