| Literature DB >> 22163674 |
Gonzalo Farias1, Anton Cervin, Karl-Erik Arzén, Sebastián Dormido, Francisco Esquembre.
Abstract
This paper introduces a new Open Source Java library suited for the simulation of embedded control systems. The library is based on the ideas and architecture of TrueTime, a toolbox of Matlab devoted to this topic, and allows Java programmers to simulate the performance of control processes which run in a real time environment. Such simulations can improve considerably the learning and design of multitasking real-time systems. The choice of Java increases considerably the usability of our library, because many educators program already in this language. But also because the library can be easily used by Easy Java Simulations (EJS), a popular modeling and authoring tool that is increasingly used in the field of Control Education. EJS allows instructors, students, and researchers with less programming capabilities to create advanced interactive simulations in Java. The paper describes the ideas, implementation, and sample use of the new library both for pure Java programmers and for EJS users. The JTT library and some examples are online available on http://lab.dia.uned.es/jtt.Entities:
Keywords: Easy Java Simulations; TrueTime; control education; embedded control systems; virtual labs
Mesh:
Year: 2010 PMID: 22163674 PMCID: PMC3231210 DOI: 10.3390/s100908585
Source DB: PubMed Journal: Sensors (Basel) ISSN: 1424-8220 Impact factor: 3.576
Figure 1.A virtual lab built with EJS and JTT. Three inverted pendulums controlled by three periodic controllers running on the same computer.
Figure 2.Schedule plot: three periodic tasks are running on the same CPU, tasks 1 and 3 have the highest and lowest priority respectively. Up arrows in a task plot indicate the released times of that task, down arrows indicate the task finish times. The initials R, P, and S indicate the possible states of the tasks. Note that the task 1 is never pre-empted.
Figure 3.TrueTime code model. The execution of task code (or user code) is modelled by a sequence of code segments that are executed in sequence by the kernel.
Figure 4.Main classes in the JTT package.
Original simulation
| 1 | |
| 2 | |
| 3 | |
| 4 | . . . |
| 5 | } |
| 6 | |
| 7 | |
| 8 | . . . |
| 9 | } |
| 10 | |
| 11 | |
| 12 | |
| 13 | MyProcess process = |
| 14 | |
| 15 | process . step (dt); |
| 16 | time += dt; |
| 17 | |
| 18 | . . . |
| 19 | } |
| 20 | } |
Modified simulation, version 1.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | . . . |
| 6 | |
| 7 | Task task1 = |
| 8 | task1.setPeriod (0.08); |
| 9 | task1.setPriority Value (0) |
| 10 | |
| 11 | task1.addCode ( |
| 12 | |
| 13 | |
| 14 | . . . |
| 15 | |
| 16 | } |
| 17 | }); |
| 18 | . . . |
| 19 | |
| 20 | Task task2 = |
| 21 | task2.set Period (0.1); |
| 22 | task2.set PriorityValue (1) |
| 23 | |
| 24 | . . . |
| 25 | |
| 26 | Kernel kernel = |
| 27 | kernel.setScheduling Policy (Kernel.FP); |
| 28 | kernel.addTask (task1); |
| 29 | kernel.addTask (task2); |
| 30 | |
| 31 | RTenv.add Kernel (kernel); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | . . . |
| 36 | } |
| 37 | |
| 38 | |
| 39 | |
| 40 | MyProcess process = |
| 41 | |
| 42 | |
| 43 | |
| 44 | process.step (nextEvent−time); |
| 45 | RTenv.runKernel ( ); |
| 46 | time = nextEvent; |
| 47 | } |
| 48 | process.step (dt); |
| 49 | time += dt; |
| 50 | } |
| 51 | |
| 52 | . . . |
| 53 | } |
| 54 | } |
Modified simulation, version 2.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | RTenv.setReflectionContext ( |
| 7 | . . . |
| 8 | |
| 9 | . . . |
| 10 | |
| 11 | task.addCode (“mycode”); |
| 12 | |
| 13 | . . . |
| 14 | } |
| 15 | . . . |
| 16 | |
| 17 | |
| 18 | |
| 19 | . . . |
| 20 | RTenv.endSegment (0.3); |
| 21 | . . . |
| 22 | |
| 23 | . . . |
| 24 | RTenv.endSegment (0.1); |
| 25 | } |
| 26 | } |
Figure 5.Diagram of an embedded control system simulation with JTT. Kernel simulation is provided by JTT, Solver and View have to be programmed or facilitated by other Java tools like EJS.
Modified simulation, version 3.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | Task task = |
| 7 | task.setPeriod (0.012); |
| 8 | |
| 9 | task.addCode ( |
| 10 | |
| 11 | controlAction = calculate (reference, output); |
| 12 | |
| 13 | } |
| 14 | }); |
| 15 | task.addCode ( |
| 16 | |
| 17 | input = controlAction; |
| 18 | |
| 19 | } |
| 20 | }); |
| 21 | |
| 22 | } |
| 23 | |
| 24 | |
| 25 | rate [0] = state [ |
| 26 | rate [ |
| 27 | rate [ |
| 28 | } |
| 29 | |
| 30 | |
| 31 | getRate (state, rates1); |
| 32 | |
| 33 | k1 [i]= state [i]+ stepSize * rates 1 [i]/2.0; |
| 34 | getRate (k1, rates 2); |
| 35 | |
| 36 | k2 [i]= state [i]+ stepSize * rates 2 [i]/2.0; |
| 37 | getRate (k2, rates 3); |
| 38 | |
| 39 | k3 [i]= state [i]+ stepSize*rates3 [i]; |
| 40 | getRate (k3, rates4); |
| 41 | |
| 42 | state [i]= state [i]+stepSize*(rates1[i]+2*rates2[i]+2*rates3[i]+rates4[i])/6.0; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | P = Kp*(beta*r−y); I = Iold; D = Td/(N*h+Td)*Dold+N*Kp*Td/(N*h+Td)*(yold−y); |
| 47 | Iold = Iold + Kp*h/Ti*(r−y); Dold = D; yold = y; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | . . . |
| 52 | } |
Creation of the kernel and task in EJS.
| 1 | |
| 2 | RTenv.setReflectionContext ( |
| 3 | kernel = |
| 4 | kernel.setSchedule ( |
| 5 | kernel.setScheduleWindow (0.5); |
| 6 | task = |
| 7 | task.setPeriod (0.012); |
| 8 | task.addCode (“taskcode”); |
| 9 | kernel.addTask (task); |
| 10 | RTenv.addKernel (kernel); |
The method ”taskcode” used by the periodic task
| 1 | |
| 2 | |
| 3 | output =x1; |
| 4 | |
| 5 | controlAction = calculate (reference, output); |
| 6 | RTenv.endSegment (executionTime); |
| 7 | |
| 8 | input = controlAction; |
| 9 | RTenv.endSegment (0); |
| 10 | } |
Figure 6.Ordinary differential equations of the model system using the editor of EJS. The ODE models are defined in the section Evolution in EJS.
Getting the schedule data of the task.
| 1 | . . . |
| 2 | // ******* |
| 3 | taskSchet=task.getSchedule (“time”); |
| 4 | taskSchev=task.getSchedule (“value”); |
| 5 | points = taskSchev.length; |
| 6 | . . . |
Figure 7.Section View of the EJS. Elements on the right are provided by EJS to build the tree-like structure on the left, which describes the GUI of the simulation of Figure 8.
Figure 8.GUI of the virtual lab developed using the JTT-EJS approach.