-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActuator.java
More file actions
38 lines (32 loc) · 1.04 KB
/
Actuator.java
File metadata and controls
38 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* This class simulates the behavior of Actuator. It receives the action value from the controller and sends it across to the process.
*/
import java.io.*;
class Actuator implements Runnable {
Physics physics;
private ObjectInputStream in;
Actuator(Physics phy, ObjectInputStream in) {
this.physics = phy;
this.in = in;
}
void init() {
double init_actions[] = new double[physics.NUM_POLES];
for (int i = 0; i < physics.NUM_POLES; i++) {
init_actions[i] = 0.75;
}
physics.update_actions(init_actions);
}
public synchronized void run() {
while (true) {
try {
// read action data from control server
Object obj = in.readObject();
double[] data = (double[]) (obj);
assert(data.length == physics.NUM_POLES);
physics.update_actions(data);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}