06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2. Fundamentals<br />

1. Remove the loop statement around the control algorithm and the waiting<br />

for next sample to simply get a function computing one new control<br />

output based on one single input event.<br />

2. Connect some external timer hardware generating periodic time events<br />

to the program. This is built into so called micro-controller chips, and<br />

available on (almost) any computer board. The timer should be set up<br />

to expire often enough to obtain good control, but seldom enough not to<br />

waste CPU time. (To find an appropriate value is a control engineering<br />

task which is not covered.)<br />

However, such an interrupt/event-driven technique does not scale up very<br />

well. Imagine a control computer handling many control loops with different<br />

sampling periods, that would require non-standard timer hardware, and the<br />

dispatching of timer events would be troublesome. Further disadvantages will<br />

be mentioned below. Thus, event processing as a general mechanism is mainly<br />

useful when developing user interfaces or computing functions that can run to<br />

completion and return whenever triggered (by time, mouse clicks, etc.). Here<br />

we also need other more powerful concepts.<br />

2.4.2 Time and encapsulation<br />

The main limitation with purely event-driven software is that the processing<br />

must be completed immediately not to delay processing of the subsequent<br />

events. When the required computing takes to long time to complete, we need<br />

some means to schedule to work to be done. For instance, the user pushing<br />

a button in a web-based application may results in a request for information<br />

to be downloaded via Internet. Clearly, we need some means to let the event<br />

handler start (or give data to) an ongoing activity taking care of the loading.<br />

That activity then needs to be interruptible by other events, and possibly by<br />

more important ongoing activities issued by those events.<br />

Another reason that we need ongoing, and interruptible, activities is software<br />

quality. It is fundamental both within OOP and programming in general<br />

to keep information locally whenever possible, and to let the program clearly<br />

express the task to be performed. Consider a control loop such as the temperature<br />

control of the LEGO-brick machine. Putting the control statements<br />

(including timing requirements) in a loop within a method of the control object<br />

is clearly better than having the timing requirements registered in one<br />

part of the program and the control actions coded in another part. So again,<br />

we want to be able to express our computations and control algorithms in an<br />

object-oriented manner as we are used to, and have a run-time system that<br />

takes care of scheduling the different activities.<br />

In Java applets the event handling is performed in functions like action<br />

and handleEvent, whereas ongoing activities are (or at least should be) done<br />

24 2012-08-29 16:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!