> Especially with a robot, it seems to me that all the action that controls the > robot should be in a separate thread, probably even with a higher priority. I > wrote a robotics simulator and controller many years back, and here is what I > did: > > The main program creates all the UI elements it may need later. This takes > the load of the CPU later when the robot is running. > > Then I fork a thread that does all the simulation. It keeps time, watches the > sensors, calculates the movement, and then controls the servos. It runs at 50 > or 60Hz using interrupts from the underlying OS. At the same time, the main > thread sits idle in Fl::run() while the main window remains open. > > Whenever the user interacts with the UI, the UI uses teh OS's Critical > Section implementation to write commands into a FIFO which the robot thread > clears every 60th of a second. That way, I can make the robot walk from the > console, for example. > > Now whenever the robot thread needs to tell the UI something, it can do so by > calling Fl::awake(do_something_callback, data). This call is explicitly made > to start actions in the UI thread from any other thread. 'data' contains a > pointer to whatever data is available. Be it a photo or new images from a > video stream. > > More details are here: > > http://www.fltk.org/doc-1.3/advanced.html > > - Matthias
I feel that I should also mention that the "robot" in question is essentially a toy, and this library in question is used for students who have never written code before. (Introduction to Computer Science). The user of the library (the CS1 student) writes their own main() function, and doesn't care about how the GUI works, other than it works. If I can't get away with having Fl::wait() in its own thread, can I do it within a signal handler/timer? Perhaps maybe it would be better to follow Greg Ercolano's suggestion, and fork() off another binary that handles the videoStream(), and communicates to it through a pipe. -John _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

