Hello,
I wrote a simple lua script that bangs the servos back and forth in a
while loop, for stress testing. To prevent our (flying) robot from
crashing when a user reflexively hits Ctrl-C, I have a signal handler
set up in one of our components to trap that, so I can't just break
out of the while loop with Ctrl-C.
I googled it, and lua does not provide keyboard handling in it's
standard library.
I know about state rfsm state machines library that could probably be
used, but it is probably overkill for trivial scripts like this.
What is a good way to terminate my while loop in this situation?
Note, I'm still a lua newb... maybe the standard library has
lightweight threads or something that will return control to the
interpreter or something, and I just don't know about it...
Thanks,
Andrew
rttlua keyboard handling?
On Do, Nov 14, 2013 at 02:56:43 +0100, Andrew Wagner wrote:
>Hello,
>
>I wrote a simple lua script that bangs the servos back and forth in a
>while loop, for stress testing. To prevent our (flying) robot from
>crashing when a user reflexively hits Ctrl-C, I have a signal handler
>set up in one of our components to trap that, so I can't just break
>out of the while loop with Ctrl-C.
>
>I googled it, and lua does not provide keyboard handling in it's
>standard library.
>
>I know about state rfsm state machines library that could probably be
>used, but it is probably overkill for trivial scripts like this.
>
>What is a good way to terminate my while loop in this situation?
>
>Note, I'm still a lua newb... maybe the standard library has
>lightweight threads or something that will return control to the
>interpreter or something, and I just don't know about it...
You probably can find some lua ncurses (or alike) library to do
non-blocking io from the keyboard to end your loop.
Alternatively, just create a LuaComponent, add a periodicActivity and
run your your servo-banging script in it's updateHook. Then you can just
use the deployer of your choice to run start() and stop() to turn it on
and off.
Markus
rttlua keyboard handling?
Banging around, I found a lighter solution:
If it's safe to kill your program, and you're using linux, you can use
the shell's flow control:
Ctrl-S can stop the application, then Ctrl-C is able to kill it, even
if your C++ code is trapping SIGINT, apparently.