forked from ranenbg/Arduino-FFB-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph_class.pde
157 lines (150 loc) · 3.93 KB
/
Graph_class.pde
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
class Graph {
float x;
float y;
int gs;
int ps;
float pointX;
float pointY;
Graph(float posx, float posy, int graphsize, int pointsize) {
x = posx;
y = posy;
gs = graphsize;
ps = pointsize;
}
void update() {
}
void show() {
int value = floor(map(Axis[0], -1, 1, 0, xAxis_log_max-1));
pushMatrix();
translate(x-gs/2, y-gs/2);
fill(128, 255, 255);
text("Y = AX + BXX + CXXX", 4, 15);
pushMatrix();
pushMatrix();
fill(96, 255, 255);
translate(gs-50, 45);
rotate(-PI/4);
text("Y = X", 0, 0);
popMatrix();
translate(gs/2, -gs/2);
for (int i=-gs/2; i<=gs/2; i++) {
pointX = i;
if (lfs_compensation == 0.0) {
pointY = gs*(1-(correct_axis (float(i)/(gs/2))/real_wheelTurn));
} else {
pointY = gs*(1-(correct_axis (float(i)/(gs/2))/lfs_wheelTurn));
}
ellipseMode(CENTER);
fill(128, 255, 255, 200);
noStroke();
ellipse(pointX, pointY, ps, ps); // graph points
}
stroke(127);
int Ypos = int (correct_axis(Axis[0])/real_wheelTurn*axisScale*2);
line(-gs/2, gs-Ypos, gs/2, gs-Ypos); // horisontal 0 line
int Xpos = int (Axis[0]*axisScale);
line(Xpos, gs/2, Xpos, gs/2+gs); // vertical 0 line
stroke(96, 255, 255, 200);
line(-gs/2, gs+gs/2, gs/2, gs/2); // diagonal (linear or 1:1) line
popMatrix();
noFill();
strokeWeight(1);
stroke(255);
rectMode(CORNER);
rect(0, 0, gs, gs); // graph frame
popMatrix();
// graph X axis
axisValue = Axis[0]*real_wheelTurn/2;
level = axisValue/real_wheelTurn*axisScale;
pushMatrix();
translate(x-axisScale, y+axisScale+17);
rotate(PI/2);
float n = axisScale/10.0;
float m = n/5.0;
for (int i = 0; i > -20; i--) {
for (int j = 0; j > -5; j--) {
line(0, i*n, 10, i*n);
line(0, j*m + i*n, 5, j*m + i*n);
}
}
line(0, -20*n, 10, -20*n);
fill(255);
pushMatrix();
translate(0, -axisScale);
rotate(-PI/2);
text(value, -4, 25);
text(axisValue, axisScale-50, 25);
popMatrix();
popMatrix();
// graph X axis arrow
pushMatrix();
beginShape();
translate(x, y+axisScale); // center of ruler axisScale
//rotate(-PI/2);
translate(level*2, 2); // moving along the ruler
int hg = 0;
fill(hg, 255, 255);
strokeWeight(1);
stroke(255);
vertex(-4, hg+0);
vertex(4, hg+0);
vertex(4, hg+5);
vertex(6, hg+5);
vertex(0, hg+12);
vertex(-6, hg+5);
vertex(-4, hg+5);
endShape();
popMatrix();
/*print(value);
print(" ");
print(a);*/
// graph Y axis
pushMatrix();
axisValue = correct_axis(Axis[0]);
level = axisValue/real_wheelTurn*axisScale;
translate(x+axisScale+17, y+axisScale);
//float n = axisScale/10;
//float m = n/5;
for (int i = 0; i > -20; i--) {
for (int j = 0; j > -5; j--) {
line(0, i*n, 10, i*n);
line(0, j*m + i*n, 5, j*m + i*n);
}
}
line(0, -20*n, 10, -20*n);
fill(255);
//text(value, 0, -(2*n+1)*10);
//text(axisValue, 0, 20);
text(axisValue, 20, -(2*n)*10+4);
float minlock = -axisScale+float(lfs_car_wheelTurn)/float(real_wheelTurn)*axisScale;
float maxlock = -minlock -axisScale*2;
strokeWeight(3);
stroke(128, 255, 255);
line(14, minlock, 20, minlock); // min lock limit (red)
line(14, maxlock, 20, maxlock); // max lock limit (green)
strokeWeight(1);
popMatrix();
// graph Y axis arrow
pushMatrix();
beginShape();
translate(x+axisScale/2+2, y); // center of ruler axisScale
rotate(-PI/2);
translate(level*2, 0); // moving along the ruler
hg = 128;
fill(hg, 255, 255);
strokeWeight(1);
stroke(255);
vertex(-4, hg+0);
vertex(4, hg+0);
vertex(4, hg+5);
vertex(6, hg+5);
vertex(0, hg+12);
vertex(-6, hg+5);
vertex(-4, hg+5);
endShape();
popMatrix();
/*print(value);
print(" ");
print(a);*/
}
}