-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample16.html
791 lines (670 loc) · 34.2 KB
/
example16.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
<!DOCTYPE html>
<meta charset=utf8>
<html>
<head>
<title>Example with potentiometer</title>
</head>
<body onload="load();">
<div>
<canvas id="canvas1" width="200" height="100" style="border: 1px dashed #00c3c3;"></canvas>
<canvas id="canvas4" width="200" height="100" style="border: 1px dashed #00c3c3;"></canvas>
<br>
<canvas id="canvas2" width="200" height="100" style="border: 1px dashed #00c3c3;"></canvas>
<canvas id="canvas5" width="200" height="100" style="border: 1px dashed #00c3c3;"></canvas>
<br>
<canvas id="canvas3" width="200" height="100" style="border: 1px dashed #00c3c3;"></canvas>
<canvas id="canvas6" width="200" height="100" style="border: 1px dashed #00c3c3;"></canvas>
<br>
</div>
<p></p>
pCoeff: <input id="pCoeff" value="0.1" size="5" />
<button id="buttonStartControlAlgorithm1" onClick="startControlAlgorithm1();">Start Ctrl Alg1</button>
<button id="buttonStopControlAlgorithm" onClick="stopControlAlgorithm();">Stop Ctrl Alg</button>
<p></p>
Kp: <input id="Kp1" value="0.15" size="5" />
Ki: <input id="Ki1" value="0.0055" size="5" />
Kd: <input id="Kd1" value="0.25" size="5" />
<button id="buttonStartControlAlgorithm2" onClick="startControlAlgorithm2();">Start Ctrl Alg2</button>
<button id="buttonStopControlAlgorithm" onClick="stopControlAlgorithm();">Stop Ctrl Alg</button>
<p></p>
Kp: <input id="Kp2" value="0.5" size="5" />
Ki: <input id="Ki2" value="0.008" size="5" />
Kd: <input id="Kd2" value="0.35" size="5" />
<button id="buttonStartControlAlgorithm3" onClick="startControlAlgorithm3();">Start Ctrl Alg3</button>
<button id="buttonStopControlAlgorithm" onClick="stopControlAlgorithm();">Stop Ctrl Alg</button>
<p></p>
FSpos1: <input id="FSpos1" value="125" size="5" />
FSpos2: <input id="FSpos2" value="25" size="5" />
<button id="buttonStartControlAlgorithm4" onClick="startControlAlgorithm4();">Start Ctrl Alg4</button>
<button id="buttonStopControlAlgorithm" onClick="stopControlAlgorithm();">Stop Ctrl Alg</button>
<div id="divForStaticPrint"> </div>
<p></p>
<div id="divForPrint"></div>
<br>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var potValue1 = 0; // value of the first potentiometer
var potValue2 = 0; // value of the second potentiometer
var x1 = new Array(); // array for x1
var y1 = new Array(); // array for y1
var x2 = new Array(); // array for x2
var y2 = new Array(); // array for y2
var x3 = new Array(); // array for x3 variable
var y3 = new Array(); // array for y3 variable
var canvas1;
var canvas2;
var ctx1;
var ctx2;
var pwm;
var FSpos1 = document.getElementById("FSpos1").value;
var FSpos2 = document.getElementById("FSpos2").value;
// variable for P part
var x4 = new Array(); // array for x4 variable
var y4 = new Array(); // array for y4 variable
var canvas4;
var ctx4;
// variable for I part
var x5 = new Array(); // array for x5 variable
var y5 = new Array(); // array for y5 variable
var canvas5;
var ctx5;
// variable for D part
var x6 = new Array(); // array for x6 variable
var y6 = new Array(); // array for y6 variable
var canvas6;
var ctx6;
function load() { // function that is started, when we open the page
canvas1 = document.getElementById("canvas1");
ctx1 = canvas1.getContext("2d");
canvas2 = document.getElementById("canvas2");
ctx2 = canvas2.getContext("2d");
// initialization for canvas3
canvas3 = document.getElementById("canvas3");
ctx3 = canvas3.getContext("2d");
// initialization for canvas4
canvas4 = document.getElementById("canvas4");
ctx4 = canvas4.getContext("2d");
// initialization for canvas5
canvas5 = document.getElementById("canvas5");
ctx5 = canvas5.getContext("2d");
// initialization for canvas6
canvas6 = document.getElementById("canvas6");
ctx6 = canvas6.getContext("2d");
// initialization of first graph
for (var i = 0; i < 200; i++) {
x1[i] = i; // for x values are 0, 1, 2, ...
y1[i] = 0; // for y values are 0
};
// initializaion of second graph
for (var i = 0; i < 200; i++) {
x2[i] = i; // x2 values are 0, 1, 2, ...
y2[i] = 0; // for y2 values are 0
};
// initialization of xy3 variables
for (var i = 0; i < 200; i++) {
x3[i] = i; // x values are 0, 1, 2, ...
y3[i] = 0; // for y values are 0
};
// initialize fourth graph arrays
for (var i = 0; i < 200; i++) {
x4[i] = i; // for x values are 0, 1, 2, ...
y4[i] = 0; // for y values are 0
};
// initialize fifth graph arrays
for (var i = 0; i < 200; i++) {
x5[i] = i; // for x values are 0, 1, 2, ...
y5[i] = 0; // for y values are 0
};
// initialize sixth graph arrays
for (var i = 0; i < 200; i++) {
x6[i] = i; // for x values are 0, 1, 2, ...
y6[i] = 0; // for y values are 0
};
};
var divForPrint = document.getElementById("divForPrint");
// var for printing messages
var numberOfLinesInLog = 20; // variable for the number of lines in log div
var counterOfLogs = 0; // variable for counting the logs
function log(msg) { // function to print messages to div with implemented scroll
var node = document.createElement("tr"); // we create variable node as tr (table row)
var textnode = document.createTextNode(counterOfLogs + " | " + msg); // create elem. with text
node.appendChild(textnode); // add to "node", i.e. table row
divForPrint.insertBefore(node, divForPrint.childNodes[0]); // insert into variable divForPrint -> document.getElementById("divForPrint");
if (counterOfLogs > numberOfLinesInLog - 1) { // if there are more numbers as e.g. 10
divForPrint.removeChild(divForPrint.childNodes[numberOfLinesInLog]); // remove the oldest printout
}
counterOfLogs = counterOfLogs + 1; // increase the counter of logs
}
var socket = io.connect("localhost:8080"); // connect via socket
socket.on("messageToClient", function (msg) {
log(msg); // add msg to div
});
socket.on("staticMsgToClient", function (msg) { // when we recive static message
document.getElementById("divForStaticPrint").innerHTML = "Status: " + msg; // we print to div
});
socket.on("clientReadValues", function (value) {
potValue1 = value.desiredValue;
potValue2 = value.actualValue;
pwm = parseInt((value.pwm).toFixed(0), 10);
// Draw graph No1 *****************************************
ctx1.lineWidth = "1";
ctx1.strokeStyle = "#ff0000";
ctx1.clearRect(0, 0, canvas1.width, canvas1.height); // clear the canvas
// add legend to graph
ctx1.font = "11px Arial";
ctx1.fillText("Desired", 70, 10);
ctx1.beginPath(); // beginning of the short line for the legend
ctx1.lineTo(50, 6);
ctx1.lineTo(65, 6);
ctx1.stroke();
ctx1.font = "11px Arial";
ctx1.fillText("Actual", 140, 10);
ctx1.strokeStyle = "#00ff00";
ctx1.beginPath(); // beginning of the short line for the legend
ctx1.lineTo(120, 6);
ctx1.lineTo(135, 6);
ctx1.stroke();
// add axis labels
ctx1.fillText("<-" + 0 + "|" + 200 + "->", 150, 100 - 5); // display no. of points on x-axis
// min on y-axis label
ctx1.fillText(1023, 5, 11);
ctx1.fillText(0, 5, 100 - 5);
ctx1.strokeStyle = "#ff0000";
ctx1.beginPath(); // to start drawing new line
y1.splice(0, 1); // on the position 0 in the field y1 we erase one value
y1[199] = potValue1; // new value is added at the end
for (var i = 0; i < 200; i++) {
ctx1.lineTo(x1[i], (100 - (y1[i] / 1023) * 100)); // 0,0 x,y coordinate is in upper left corner
};
ctx1.stroke(); // to draw the line
// End of draw graph No1 ***********************************
// Draw graph No2 *****************************************
ctx1.strokeStyle = "#00ff00"; // green line
ctx1.beginPath(); // to start drawing new line
y2.splice(0, 1); // on the position 0 in the field y2 we erase one value
y2[199] = potValue2; // new value is added at the end
for (var i = 0; i < 200; i++) {
ctx1.lineTo(x2[i], (100 - (y2[i] / 1023) * 100)); // 0,0 x,y coordinate is in upper left corner
};
ctx1.stroke(); // to draw the line
// End of draw graph No2 ***********************************
// Draw graph No3 on canvas2 *****************************************
ctx2.lineWidth = "1";
ctx2.clearRect(0, 0, canvas2.width, canvas2.height); // clear the canvas
// draw centerline at 0
ctx2.strokeStyle = "#add8e6";
ctx2.beginPath(); // draw centerline at 0
ctx2.lineTo(0, 50); // starting point
ctx2.lineTo(200, 50); // ending point
ctx2.stroke();
// add legend to graph
ctx2.font = "11px Arial";
ctx2.fillText("PWM", 70, 10);
ctx2.strokeStyle = "#0000ff";
ctx2.beginPath(); // beginning of the short line for the legend
ctx2.lineTo(50, 6);
ctx2.lineTo(65, 6);
ctx2.stroke();
ctx2.strokeStyle = "#0000ff";
ctx2.beginPath(); // to start drawing new line
y3.splice(0, 1); // on the position 0 in the field y we erase one value
y3[199] = pwm; // new value is added at the end
for (var i = 0; i < 200; i++) {
ctx2.lineTo(x3[i], (100 - (255 + y3[i]) / 510 * 100)); // 0,0 x,y coordinate is in upper left corner
};
ctx2.stroke(); // to draw the line
// add axis labels
ctx2.fillText("<-" + 0 + "|" + 200 + "->", 150, 100 - 5); // display no. of points on x-axis
// min on y-axis label
ctx2.fillText(255, 5, 11);
ctx2.fillText(-255, 5, 100 - 5);
// End of draw No3 on canvas2 ***********************************
// Draw canvas3 as X **********************************************
ctx3.clearRect(0, 0, canvas3.width, canvas3.height); // clear canvas only ONCE!
// draw X
ctx3.lineWidth = "1";
ctx3.strokeStyle = "#add8e6";
ctx3.beginPath(); // beginning of the line
ctx3.lineTo(10, 10); // starting point
ctx3.lineTo(190, 90); // ending point
ctx3.stroke(); // to put it on the graph
ctx3.beginPath(); // beginning of the line
ctx3.lineTo(10, 90); // starting point
ctx3.lineTo(190, 10); // ending point
ctx3.stroke(); // to put it on the graph
// Draw canvas3 END ************************************
// Draw canvas4 graph for P part **********************************************
ctx4.clearRect(0, 0, canvas4.width, canvas4.height); // clear canvas only ONCE!
var newvalue = 0;
var range = 35;
// draw line at coordinate 0
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#000000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100, 0); // starting point
ctx4.lineTo(100, 100); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#000000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(0, 90); // starting point
ctx4.lineTo(200, 90); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#000000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(95, 10); // starting point
ctx4.lineTo(105, 10); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 - FSpos2 / range * 100, 90); // starting point
ctx4.lineTo(100, 10); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(FSpos2 / range * 100 + 100, 90); // starting point
ctx4.lineTo(100, 10); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#00ff00"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 - FSpos2 / range * 100, 10); // starting point
ctx4.lineTo(100, 90); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#00ff00"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 - FSpos2 / range * 100, 10); // starting point
ctx4.lineTo(0, 10); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#0000ff"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(FSpos2 / range * 100 + 100, 10); // starting point
ctx4.lineTo(100, 90); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#0000ff"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(FSpos2 / range * 100 + 100, 10); // starting point
ctx4.lineTo(200, 10); // ending point
ctx4.stroke(); // to put it on the graph
var errvalue = value.err * range / FSpos2 * 2;
if (errvalue < -FSpos2 / range * 100 / 4) {
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#00ff00"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = 80 / (FSpos2 / range * 100) * (errvalue + FSpos2 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = -80 / (FSpos2 / range * 100) * (errvalue) + 10;
if (errvalue > 0)
newvalue = 90;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
} else {
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = -80 / (FSpos2 / range * 100) * (errvalue) + 10;
if (errvalue > 0)
newvalue = 90;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#00ff00"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = 80 / (FSpos2 / range * 100) * (errvalue + FSpos2 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
}
if (errvalue > FSpos2 / range * 100 / 4) {
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#0000ff"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = -80 / (FSpos2 / range * 100) * (errvalue - FSpos2 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = 80 / (FSpos2 / range * 100) * (errvalue) + 10;
if (errvalue < 0)
newvalue = 90;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
} else {
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = 80 / (FSpos2 / range * 100) * (errvalue) + 10;
if (errvalue < 0)
newvalue = 90;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#0000ff"; // light red
ctx4.beginPath(); // beginning of the line
ctx4.lineTo(100 + errvalue, 90); // starting point
newvalue = -80 / (FSpos2 / range * 100) * (errvalue - FSpos2 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
}
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#00ff00"; // light red
ctx4.beginPath(); // beginning of the line
newvalue = 80 / (FSpos2 / range * 100) * (errvalue + FSpos2 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100, newvalue); // starting point
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the grap
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
newvalue = -80 / (FSpos2 / range * 100) * (errvalue) + 10;
if (errvalue > 0)
newvalue = 90;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100, newvalue); // starting point
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // light red
ctx4.beginPath(); // beginning of the line
newvalue = 80 / (FSpos2 / range * 100) * (errvalue) + 10;
if (errvalue < 0)
newvalue = 90;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100, newvalue); // starting point
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.lineWidth = "1";
ctx4.strokeStyle = "#0000ff"; // light red
ctx4.beginPath(); // beginning of the line
newvalue = -80 / (FSpos2 / range * 100) * (errvalue - FSpos2 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10)
newvalue = 10;
ctx4.lineTo(100, newvalue); // starting point
ctx4.lineTo(100 + errvalue, newvalue); // ending point
ctx4.stroke(); // to put it on the graph
ctx4.fillText(-range, 5, 85);
ctx4.fillText(range, 180, 85);
ctx4.fillStyle = "#00ff00";
ctx4.fillText(value.AlphaCut[0], 5, 38);
ctx4.fillStyle = "#ff0000";
ctx4.fillText(value.AlphaCut[1], 5, 50);
ctx4.fillStyle = "#0000ff";
ctx4.fillText(value.AlphaCut[2], 5, 62);
// draw P
/*ctx4.lineWidth = "1";
ctx4.strokeStyle = "#ff0000"; // set red color
ctx4.beginPath(); // to start drawing new line
y4.splice(0, 1); // on the position 0 in the field y3 we erase one value
y4[199] = value.err; // new value is added at the end
for (var i=0; i<200; i++) {
ctx4.lineTo(x4[i], (100 - (1024 + y4[i]) / 2048 * 100)); // 0,0 x,y coordinate is in upper left corner
};
ctx4.stroke(); // to draw the line*/
// END of draw canvas4 graph for P part **********************************************
// Draw canvas5 graph for I part **********************************************
ctx5.clearRect(0, 0, canvas4.width, canvas4.height); // clear canvas only ONCE!
newvalue = 0;
range = 254;
// draw line at coordinate 0
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#000000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100, 0); // starting point
ctx5.lineTo(100, 100); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#000000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(0, 90); // starting point
ctx5.lineTo(200, 90); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#000000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(95, 10); // starting point
ctx5.lineTo(105, 10); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#ff0000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 - FSpos1 / range * 100, 90); // starting point
ctx5.lineTo(100, 10); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#ff0000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(FSpos1 / range * 100 + 100, 90); // starting point
ctx5.lineTo(100, 10); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#00ff00"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 - FSpos1 / range * 100, 10); // starting point
ctx5.lineTo(100, 90); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#00ff00"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 - FSpos1 / range * 100, 10); // starting point
ctx5.lineTo(0, 10); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#0000ff"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(FSpos1 / range * 100 + 100, 10); // starting point
ctx5.lineTo(100, 90); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#0000ff"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(FSpos1 / range * 100 + 100, 10); // starting point
ctx5.lineTo(200, 10); // ending point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#000000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 + FSpos1 / range * 100, 90); // starting point
ctx5.lineTo(100 + FSpos1 / range * 100, 10); // starting point
ctx5.stroke(); // to put it on the graph
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#000000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 - FSpos1 / range * 100, 90); // starting point
ctx5.lineTo(100 - FSpos1 / range * 100, 10); // starting point
ctx5.stroke(); // to put it on the graph
ctx5.fillText(-range, 5, 85);
ctx5.fillText(range, 180, 85);
var cyclevalue = 0;
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#00ff00"; // light red
for (var ii = -(100 - FSpos1 / range * 100).toFixed() + 2; ii < 0; ii++) {
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 + ii, 90); // starting point
newvalue = 80 / (FSpos1 / range * 100) * (ii + FSpos1 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10 + 80 * (1 - value.AlphaCut[0]))
newvalue = 10 + 80 * (1 - value.AlphaCut[0]);
ctx5.lineTo(100 + ii, newvalue); // ending point
ctx5.stroke(); // to put it on the graph
}
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#ff0000"; // light red
for (var ii = -(100 - FSpos1 / range * 100).toFixed() + 2; ii < 0; ii++) {
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 + ii, 90); // starting point
newvalue = -80 / (FSpos1 / range * 100) * (ii) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10 + 80 * (1 - value.AlphaCut[1]))
newvalue = 10 + 80 * (1 - value.AlphaCut[1]);
ctx5.lineTo(100 + ii, newvalue); // ending point
ctx5.stroke(); // to put it on the graph
}
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#ff0000"; // light red
for (var ii = 0; ii < FSpos1 / range * 100; ii++) {
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 + ii, 90); // starting point
newvalue = 80 / (FSpos1 / range * 100) * (ii) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10 + 80 * (1 - value.AlphaCut[1]))
newvalue = 10 + 80 * (1 - value.AlphaCut[1]);
ctx5.lineTo(100 + ii, newvalue); // ending point
ctx5.stroke(); // to put it on the graph
}
ctx5.lineWidth = "1";
ctx5.strokeStyle = "#0000ff"; // light red
for (var ii = 0; ii < FSpos1 / range * 100; ii++) {
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 + ii, 90); // starting point
newvalue = -80 / (FSpos1 / range * 100) * (ii - FSpos1 / range * 100) + 10;
if (newvalue > 90)
newvalue = 90;
if (newvalue < 10 + 80 * (1 - value.AlphaCut[2]))
newvalue = 10 + 80 * (1 - value.AlphaCut[2]);
ctx5.lineTo(100 + ii, newvalue); // ending point
ctx5.stroke(); // to put it on the graph
}
ctx5.lineWidth = "2";
ctx5.strokeStyle = "#000000"; // light red
ctx5.beginPath(); // beginning of the line
ctx5.lineTo(100 + value.ValuesForFuzzy[0] / range * 100, 90); // starting point
ctx5.lineTo(100 + value.ValuesForFuzzy[0] / range * 100, 85); // starting point
ctx5.stroke(); // to put it on the graph
// END of draw canvas5 graph for i part **********************************************
// Draw canvas6 graph for D part **********************************************
ctx6.clearRect(0, 0, canvas6.width, canvas6.height); // clear canvas only ONCE!
// draw line at coordinate 0
ctx6.lineWidth = "1";
ctx6.strokeStyle = "#add8e6"; // light green
ctx6.beginPath(); // beginning of the line
ctx6.lineTo(0, 50); // starting point
ctx6.lineTo(200, 50); // ending point
ctx6.stroke(); // to put it on the graph
// put on the legend
ctx6.font = "11px Arial";
ctx6.fillText("dError/dt", 70, 10);
ctx6.strokeStyle = "#00ff00";
ctx6.beginPath(); // beginning of legend line draw
ctx6.lineTo(50, 6);
ctx6.lineTo(65, 6);
ctx6.stroke(); // end of legend line draw
// draw I
ctx6.lineWidth = "1";
ctx6.strokeStyle = "#0000ff"; // set green color
ctx6.beginPath(); // to start drawing new line
y6.splice(0, 1); // on the position 0 in the field y3 we erase one value
y6[199] = value.dErr; // new value is added at the end
for (var i = 0; i < 200; i++) {
ctx6.lineTo(x6[i], (100 - (150 + y6[i]) / 300 * 100)); // 0,0 x,y coordinate is in upper left corner
};
ctx6.stroke(); // to draw the line
// add axis labels
ctx6.font = "10px Arial";
// x-axis label
ctx6.fillText("<-" + 0 + "|" + 200 + "->", 155, 100 - 5); // display number of points on x-axis
// min on y-axis label:
//ctx6.textBaseline="top"; // to print font 5 px from top
ctx6.fillText(150, 5, 11); // values for y axis
ctx6.fillText(-150, 5, 100 - 5);
// END of draw canvas6 graph for D part **********************************************
log(value.desiredValue + "|" + value.actualValue + "|" + (value.desiredValue - value.actualValue) +
"|" + (value.pwm).toFixed(0));
})
function startControlAlgorithm1() {
stopControlAlgorithm(); // just in case, if it is not started
pCoeff = document.getElementById("pCoeff").value; // read the value of coeff from input field
socket.emit("startControlAlgorithm", {"ctrlAlgNo": 1, "pCoeff": pCoeff}); // send value of coeff
}
function startControlAlgorithm2() {
stopControlAlgorithm(); // just in case, if it is not started
Kp1 = document.getElementById("Kp1").value; // read the value of coeff from input field
Ki1 = document.getElementById("Ki1").value; // read the value of coeff from input field
Kd1 = document.getElementById("Kd1").value; // read the value of coeff from input field
socket.emit("startControlAlgorithm", {"ctrlAlgNo": 2, "Kp1": Kp1, "Ki1": Ki1, "Kd1": Kd1}); // send value of coeff
}
function startControlAlgorithm3() {
stopControlAlgorithm(); // just in case, if it is not started
Kp2 = document.getElementById("Kp2").value; // read the value of coeff from input field
Ki2 = document.getElementById("Ki2").value; // read the value of coeff from input field
Kd2 = document.getElementById("Kd2").value; // read the value of coeff from input field
socket.emit("startControlAlgorithm", {"ctrlAlgNo": 3, "Kp2": Kp2, "Ki2": Ki2, "Kd2": Kd2}); // send value of coeff
}
function startControlAlgorithm4() {
stopControlAlgorithm(); // just in case, if it is not started
FSpos1 = document.getElementById("FSpos1").value; // read the value of coeff from input field
FSpos2 = document.getElementById("FSpos2").value; // read the value of coeff from input field
socket.emit("startControlAlgorithm", {"ctrlAlgNo": 4, "FSpos1": FSpos1, "FSpos2": FSpos2}); // send value of coeff
}
function stopControlAlgorithm() {
socket.emit("stopControlAlgorithm");
}
socket.on("disconnect", function () {
log("Disconnected from the server"); // we print status of disconn. to div
});
</script>
</body>
</html>