Replies: 6 comments
-
This is currently not possible for technical reasons. The way ev3dev works would need to be changed. Some related discussion: ev3dev/ev3dev#794. |
Beta Was this translation helpful? Give feedback.
-
Okay, so you wrote there:
from ev3dev import ev3
if __name__ == "__main__":
try:
ev3.interrupt_on_back_button()
# init other stuff
while True:
# do stuff
except:
# thing to do that sould happen, when the button was pressed
# just make something to go back into your program would that be correct? or is it just something that I overread that would prevent this? Also I'd love to see these changes done in ev3dev so that this would be possible. |
Beta Was this translation helpful? Give feedback.
-
So my FLL kids have this large program that does all of their "runs" and controls the whole thing via a master control program so they don't need to "exit" to Brick Man during their competition. Occasionally, things go wrong and they want to "stop a run", without exiting their "master control" program (because relaunching takes a long time while the clock is ticking). I'm looking for a solution I can point them at that doesn't involve littering their code with checks against some global state. If the "back" button on the EV3 were to raise a catchable exception, that would be a very elegant solution for them. Their "master control" program could simply try each of the "runs" and catch the exception if it were thrown. But alas, apparently that is not yet an option. Any other suggestions? |
Beta Was this translation helpful? Give feedback.
-
There is an experimental So maybe you could do something like this (untested)? from pybricks.experimental import run_parallel
# if this is true, it means we are running a mission
running = False
...
def cancel_button_monitor():
while not any(ev3.buttons.pressed()):
wait(100)
if not running:
return
throw RuntimeError("canceled")
def run_1():
# mission run 1
try:
...
finally:
global running
running = False
def run_2():
# mission run 2
try:
...
finally:
global running
running = False
def master_control():
while True:
# get input
...
try:
global running
if selected == 1:
running = True
run_parallel(run_1, cancel_button_monitor)
elif selected == 2:
running = True
run_parallel(run_2, cancel_button_monitor)
catch Exception as ex:
print("error during run:")
print(ex)
finally:
# stop all motors here
... If a button is pressed during a run, the |
Beta Was this translation helpful? Give feedback.
-
Pybricks never disappoints! We'll give it a try and report back. Only concern is that they have some pretty tight loops in a few places (scanning for lines at high speed, line follows, etc.). Presumably running something like cancel_button_monitor() every 100ms wouldn't impact any of that... |
Beta Was this translation helpful? Give feedback.
-
I forgot, there is a file |
Beta Was this translation helpful? Give feedback.
-
Describe the solution you'd like
I think it would be useful to be able to use the back-button on the ev3 brick in your programs too. I thought of a method that would stop it from exiting the program and give it it's own entry in brick.buttons.pressed()
Describe alternatives you've considered
Just an idea for a possible feature.
Additional context
I would love to use a discrete back-button for some menus and stuff, I'm trying to do on the display
Beta Was this translation helpful? Give feedback.
All reactions