-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPendulum.java
More file actions
159 lines (133 loc) · 3.56 KB
/
Pendulum.java
File metadata and controls
159 lines (133 loc) · 3.56 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Pendulum {
public int pole_id; // ID of the pole
public double init_pos; // initial position
public double pos, posDot, angle, angleDot;
public double prevAngle, angleDDot, posDDot;
public double action = 0.75;
public final double cartMass = 1.;
public final double poleMass = 0.1;
public final double poleLength = 1.;
public final double forceMag = 30.;
public final double fricCart = 0.00005;
public final double fricPole = 0.005;
public final double totalMass = cartMass + poleMass;
public final double halfPole = 0.5 * poleLength;
public final double poleMassLength = halfPole * poleMass;
public final double fourthirds = 4. / 3.;
public final double cartWidth = 0.4; // for UI and collision detecion
double tau_sim;
int tau_phy_ms;
PoleState poleState = PoleState.NORMAL;
public Pendulum(int id, double init_pos) {
this.pole_id = id;
this.init_pos = init_pos;
this.pos = init_pos;
}
int get_id() {
return pole_id;
}
void update_pos(double pos) {
synchronized (this) {
this.pos = pos;
}
}
double get_pos() {
synchronized (this) {
return this.pos;
}
}
void update_posDot(double posDot) {
synchronized (this) {
this.posDot = posDot;
}
}
double get_posDot() {
synchronized (this) {
return this.posDot;
}
}
void update_posDDot(double posDDot) {
synchronized (this) {
this.posDDot = posDDot;
}
}
double get_posDDot() {
synchronized (this) {
return this.posDDot;
}
}
void update_angle(double angle) {
synchronized (this) {
this.angle = angle;
}
}
double get_angle() {
synchronized (this) {
return this.angle;
}
}
void update_angleDot(double angleDot) {
synchronized (this) {
this.angleDot = angleDot;
}
}
double get_angleDot() {
synchronized (this) {
return this.angleDot;
}
}
void update_angleDDot(double angleDDot) {
synchronized (this) {
this.angleDDot = angleDDot;
}
}
double get_angleDDot() {
synchronized (this) {
return this.angleDDot;
}
}
void update_prevAngle(double prevAngle) {
synchronized (this) {
this.prevAngle = prevAngle;
}
}
double get_prevAngle() {
synchronized (this) {
return this.prevAngle;
}
}
void update_action(double action) {
synchronized (this) {
this.action = action;
}
}
double get_action() {
synchronized (this) {
return this.action;
}
}
PoleState get_poleState() {
synchronized (this) {
return this.poleState;
}
}
void update_poleState(PoleState state) {
synchronized (this) {
this.poleState = state;
}
}
/**
* This method resets the pole position values.
*/
public void resetPole() {
this.update_pos(this.init_pos);
this.update_posDot(0.);
this.update_angle(0.);
this.update_angleDot(0.);
}
}