Page 52 - Designing Autonomous Mobile Robots : Inside the Mindo f an Intellegent Machine
P. 52
The Basics of Real-time Software (For Mere Mortals)
build the necessary protection into the object itself rather than exposing public
variables.
Visual Basic and real-time controls
It is obviously beyond the scope of this book to attempt to address the basics of
Visual Basic programming. There are many fine reference books on the subject, but
they do not generally talk about real-time considerations, so I will try to provide
some useful insights here. Although Visual Basic (VB) is not a true real-time lan-
guage, it is a remarkably easy-to-use object-oriented language that can do a very
impressive job of faking real-time operations. To understand how this can be done,
consider how VB and Windows switch tasks.
VB events
VB depends upon events to allocate CPU time to different tasks. These events are
somewhat different from those used by conventional kernels in that most are more
software in nature as opposed to being interrupt driven. The operating system main-
tains a list of all the possible events that could occur at any given time. VB does have
OnComm Events that support basic serial communications interrupts, as well as
other events that are linked to hardware interrupts, but on the whole, most events
are software generated.
For example, as a program posts a form on the screen with controls (buttons, sliders,
etc.), the events that have been programmed for the controls are added to the list of
possible events. If the mouse is then clicked, for example, the operating system will
evaluate the cursor position to see if it is over an active control, and whether there
is a procedure listed for clicking that control. If there is a procedure for the control,
and if the control is enabled, then the procedure is called (executed).
DoEvents
The mouse itself may generate interrupts as it is moved, but under Windows, these
do not elicit macro-events. The operating system instead simply stores away the
position of the cursor. This cursor information only gets accessed and evaluated, and
action taken, when the operating system has control of the CPU. But if the inter-
rupt did not provide this control to the operating system through an interrupt, then
how did it get control? The answer is that all well-behaved programs must release
control to the operating system on a frequent basis.
35

