On 20.12.2010, at 20:25, John Hoare wrote: > Here's the more complicated use case, we provide a "VideoStream" object, > which will create a window, and constantly update it with the current > display from the robot. > > VideoStream vs(robot); > vs.startStream(); // Non-blocking, creates an image window and allows > // user to continue > > robot.move(...); // Or do whatever > robot.move(...); > > vs.endStream(); // Closes VideoStream window > > > This is really the reason why I have everything in the threads, for the > videostream object. Likewise, users should also be able to show() an > image while a videostream window also exists.
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 _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

