1 |
import jtt.*; // Import the JTT package
|
2 |
public class MyProcess { |
3 |
// Initialize the process
|
4 |
public MyProcess ( ) { |
5 |
. . . |
6 |
// create a task
|
7 |
Task task1 = new Task ( ); |
8 |
task1.setPeriod (0.08); // period 80 ms
|
9 |
task1.setPriority Value (0) // Top priority
|
10 |
// add code to a task
|
11 |
task1.addCode (new CodeSegment ( ) { |
12 |
// code of the first segment
|
13 |
public double code ( ) { |
14 |
. . . |
15 |
return 0.03; // execution time
|
16 |
} |
17 |
}); |
18 |
. . . |
19 |
// create another task
|
20 |
Task task2 = new Task ( ); |
21 |
task2.set Period (0.1); // period 100 ms
|
22 |
task2.set PriorityValue (1) // priority
|
23 |
// add code to another task
|
24 |
. . . |
25 |
// create kernel and add it the tasks
|
26 |
Kernel kernel = new Kernel ( ) |
27 |
kernel.setScheduling Policy (Kernel.FP); |
28 |
kernel.addTask (task1); |
29 |
kernel.addTask (task2); |
30 |
// add the kernel to the real time environment
|
31 |
RTenv.add Kernel (kernel); |
32 |
} |
33 |
// Step the process for an increment of time
|
34 |
public void step (double dt) { |
35 |
. . . |
36 |
} |
37 |
// Simulate the process
|
38 |
static public void main (String [] args) { |
39 |
double time = 0, tFinal = 1.0, dt = 0.001; |
40 |
MyProcess process = new MyProcess ( ); |
41 |
while (time <tFinal) { |
42 |
double nextEvent = RTenv.nextEvent ( ); |
43 |
if (nextEvent <time + dt) { |
44 |
process.step (nextEvent−time); |
45 |
RTenv.runKernel ( ); |
46 |
time = nextEvent; |
47 |
} else { |
48 |
process.step (dt); |
49 |
time += dt; |
50 |
} |
51 |
// output process variables
|
52 |
. . . |
53 |
} |
54 |
} // end of class
|