-
Notifications
You must be signed in to change notification settings - Fork 60
/
MultiWiiConf.pde
3128 lines (2770 loc) · 142 KB
/
MultiWiiConf.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
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import processing.serial.Serial; // serial library
import controlP5.*; // controlP5 library
import processing.opengl.*;
import java.lang.StringBuffer; // for efficient String concatemation
import javax.swing.SwingUtilities; // required for swing and EDT
import javax.swing.JFileChooser; // Saving dialogue
import javax.swing.filechooser.FileFilter; // for our configuration file filter "*.mwi"
import javax.swing.JOptionPane; // for message dialogue
//Added For Processing 2.0.x compabillity
import java.util.*;
import java.io.*;
//****************************
// TODO add new msp : pid description with bound and scale
PrintWriter output;
BufferedReader reader;
String portnameFile="SerialPort.txt"; // Name of file for Autoconnect.
int GUI_BaudRate = 115200; // Default.
int SerialPort;
Serial g_serial;
ControlP5 controlP5;
Textlabel txtlblWhichcom,TxtInfoMotors1;
Textlabel txtlblRates,txtlblRev,TxtLeftW,TxtRightW,TxtRevW,TxtRevR,TxtRates,TxtRev,
TxtMids,TxtMin,TxtMax,TxtSLeft,TxtSNick,TxtSRight,TxtInfo,TxtInfo1,TxtInfo2,
TxtInfo3,TxtInfo4,TxtAux,Links;
ListBox commListbox,baudListbox;
static int CHECKBOXITEMS=0;
static int PIDITEMS=10;
int commListMax;
int tabHeight=20; // Extra height needed for Tabs
int Centerlimits[] = {1200,1800}; // Endpoints of ServoCenterSliders
cGraph g_graph;
int windowsX = 1000; int windowsY = 550+tabHeight;
int xGraph = 10; int yGraph = 325+tabHeight;
int xObj = 520; int yObj = 293+tabHeight;
int xCompass = 920; int yCompass = 341+tabHeight;
int xLevelObj = 920; int yLevelObj = 80+tabHeight;
int xParam = 120; int yParam = 5+tabHeight;
int xRC = 690; int yRC = 10+tabHeight;
int xMot = 690; int yMot = 155+tabHeight;
int xButton = 845; int yButton = 231+tabHeight;
int xBox = 415; int yBox = 10+tabHeight;
int xGPS = 853; int yGPS = 438+tabHeight;
int xServ = 350; int yServ = 20+tabHeight;
int i, j; // enummerators
int byteRC_RATE,byteRC_EXPO, byteRollPitchRate,byteYawRate,
byteDynThrPID,byteThrottle_EXPO, byteThrottle_MID, byteSelectSetting,
cycleTime, i2cError,
version, versionMisMatch,horizonInstrSize,
GPS_distanceToHome, GPS_directionToHome,
GPS_numSat, GPS_fix, GPS_update, GPS_altitude, GPS_speed,
GPS_latitude, GPS_longitude,
init_com, graph_on, pMeterSum, intPowerTrigger, bytevbat, amperage, rssi ;
int multiCapability = 0; // Bitflags stating what capabilities are/are not present in the compiled code.
int byteMP[] = new int[8]; // Motor Pins. Varies by multiType and Arduino model (pro Mini, Mega, etc).
int MConf[] = new int[10]; // Min/Maxthro etc
int byteP[] = new int[PIDITEMS], byteI[] = new int[PIDITEMS], byteD[] = new int[PIDITEMS];
int activation[];
int ServoMID[] = new int[8]; // Plane,ppm/pwm conv,heli
int servoRATE[] = new int[8];
int servoDirection[] = new int[8];
int ServoMIN[] = new int[8];
int ServoMAX[] = new int[8];
int wingDir[] = new int[8]; // Flying wing
int wingPos[] = new int[8];
int In[] = new int[8];
Textlabel TxtMIX[] = new Textlabel[6];
int multiType; // 1 for tricopter, 2 for quad+, 3 for quadX, ...
// Alias for multiTypes
int TRI =1;
int QUADP =2;
int QUADX =3;
int BI =4;
int GIMBAL =5;
int Y6 =6;
int HEX6 =7;
int FLYING_WING =8;
int Y4 =9;
int HEX6X =10;
int OCTOX8 =11;
int OCTOFLATX =12;
int OCTOFLATP =13;
int AIRPLANE =14;
int HELI_120_CCPM =15;
int HELI_90_DEG =16;
int VTAIL4 =17;
int HEX6H =18;
int PPM_TO_SERVO =19;
int DUALCOPTER =20;
int SINGLECOPTER =21;
float gx, gy, gz, ax, ay, az, magx, magy, magz, alt, head, angx, angy,
debug1, debug2, debug3, debug4,
angyLevelControl, angCalc,
pVersion;
float mot[] = new float[8],
servo[] = new float[8],
RCChan[] = new float[16];
private static final int ROLL = 0, PITCH = 1, YAW = 2, ALT = 3, VEL = 4, LEVEL = 5, MAG = 6;
boolean axGraph =true,ayGraph=true,azGraph=true,gxGraph=true,gyGraph=true,gzGraph=true,altGraph=true,headGraph=true, magxGraph =true,magyGraph=true,magzGraph=true,
debug1Graph = false,debug2Graph = false,debug3Graph = false,debug4Graph = false,hideDraw=false,GraphicsInited=false,gimbalConfig=false,flapperons=false,
flaps=false,InitServos=true;
boolean toggleServo=false,toggleWriteServo=false,toggleWing=false,toggleWriteWing=false,toggleLive=false,toggleWriteServoLive=false,toggleWriteWingLive=false,
toggleSaveHeli=false,toggleWaitHeli=false,toggleGimbal=false,
graphEnabled = false,Mag_=false,gimbal=false, servoStretch=false,camTrigger=false,ExportServo=false,
toggleTrigger=false,ServosActive=false;
static int RCThro = 3, RCRoll = 0, RCPitch =1, RCYaw =2, RCAUX1=4, RCAUX2=5, RCAUX3=6, RCAUX4=7;
cDataArray accPITCH = new cDataArray(200), accROLL = new cDataArray(200), accYAW = new cDataArray(200),
gyroPITCH = new cDataArray(200), gyroROLL = new cDataArray(200), gyroYAW = new cDataArray(200),
magxData = new cDataArray(200), magyData = new cDataArray(200), magzData = new cDataArray(200),
altData = new cDataArray(200), headData = new cDataArray(200),
debug1Data = new cDataArray(200), debug2Data = new cDataArray(200), debug3Data = new cDataArray(200),
debug4Data = new cDataArray(200);
Numberbox confP[] = new Numberbox[PIDITEMS],
confI[] = new Numberbox[PIDITEMS],
confD[] = new Numberbox[PIDITEMS],
confINF[] = new Numberbox[7],
VBat[] = new Numberbox[6]
;
Numberbox confRC_RATE, confRC_EXPO, rollPitchRate, yawRate, dynamic_THR_PID, throttle_EXPO, throttle_MID,
confPowerTrigger, confSetting, confSelectSetting;
Slider axSlider, aySlider, azSlider, gxSlider, gySlider, gzSlider, magxSlider, magySlider,
magzSlider, altSlider, headSlider, debug1Slider, debug2Slider, debug3Slider, debug4Slider,scaleSlider,motorControlSlider;
Slider servoSliderH[] = new Slider[8],
servoSliderV[] = new Slider[8],
motSlider[] = new Slider[8],
TX_StickSlider[] = new Slider[8],
GimbalSlider[] = new Slider[12],
ServoSliderC[] = new Slider[8],
ServoSliderMAX[] = new Slider[8],
ServoSliderMIN[] = new Slider[8];
Button buttonIMPORT, buttonSAVE, buttonREAD, buttonRESET, buttonWRITE, buttonCALIBRATE_ACC, buttonCALIBRATE_MAG, buttonSTART, buttonSTOP, buttonSETTING,
buttonAcc, buttonBaro, buttonMag, buttonGPS, buttonSonar, buttonOptic, buttonRXbind, btnQConnect,buttonExport,
btMagDecl,btMWiiHome,btDownloads;
Button SaveSERVO,buttonSERVO,buttonWing,SaveWing,buttonLIVE,buttonCCPM,buttonGimbal,btnTrigger;
Toggle tACC_ROLL, tACC_PITCH, tACC_Z, tGYRO_ROLL, tGYRO_PITCH, tGYRO_YAW, tBARO,tHEAD, tMAGX, tMAGY, tMAGZ,
tDEBUG1, tDEBUG2, tDEBUG3, tDEBUG4;
// Motors Toggles
Toggle motToggle[] = new Toggle[8];
// Colors
color yellow_ = color(200, 200, 20), green_ = color(30, 120, 30), red_ = color(120, 30, 30), blue_ = color(50, 50, 100),
grey_ = color(30, 30, 30),black_ = color(0, 0, 0),orange_ =color(200,128,0);
PFont font8, font9, font12, font15;
CheckBox checkbox[], checkboxRev[];
CheckBox Bbox, Wbox, Mbox;
Button buttonCheckbox[], BtServo[], BtAUX[];
Numberbox RateSlider[];
// TODO New part
void create_GimbalGraphics(){
if(gimbal){
gimbalConfig = true;
int sMin=1020;int sMax=2000;
if(servoStretch) {sMin=500; sMax=2500;}
int Step=yServ-10;
GimbalSlider[0] = controlP5.addSlider("Tilt_Min" ,sMin,1500,0,xServ+10,Step+80,60,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[1] = controlP5.addSlider("Tilt_Max" ,1500,sMax,0,xServ+150 ,Step+80,60,10).setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[2] = controlP5.addSlider("Channel " ,1200,1700,0,xServ+100,Step+60,90,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[3] = controlP5.addSlider("Tilt_Prop",-125,125,0,xServ+100,Step+100, 60,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
Step+=90;
GimbalSlider[4] = controlP5.addSlider("Roll_Min" ,sMin,1500,0,xServ+10,Step+80,60,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[5] = controlP5.addSlider("Roll_Max" ,1500,sMax,0,xServ+150 ,Step+80,60,10).setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[6] = controlP5.addSlider("Channel" ,1200,1700,0,xServ+100,Step+60,90,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[7] = controlP5.addSlider("Roll_Prop",-125,125,0,xServ+100,Step+100, 60,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[8] = controlP5.addSlider("Trig_LO" ,500,2000,0,xServ+10,Step+80,60,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[9] = controlP5.addSlider("Trig_HI" ,1000,sMax,0,xServ+150 ,Step+80,60,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[10] = controlP5.addSlider("Trigger" ,0,30000,0,xServ+100,Step+60,90,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings");
GimbalSlider[11] = controlP5.addSlider("Trig_Rev",-0,1,0,xServ+100,Step+100, 40,10) .setDecimalPrecision(0).hide().moveTo("ServoSettings") .setNumberOfTickMarks(2).setColorTickMark(0);
buttonGimbal.show();
if(camTrigger)btnTrigger.show();
controlP5.getTab("ServoSettings").show();
}
}
void create_ServoGraphics(){
BtServo = new Button[8];
BtAUX = new Button[5];
checkboxRev = new CheckBox[8];
RateSlider = new Numberbox[8];
GraphicsInited=true;
Bbox = controlP5.addCheckBox("Bbox").setPosition(xServ+40,yServ+40).setColorForeground(color(120))
.setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10).setColorBackground(color(140))
.setItemsPerRow(1).setSpacingColumn(30).setSpacingRow(10)
.addItem("0", 254).addItem("1", 254).addItem("2", 254)
.addItem("3", 254).addItem("4", 254).addItem("5", 254)
.addItem("6", 254).addItem("7", 254)
.hide().hideLabels().moveTo("ServoSettings")
;
//Create Common ServoSliders
int Step =0;
int sMin=1020;int sMax=2000;
if(servoStretch) {sMin=500; sMax=2500;}
for (i=0;i<8;i++) {
ServoSliderC[i] = controlP5.addSlider("Servo "+i,Centerlimits[0],Centerlimits[1],0,xServ+180,yServ+40+Step,110,12).setDecimalPrecision(0).hide().setLabel("").moveTo("ServoSettings");
ServoSliderMIN[i] = controlP5.addSlider("MIN "+i,sMin,1500,0,xServ+80,yServ+40+Step,40,12).setDecimalPrecision(0).setLabel("").hide().moveTo("ServoSettings");
ServoSliderMAX[i] = controlP5.addSlider("MAX "+i,1500,sMax,0,xServ+125,yServ+40+Step,40,12).setDecimalPrecision(0).setLabel("").hide().moveTo("ServoSettings");
Step+=20; }
// ServoGraphics For AirPlane SC & DC
if(multiType == PPM_TO_SERVO || multiType == AIRPLANE ){
controlP5.getTab("ServoSettings").show();
TxtRates = controlP5.addTextlabel("label","Servo Rates in %").setPosition(xServ+75,yServ+20).hide().moveTo("ServoSettings");
TxtMids = controlP5.addTextlabel("Mlabel","Offset for servos").setPosition(xServ+190,yServ+20).hide().moveTo("ServoSettings");
TxtAux = controlP5.addTextlabel("Alabel","Channel for Flaps").setPosition(xServ-120,yServ+20).hide().moveTo("ServoSettings");
TxtRev = controlP5.addTextlabel("txtlblRev","Norm/Rev").setPosition(xServ+10,yServ+20).hide().moveTo("ServoSettings");
//****************** End of AirPlane ********************
}
if(multiType == FLYING_WING || multiType == TRI || multiType == BI || multiType == DUALCOPTER || multiType == SINGLECOPTER){ //ServoGraphics For FlyingWng & TRI & BI || multiType == DUALCOPTER
controlP5.getTab("ServoSettings").show();
int LabelPos=100;
if(multiType == FLYING_WING){
Wbox = controlP5.addCheckBox("Wbox").setColorForeground(color(120)).setColorBackground(color(140)).setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10)
.setItemsPerRow(2).setSpacingColumn(50).setSpacingRow(10).setPosition(xServ-160 ,yServ+50)
.addItem("L Roll", 254).addItem("R Roll", 254).addItem("L NICK", 254).addItem("R NICK", 254).moveTo("ServoSettings") ;
TxtLeftW = controlP5.addTextlabel("Label","Left Wing" ).setPosition(xServ+110,yServ+40).hide().moveTo("ServoSettings");
TxtRightW = controlP5.addTextlabel("Rlabel","Right Wing").setPosition(xServ+110,yServ+130).hide().moveTo("ServoSettings");
}
if(multiType == TRI){
Wbox = controlP5.addCheckBox("Wbox").setColorForeground(color(120)).setColorBackground(color(140)).setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10)
.setItemsPerRow(1).setSpacingColumn(50).setSpacingRow(10).setPosition(xServ-160 ,yServ+50)
.addItem("YAW", 254).moveTo("ServoSettings") ;
TxtLeftW = controlP5.addTextlabel("Label","Yaw Servo" ).setPosition(xServ+110,yServ+40).hide().moveTo("ServoSettings");
TxtRightW = controlP5.addTextlabel("Rlabel"," ").setPosition(xServ+110,yServ+140).hide().moveTo("ServoSettings");
}
if(multiType == BI){
Wbox = controlP5.addCheckBox("Wbox").setColorForeground(color(120)).setColorBackground(color(140)).setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10)
.setItemsPerRow(2).setSpacingColumn(50).setSpacingRow(10).setPosition(xServ-160 ,yServ+50)
.addItem("L Yaw", 254).addItem("R Yaw", 254).addItem("L NICK", 254).addItem("R NICK", 254).moveTo("ServoSettings") ;
TxtLeftW = controlP5.addTextlabel("Label","Left Servo" ).setPosition(xServ+110,yServ+40).hide().moveTo("ServoSettings");
TxtRightW = controlP5.addTextlabel("Rlabel","Right Servo").setPosition(xServ+110,yServ+140).hide().moveTo("ServoSettings");
}
if(multiType == DUALCOPTER){
Wbox = controlP5.addCheckBox("Wbox").setColorForeground(color(120)).setColorBackground(color(140)).setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10)
.setItemsPerRow(2).setSpacingColumn(70).setSpacingRow(10).setPosition(xServ-160 ,yServ+50)
.addItem("Pitch ", 254).addItem("Roll ", 254).moveTo("ServoSettings").hide();
TxtLeftW = controlP5.addTextlabel("Label","Roll" ).setPosition(xServ+110,yServ+40).hide().moveTo("ServoSettings");
TxtRightW = controlP5.addTextlabel("Rlabel","Nick").setPosition(xServ+110,yServ+130).hide().moveTo("ServoSettings");
}
if(multiType == SINGLECOPTER){
Wbox = controlP5.addCheckBox("Wbox").setColorForeground(color(120)).setColorBackground(color(140)).setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10)
.setItemsPerRow(2).setSpacingColumn(50).setSpacingRow(10).setPosition(xServ-80 ,yServ+100)
.addItem(" Right ", 254).addItem("R yaw", 254)
.addItem(" Left ", 254) .addItem("L yaw", 254)
.addItem(" Front", 254) .addItem("F yaw", 254)
.addItem(" Rear", 254) .addItem(" yaw", 254)
.moveTo("ServoSettings") ;
LabelPos=60;
TxtMin = controlP5.addTextlabel("Minlabel","MIN").setPosition(xServ+85,yServ+80) .hide().moveTo("ServoSettings");
TxtMax = controlP5.addTextlabel("Maxlabel","MAX").setPosition(xServ+130,yServ+80).hide().moveTo("ServoSettings");
TxtMids = controlP5.addTextlabel("Mlabel","Offset servos").setPosition(xServ+190,yServ+80).hide().moveTo("ServoSettings");
}
TxtRevW = controlP5.addTextlabel("Revlabel","Change Gyro/Acc Direction" ).setPosition(xServ-165,yServ+30).hide().moveTo("ServoSettings");
TxtRevR = controlP5.addTextlabel("Revtx","Change Dir in TX To Match" ).setPosition(xServ-170,yServ+LabelPos).hide().moveTo("ServoSettings");
//****************** End of FlyingWng & TRI ********************
}
// ServoGraphics For Heli 120 && 90
if(multiType == HELI_120_CCPM || multiType == HELI_90_DEG ){
controlP5.getTab("ServoSettings").show();
TxtMin = controlP5.addTextlabel("Minlabel","MIN").setPosition(xServ+85,yServ+20) .hide().moveTo("ServoSettings");
TxtMax = controlP5.addTextlabel("Maxlabel","MAX").setPosition(xServ+130,yServ+20).hide().moveTo("ServoSettings");
TxtMids = controlP5.addTextlabel("Mlabel","Offset servos").setPosition(xServ+190,yServ+20).hide().moveTo("ServoSettings");
TxtRates = controlP5.addTextlabel("label","Not Used").setPosition(xServ+75,yServ+20).hide().moveTo("ServoSettings");
TxtRev = controlP5.addTextlabel("txtlblRev","Servos").setPosition(xServ+10,yServ+20).hide().moveTo("ServoSettings");
// CCPM settings
// Mixer Boxes
int XPos=xServ+40;
int YPos=yServ-0;
Mbox = controlP5.addCheckBox("Wbox").setColorForeground(color(120)).setColorBackground(color(140)).setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10)
.setItemsPerRow(3).setSpacingColumn(15).setSpacingRow(10).setPosition(XPos-180 ,YPos+50)
.addItem("mix3_4", 254) .addItem("mix3_2", 254).addItem("mix3_1", 254)
.addItem("mix4_4", 254) .addItem("mix4_2", 254).addItem("mix4_1", 254)
.addItem("mix6_4", 254) .addItem("mix6_2", 254).addItem("mix6_1", 254)
.moveTo("ServoSettings").hideLabels().hide();
TxtMIX[0] = controlP5.addTextlabel("mix1","NICK") .setPosition(XPos-220,YPos+50).moveTo("ServoSettings");
TxtMIX[1] = controlP5.addTextlabel("mix2","LEFT") .setPosition(XPos-220,YPos+70).moveTo("ServoSettings");
TxtMIX[2] = controlP5.addTextlabel("mix3","RIGHT").setPosition(XPos-220,YPos+90).moveTo("ServoSettings");
TxtMIX[3] = controlP5.addTextlabel("mix4","COLL") .setPosition(XPos-195,YPos+30).moveTo("ServoSettings");
TxtMIX[4] = controlP5.addTextlabel("mix5","NICK") .setPosition(XPos-155,YPos+30).moveTo("ServoSettings");
TxtMIX[5] = controlP5.addTextlabel("mix6","ROLL") .setPosition(XPos-115,YPos+30).moveTo("ServoSettings");
for (i=0;i<6;i++) { TxtMIX[i].hide();}
//******************End of Heli********************
}
// Common Graphics for servos
Step =0;
for (i=0;i<8;i++) { // TODO Something
BtServo[i] = controlP5.addButton("CHb"+i,1,xServ-30,yServ+40+20*i,60,12).setColorBackground(green_).setLabel("Servo "+i).hide().moveTo("ServoSettings");
checkboxRev[i] = controlP5.addCheckBox("cbR"+i).moveTo("ServoSettings");
checkboxRev[i].setPosition(xServ+70,yServ+40+20*i)
.setColorActive(color(255)).setColorBackground(color(120))
.setItemHeight(10).setItemWidth(20).hide()
.moveTo("ServoSettings")
;
RateSlider[i] = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("Rate"+i,0,xServ+70,yServ+40+i*20,100,14));
RateSlider[i].setColorBackground(yellow_);RateSlider[i].setDirection(Controller.HORIZONTAL);
RateSlider[i].setDecimalPrecision(0);RateSlider[i].setMultiplier(1);RateSlider[i].setMin(0).setMax(125).hide().moveTo("ServoSettings");
}
for (i=0;i<4;i++) BtAUX[i] = controlP5.addButton("Cau"+i,1,xServ-100,yServ+40+20*i,60,12).setColorBackground(red_).setLabel(" AUX "+(i+1)).moveTo("ServoSettings").hide();
BtAUX[4] = controlP5.addButton("Cau4" ,1,xServ-100,yServ+120,60,12).setColorBackground(blue_).setLabel("Disable").moveTo("ServoSettings").hide();
//************************ End of servoGrapics**********************
}
void create_checkboxes(String[] names) {
/* destroy old buttons */
for (int i=0; i<CHECKBOXITEMS; i++) {
buttonCheckbox[i].remove();
checkbox[i].remove();
}
int i=0;
/* create new list entries and buttons */
checkbox = new CheckBox[names.length];
buttonCheckbox = new Button[names.length];
activation = new int[names.length];
for (String name : names) {
if ( name.equals("CAMTRIG")) camTrigger=true;
if ( name.equals("CAMSTAB") || name.equals("CAMTRIG")) gimbal=true;
buttonCheckbox[i] = controlP5.addButton("bcb"+i,1,xBox-30,yBox+20+13*i,68,12).setColorBackground(red_).setLabel(name);
checkbox[i] = controlP5.addCheckBox("cb"+i,xBox+40,yBox+20+13*i).setColorActive(color(255)).setColorBackground(color(120)).
setItemsPerRow(12).setSpacingColumn(10).setLabel("");
for (int j=1; j<=12; j++) checkbox[i].addItem(i + "_cb_" + j, j).hideLabels();
i++;
}
CHECKBOXITEMS = names.length;
}
// coded by Eberhard Rensch
// Truncates a long port name for better (readable) display in the GUI
String shortifyPortName(String portName, int maxlen) {
String shortName = portName;
if(shortName.startsWith("/dev/cu.")) shortName = "";// only collect the corresponding tty. devices
return shortName;
// not compatible currently with reconnect feature
// http://www.multiwii.com/forum/viewtopic.php?f=8&t=4077&p=41692#p41692
/*
if(shortName.startsWith("/dev/")) shortName = shortName.substring(5);
if(shortName.startsWith("tty.")) shortName = shortName.substring(4); // get rid of leading tty. part of device name
if(shortName.length()>maxlen) shortName = shortName.substring(0,(maxlen-1)/2) + "~" +shortName.substring(shortName.length()-(maxlen-(maxlen-1)/2));
if(shortName.startsWith("cu.")) shortName = "";// only collect the corresponding tty. devices
return shortName;
*/
}
controlP5.Controller hideLabel(controlP5.Controller c) {
c.setLabel("");
c.setLabelVisible(false);
return c;
}
void setup() {
// Trying to make both worlds happy..
if( P3D == OPENGL ) pVersion = 2.0; else pVersion = 1.5;
size(1080,720,OPENGL);
frameRate(20);
font8 = createFont("Arial bold",8,false);
font9 = createFont("Arial bold",9,false);
font12 = createFont("Arial bold",12,false);
font15 = createFont("Arial bold",15,false);
controlP5 = new ControlP5(this); // initialize the GUI controls
//controlP5.setControlFont(font12);
addTabs();
g_graph = new cGraph(xGraph+110,yGraph, 480, 200);
// Baud list items
baudListbox = controlP5.addListBox("baudList",5,95+tabHeight,110,240).moveTo("Config"); // make a listbox with available Baudrates
baudListbox.getCaptionLabel().set("BAUD_RATE");
baudListbox.setColorBackground(red_);
baudListbox.setBarHeight(17);
baudListbox.addItem("9600" ,9600); // addItem(name,value)
baudListbox.addItem("14400" ,14400);
baudListbox.addItem("19200" ,19200);
baudListbox.addItem("28800" ,28800);
baudListbox.addItem("38400" ,38400);
baudListbox.addItem("57600" ,57600);
baudListbox.addItem("115200",115200);
// make a listbox and populate it with the available comm ports
commListbox = controlP5.addListBox("portComList",5,105+tabHeight,110,120);
commListbox.getCaptionLabel().set("PORT COM");
commListbox.setColorBackground(red_);
commListbox.setBarHeight(17);
for( i=0;i<Serial.list().length;i++) {
String pn = shortifyPortName(Serial.list()[i], 13);
//if( pn.startsWith("/dev/ttyUSB") ) {
if (pn.length() >0 ) commListbox.addItem(pn,i); // addItem(name,value)
commListMax = i;
//}
}
commListbox.addItem("Close Comm",++commListMax); // addItem(name,value)
// text label for which comm port selected
txtlblWhichcom = controlP5.addTextlabel("txtlblWhichcom","No Port Selected",5,65+tabHeight); // textlabel(name,text,x,y)
// Information textlabels
TxtInfo = controlP5.addTextlabel("SInf","Remember To Save Changes to Eeprom!!") .setPosition(xServ-30, yServ+210).hide().moveTo("ServoSettings");
TxtInfo1 = controlP5.addTextlabel("xInf","Grey Values Is Set As #define In Config.h!!") .setPosition(xServ+0, yServ+210).moveTo("Config");
TxtInfo2 = controlP5.addTextlabel("gInf","Green Values Can Be Changed Press Write To Save!!") .setPosition(xServ+0, yServ+190).moveTo("Config");
TxtInfo3 = controlP5.addTextlabel("CsInf","Remember To Activate CAMSTAB!!") .setPosition(xServ+10, yServ+20).hide().moveTo("ServoSettings");
TxtInfo4 = controlP5.addTextlabel("CtInf","Remember To Activate CAMTRIG!!") .setPosition(xServ+10, yServ+20).hide().moveTo("ServoSettings");
Links = controlP5.addTextlabel("LinkInf","Some Useful Webpages!!") .setPosition(xServ+100, yServ+20).moveTo("Config");
TxtInfoMotors1 = controlP5.addTextlabel("motInf1","This is a function for Balancing Propellors Dynamicly\n"+
"Select motor(s) and control throttle.").setPosition(xServ-200, yServ+10).moveTo("Motors");
buttonSAVE = controlP5.addButton("bSAVE",1,5,45+tabHeight,40,19).setLabel("SAVE").setColorBackground(red_);
buttonIMPORT = controlP5.addButton("bIMPORT",1,50,45+tabHeight,40,19).setLabel("LOAD").setColorBackground(red_);
btnQConnect = controlP5.addButton("bQCONN",1,xGraph+0,yGraph-105,100,19).setLabel(" ReConnect").setColorBackground(red_);
buttonSTART = controlP5.addButton("bSTART",1,xGraph+110,yGraph-25,45,19).setLabel("START").setColorBackground(red_);
buttonSTOP = controlP5.addButton("bSTOP",1,xGraph+160,yGraph-25,45,19).setLabel("STOP").setColorBackground(red_);
buttonAcc = controlP5.addButton("bACC",1,xButton,yButton,45,15).setColorBackground(red_).setLabel("ACC");
buttonBaro = controlP5.addButton("bBARO",1,xButton+50,yButton,45,15).setColorBackground(red_).setLabel("BARO");
buttonMag = controlP5.addButton("bMAG",1,xButton+100,yButton,45,15).setColorBackground(red_).setLabel("MAG");
buttonGPS = controlP5.addButton("bGPS",1,xButton,yButton+17,45,15).setColorBackground(red_).setLabel("GPS");
buttonSonar = controlP5.addButton("bSonar",1,xButton+50,yButton+17,45,15).setColorBackground(red_).setLabel("SONAR");
buttonOptic = controlP5.addButton("bOptic",1,xButton+100,yButton+17,45,15).setColorBackground(grey_).setLabel("OPTIC");
color c,black;
black = color(0,0,0);
int xo = xGraph-7;
int x = xGraph+40;
int y1= yGraph+10; //ACC
int y2= yGraph+55; //GYRO
int y5= yGraph+100; //MAG
int y3= yGraph+150; //ALT
int y4= yGraph+165; //HEAD
int y7= yGraph+185; //GPS
int y6= yGraph+205; //DEBUG
tACC_ROLL = controlP5.addToggle("ACC_ROLL",true,x,y1+10,20,10).setColorActive(color(255, 0, 0)).setColorBackground(black).setLabel("");
tACC_PITCH = controlP5.addToggle("ACC_PITCH",true,x,y1+20,20,10).setColorActive(color(0, 255, 0)).setColorBackground(black).setLabel("");
tACC_Z = controlP5.addToggle("ACC_Z",true,x,y1+30,20,10).setColorActive(color(0, 0, 255)).setColorBackground(black).setLabel("");
tGYRO_ROLL = controlP5.addToggle("GYRO_ROLL",true,x,y2+10,20,10).setColorActive(color(200, 200, 0)).setColorBackground(black).setLabel("");
tGYRO_PITCH = controlP5.addToggle("GYRO_PITCH",true,x,y2+20,20,10).setColorActive(color(0, 255, 255)).setColorBackground(black).setLabel("");
tGYRO_YAW = controlP5.addToggle("GYRO_YAW",true,x,y2+30,20,10).setColorActive(color(255, 0, 255)).setColorBackground(black).setLabel("");
tBARO = controlP5.addToggle("BARO",true,x,y3 ,20,10).setColorActive(color(125, 125, 125)).setColorBackground(black).setLabel("");
tHEAD = controlP5.addToggle("HEAD",true,x,y4 ,20,10).setColorActive(color(225, 225, 125)).setColorBackground(black).setLabel("");
tMAGX = controlP5.addToggle("MAGX",true,x,y5+10,20,10).setColorActive(color(50, 100, 150)).setColorBackground(black).setLabel("");
tMAGY = controlP5.addToggle("MAGY",true,x,y5+20,20,10).setColorActive(color(100, 50, 150)).setColorBackground(black).setLabel("");
tMAGZ = controlP5.addToggle("MAGZ",true,x,y5+30,20,10).setColorActive(color(150, 100, 50)).setColorBackground(black).setLabel("");
tDEBUG1 = controlP5.addToggle("DEBUG1",true,x+70,y6,20,10) .setColorActive(color(200, 50, 0)).setColorBackground(black).setLabel("").setValue(0);
tDEBUG2 = controlP5.addToggle("DEBUG2",true,x+190,y6,20,10).setColorActive(color(0, 200, 50)).setColorBackground(black).setLabel("").setValue(0);
tDEBUG3 = controlP5.addToggle("DEBUG3",true,x+310,y6,20,10).setColorActive(color(50, 0, 200)).setColorBackground(black).setLabel("").setValue(0);
tDEBUG4 = controlP5.addToggle("DEBUG4",true,x+430,y6,20,10).setColorActive(color(150, 100, 50)).setColorBackground(black).setLabel("").setValue(0);
controlP5.addTextlabel( "alarmLabel", "Alarm:", xGraph -5, yGraph -32);
controlP5.addTextlabel("acclabel","ACC",xo,y1 -4);
controlP5.addTextlabel("accrolllabel"," ROLL",xo,y1+10).setFont(font9);
controlP5.addTextlabel("accpitchlabel"," PITCH",xo,y1+20).setFont(font9);
controlP5.addTextlabel("acczlabel"," Z",xo,y1+30).setFont(font9);
controlP5.addTextlabel("gyrolabel","GYRO",xo,y2 -4);
controlP5.addTextlabel("gyrorolllabel"," ROLL",xo,y2+10).setFont(font9);
controlP5.addTextlabel("gyropitchlabel"," PITCH",xo,y2+20).setFont(font9);
controlP5.addTextlabel("gyroyawlabel"," YAW",xo,y2+30).setFont(font9);
controlP5.addTextlabel("maglabel","MAG",xo,y5 -4);
controlP5.addTextlabel("magrolllabel"," ROLL",xo,y5+10).setFont(font9);
controlP5.addTextlabel("magpitchlabel"," PITCH",xo,y5+20).setFont(font9);
controlP5.addTextlabel("magyawlabel"," YAW",xo,y5+30).setFont(font9);
controlP5.addTextlabel("altitudelabel","ALT",xo,y3 -4);
controlP5.addTextlabel("headlabel","HEAD",xo,y4 -4);
controlP5.addTextlabel("debug1","debug1",x+90,y6 -2).setFont(font9);
controlP5.addTextlabel("debug2","debug2",x+210,y6 -2).setFont(font9);
controlP5.addTextlabel("debug3","debug3",x+330,y6 -2).setFont(font9);
controlP5.addTextlabel("debug4","debug4",x+450,y6 -2).setFont(font9);
axSlider = controlP5.addSlider("axSlider",-1000,+1000,0,x+20,y1+10,50,10).setDecimalPrecision(0).setLabel("");
aySlider = controlP5.addSlider("aySlider",-1000,+1000,0,x+20,y1+20,50,10).setDecimalPrecision(0).setLabel("");
azSlider = controlP5.addSlider("azSlider",-1000,+1000,0,x+20,y1+30,50,10).setDecimalPrecision(0).setLabel("");
gxSlider = controlP5.addSlider("gxSlider",-5000,+5000,0,x+20,y2+10,50,10).setDecimalPrecision(0).setLabel("");
gySlider = controlP5.addSlider("gySlider",-5000,+5000,0,x+20,y2+20,50,10).setDecimalPrecision(0).setLabel("");
gzSlider = controlP5.addSlider("gzSlider",-5000,+5000,0,x+20,y2+30,50,10).setDecimalPrecision(0).setLabel("");
altSlider = controlP5.addSlider("altSlider",-30000,+30000,0,x+20,y3 ,50,10).setDecimalPrecision(2).setLabel("");
headSlider = controlP5.addSlider("headSlider",-200,+200,0,x+20,y4 ,50,10).setDecimalPrecision(0).setLabel("");
magxSlider = controlP5.addSlider("magxSlider",-5000,+5000,0,x+20,y5+10,50,10).setDecimalPrecision(0).setLabel("");
magySlider = controlP5.addSlider("magySlider",-5000,+5000,0,x+20,y5+20,50,10).setDecimalPrecision(0).setLabel("");
magzSlider = controlP5.addSlider("magzSlider",-5000,+5000,0,x+20,y5+30,50,10).setDecimalPrecision(0).setLabel("");
debug1Slider = controlP5.addSlider("debug1Slider",-32768,+32767,0,x+130,y6,50,10).setDecimalPrecision(0).setLabel("");
debug2Slider = controlP5.addSlider("debug2Slider",-32768,+32767,0,x+250,y6,50,10).setDecimalPrecision(0).setLabel("");
debug3Slider = controlP5.addSlider("debug3Slider",-32768,+32767,0,x+370,y6,50,10).setDecimalPrecision(0).setLabel("");
debug4Slider = controlP5.addSlider("debug4Slider",-32768,+32767,0,x+490,y6,50,10).setDecimalPrecision(0).setLabel("");
for( i=0;i<PIDITEMS;i++) {
confP[i] = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("confP"+i,0,xParam+40,yParam+20+i*17,30,14));
confP[i].setColorBackground(red_).setMin(0).setDirection(Controller.HORIZONTAL).setDecimalPrecision(1).setMultiplier(0.1).setMax(20);
confI[i] = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("confI"+i,0,xParam+75,yParam+20+i*17,40,14));
confI[i].setColorBackground(red_).setMin(0).setDirection(Controller.HORIZONTAL).setDecimalPrecision(3).setMultiplier(0.001).setMax(0.250);
confD[i] = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("confD"+i,0,xParam+120,yParam+20+i*17,30,14));
confD[i].setColorBackground(red_).setMin(0).setDirection(Controller.HORIZONTAL).setDecimalPrecision(0).setMultiplier(1).setMax(100);
}
for( i=0;i<7;i++) {
confINF[i] = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("confINF"+i,0,xParam+10,yParam+10+i*35,60,14));
confINF[i].setColorBackground(green_).setMin(0).setDirection(Controller.HORIZONTAL).setDecimalPrecision(0).setMultiplier(5).setMax(100).moveTo("Config").hide();
}
confINF[0].setLabel("Minthrottle").setMin(1000).setMax(1500).moveTo("Config");
confINF[1].setLabel("MAXhrottle").setMin(1500).setMax(2000).moveTo("Config");
confINF[2].setLabel("Min command").setMin(900).setMax(1200).moveTo("Config");
confINF[3].setLabel("FS Thr").setMin(1200).setMax(2000).moveTo("Config");
confINF[4].setLabel("Armed count").setMin(0).setMax(10000).setColorBackground(red_).moveTo("Config");
confINF[5].setLabel("Acc ArmedTime").setMin(0).setMax(360000).setColorBackground(red_).moveTo("Config");
confINF[6].setLabel("MAG Decl").setMin(-30).setMax(30).setDecimalPrecision(1).setMultiplier(.1).moveTo("Config");
confI[8].hide();confD[8].hide();confD[4].hide();
confP[9].hide();confI[9].hide();confD[9].hide();
//change bounds for POS-4 POSR-5 and NAV-6
confP[4].setDecimalPrecision(2).setMultiplier(0.01).setMax(5);
confI[4].setDecimalPrecision(1).setMultiplier(0.1) .setMax(2.5);
confP[5].setDecimalPrecision(1).setMultiplier(0.1) .setMax(25);
confI[5].setDecimalPrecision(2).setMultiplier(0.01).setMax(2.5);
confD[5].setDecimalPrecision(3).setMultiplier(.001).setMax(.250);
confP[6].setDecimalPrecision(1).setMultiplier(0.1) .setMax(25);
confI[6].setDecimalPrecision(2).setMultiplier(0.01).setMax(2.5);
confD[6].setDecimalPrecision(3).setMultiplier(.001).setMax(.250);
rollPitchRate = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("rollPitchRate",0,xParam+160,yParam+30,30,14)).setDecimalPrecision(2);
rollPitchRate.setDirection(Controller.HORIZONTAL).setMin(0).setMax(1).setColorBackground(red_).setMultiplier(0.01);
yawRate = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("yawRate",0,xParam+160,yParam+54,30,14)).setDecimalPrecision(2);
yawRate.setDirection(Controller.HORIZONTAL).setMin(0).setMax(1).setColorBackground(red_).setMultiplier(0.01);
dynamic_THR_PID = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("dynamic_THR_PID",0,xParam+215,yParam+22,30,14)).setDecimalPrecision(2);
dynamic_THR_PID.setMultiplier(0.01).setDirection(Controller.HORIZONTAL).setMin(0).setMax(1).setColorBackground(red_);
confRC_RATE = controlP5.addNumberbox("RC RATE",1,xParam+40,yParam+220,30,14).setDecimalPrecision(2).setMultiplier(0.01).setLabel("");
confRC_RATE.setDirection(Controller.HORIZONTAL).setMin(0).setMax(2.5).setColorBackground(red_);
confRC_EXPO = controlP5.addNumberbox("RC EXPO",0,xParam+40,yParam+237,30,14).setDecimalPrecision(2).setMultiplier(0.01).setLabel("");
confRC_EXPO.setDirection(Controller.HORIZONTAL).setMin(0).setMax(1).setColorBackground(red_);
confSetting = controlP5.addNumberbox("_SETTING",0,xParam+2,yParam+2,30,14).setDecimalPrecision(0).setMultiplier(1).setLabel("")
.setDirection(Controller.HORIZONTAL).setMin(0).setMax(2).setColorBackground(red_);//.hide();
confSelectSetting = controlP5.addNumberbox("S_SETTING",0,xParam+520,yParam+260,30,14).setDecimalPrecision(0).setMultiplier(1).setLabel("")
.setDirection(Controller.HORIZONTAL).setMin(0).setMax(2).setColorBackground(red_);//.hide();
throttle_MID = controlP5.addNumberbox("T MID",0.5,xParam+40,yParam+180,30,14).setDecimalPrecision(2).setMultiplier(0.01).setLabel("")
.setDirection(Controller.HORIZONTAL).setMin(0).setMax(1).setColorBackground(red_);
throttle_EXPO = controlP5.addNumberbox("T EXPO",0,xParam+40,yParam+197,30,14).setDecimalPrecision(2).setMultiplier(0.01).setLabel("")
.setDirection(Controller.HORIZONTAL).setMin(0).setMax(1).setColorBackground(red_);
buttonREAD = controlP5.addButton("READ" , 1, xParam+5, yParam+260, 50, 16) .setColorBackground(red_);
buttonRESET = controlP5.addButton("RESET", 1, xParam+60, yParam+260, 60, 16) .setColorBackground(red_);
buttonWRITE = controlP5.addButton("WRITE", 1, xParam+290, yParam+260, 50, 16) .setColorBackground(red_);
buttonSERVO = controlP5.addButton("SERVO", 1, xParam+5, yParam+220, 55, 16) .setColorBackground(red_).hide().moveTo("ServoSettings");
buttonWing = controlP5.addButton("WING" , 1, xParam+5, yParam+220, 55, 16) .setColorBackground(red_).hide().moveTo("ServoSettings");
buttonExport= controlP5.addButton("Eport_Servo",1, xParam+5, yParam+10, 100,19) .setLabel("Export to file").setColorBackground(green_).moveTo("ServoSettings").hide();
SaveSERVO = controlP5.addButton("SAVE_Servo", 1 , xParam+290, yParam+260, 55, 16).setColorBackground(green_).hide().setLabel(" Save").moveTo("ServoSettings");
SaveWing = controlP5.addButton("SAVE_WING", 1 , xParam+290, yParam+260, 55, 16).setColorBackground(green_).hide().setLabel(" Save").moveTo("ServoSettings");
buttonLIVE= controlP5.addButton("LIVE_SERVO", 1 , xParam+65, yParam+220, 75, 16).setColorBackground(red_).setLabel("Go Live").hide().moveTo("ServoSettings");
buttonCALIBRATE_ACC = controlP5.addButton("CALIB_ACC", 1, xParam+210, yParam+260, 70, 16).setColorBackground(red_);
buttonCALIBRATE_MAG = controlP5.addButton("CALIB_MAG", 1, xParam+130, yParam+260, 73, 16).setColorBackground(red_);
buttonSETTING = controlP5.addButton("SETTING" , 1, xParam+410, yParam+260, 105, 16) .setColorBackground(red_).setLabel("SELECT SETTING");//.hide();
buttonGimbal = controlP5.addButton("GIMBAL" , 1, xParam+5, yParam+200,55,16).setColorBackground(green_).hide().moveTo("ServoSettings");
btnTrigger = controlP5.addButton("TRIGGER" , 1, xParam+65, yParam+200,75,16).setColorBackground(green_).hide().moveTo("ServoSettings");
btMagDecl = controlP5.addButton("MagDecl" , 1, xParam+350, yParam+100, 180, 16).setColorBackground(grey_).moveTo("Config").setLabel("magnetic-declination.com");
btMWiiHome = controlP5.addButton("MWiiHome" , 1, xParam+350, yParam+60, 180, 16).setColorBackground(grey_).moveTo("Config").setLabel("MUltiWii Forum");
btDownloads = controlP5.addButton("MWiiGet" , 1, xParam+350, yParam+80, 180, 16).setColorBackground(grey_).moveTo("Config").setLabel("MUltiWii Downloads");
// Sliders for Transmitter
TX_StickSlider[RCRoll ] = controlP5.addSlider("Roll", 900,2100,1500,xRC,yRC+15,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCPitch] = controlP5.addSlider("Pitch",900,2100,1500,xRC,yRC+30,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCThro ] = controlP5.addSlider("Throt",900,2100,1500,xRC,yRC,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCYaw ] = controlP5.addSlider("Yaw", 900,2100,1500,xRC,yRC+45,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCAUX1] = controlP5.addSlider("AUX1", 1000,2000,1500,xRC,yRC+60,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCAUX2] = controlP5.addSlider("AUX2", 1000,2000,1500,xRC,yRC+75,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCAUX3] = controlP5.addSlider("AUX3", 1000,2000,1500,xRC,yRC+90,100,10) .setDecimalPrecision(0);
TX_StickSlider[RCAUX4] = controlP5.addSlider("AUX4", 1000,2000,1500,xRC,yRC+105,100,10).setDecimalPrecision(0);
motorControlSlider = controlP5.addSlider("Motors",1000,2000,1500,xParam+410, yParam,90,30) .setDecimalPrecision(0).hide();
for( i=0;i<8;i++) {
motToggle[i] = controlP5.addToggle("M"+i,false,xMot-100,yMot+15,20,15).moveTo("Motors").hide();
motSlider[i] = controlP5.addSlider("motSlider"+i,900,2000,1500,0,0,10,100).setDecimalPrecision(0).hide();
servoSliderH[i] = controlP5.addSlider("ServoH"+i,1000,2000,1500,0,0,100,10).setDecimalPrecision(0).hide();
servoSliderV[i] = controlP5.addSlider("ServoV"+i,1000,2000,1500,0,0,10,100).setDecimalPrecision(0).hide();
}
for( i=0;i<6;i++) {
VBat[i] = (controlP5.Numberbox) hideLabel(controlP5.addNumberbox("VBat"+i,0,xParam+120,yParam+20+i*35,60,14));
VBat[i].setColorBackground(red_).setMin(0).setMax(20).setDirection(Controller.HORIZONTAL).setDecimalPrecision(1).setMultiplier(1).moveTo("Config").hide();
}
VBat[0].setCaptionLabel("VBatscale").setDecimalPrecision(0).setMin(0).setMax(200);
VBat[1].setCaptionLabel("Warning 1").setMultiplier(0.1);
VBat[2].setCaptionLabel("Warning 2").setMultiplier(0.1);
VBat[3].setCaptionLabel("Critical").setMultiplier(0.1);
VBat[4].setCaptionLabel("Volt").setColorBackground(red_).setDecimalPrecision(2);
VBat[5].setCaptionLabel("RSSI").setColorBackground(red_).setDecimalPrecision(0).setMin(0).setMax(1023);
scaleSlider = controlP5.addSlider("SCALE",0,10,1,xGraph+515,yGraph,75,20).setLabel("");// GraphScaler
confPowerTrigger = controlP5.addNumberbox("",0,xGraph+50,yGraph-29,40,14).setDecimalPrecision(0).setMultiplier(10)
.setDirection(Controller.HORIZONTAL).setMin(0).setMax(65535).setColorBackground(red_);
Tooltips();
} /************* End of setup() *************/
/******************************* Multiwii Serial Protocol **********************/
private static final String MSP_HEADER = "$M<";
private static final int
MSP_IDENT =100,
MSP_STATUS =101,
MSP_RAW_IMU =102,
MSP_SERVO =103,
MSP_MOTOR =104,
MSP_RC =105,
MSP_RAW_GPS =106,
MSP_COMP_GPS =107,
MSP_ATTITUDE =108,
MSP_ALTITUDE =109,
MSP_ANALOG =110,
MSP_RC_TUNING =111,
MSP_PID =112,
MSP_BOX =113,
MSP_MISC =114,
MSP_MOTOR_PINS =115,
MSP_BOXNAMES =116,
MSP_PIDNAMES =117,
MSP_SERVO_CONF =120,
MSP_SET_RAW_RC =200,
MSP_SET_RAW_GPS =201,
MSP_SET_PID =202,
MSP_SET_BOX =203,
MSP_SET_RC_TUNING =204,
MSP_ACC_CALIBRATION =205,
MSP_MAG_CALIBRATION =206,
MSP_SET_MISC =207,
MSP_RESET_CONF =208,
MSP_SELECT_SETTING =210,
MSP_SET_HEAD =211, // Not used
MSP_SET_SERVO_CONF =212,
MSP_SET_MOTOR =214,
MSP_BIND =241,
MSP_EEPROM_WRITE =250,
MSP_DEBUGMSG =253,
MSP_DEBUG =254
;
public static final int
IDLE = 0,
HEADER_START = 1,
HEADER_M = 2,
HEADER_ARROW = 3,
HEADER_SIZE = 4,
HEADER_CMD = 5,
HEADER_ERR = 6
;
int c_state = IDLE;
boolean err_rcvd = false;
byte checksum=0;
byte cmd;
int offset=0, dataSize=0;
byte[] inBuf = new byte[256];
int p;
int read32() {return (inBuf[p++]&0xff) + ((inBuf[p++]&0xff)<<8) + ((inBuf[p++]&0xff)<<16) + ((inBuf[p++]&0xff)<<24); }
int read16() {return (inBuf[p++]&0xff) + ((inBuf[p++])<<8); }
int read8() {return inBuf[p++]&0xff;}
int mode;
boolean toggleRead = false,toggleReset = false,toggleCalibAcc = false,toggleCalibMag = false,toggleWrite = false,
toggleRXbind = false,toggleSetSetting = false,toggleVbat=true,toggleMotor=false,motorcheck=true;
//send msp without payload
private List<Byte> requestMSP(int msp) {
return requestMSP( msp, null);
}
//send multiple msp without payload
private List<Byte> requestMSP (int[] msps) {
List<Byte> s = new LinkedList<Byte>();
for (int m : msps) {
s.addAll(requestMSP(m, null));
}
return s;
}
//send msp with payload
private List<Byte> requestMSP (int msp, Character[] payload) {
if(msp < 0) {
return null;
}
List<Byte> bf = new LinkedList<Byte>();
for (byte c : MSP_HEADER.getBytes()) {
bf.add( c );
}
byte checksum=0;
byte pl_size = (byte)((payload != null ? int(payload.length) : 0)&0xFF);
bf.add(pl_size);
checksum ^= (pl_size&0xFF);
bf.add((byte)(msp & 0xFF));
checksum ^= (msp&0xFF);
if (payload != null) {
for (char c :payload){
bf.add((byte)(c&0xFF));
checksum ^= (c&0xFF);
}
}
bf.add(checksum);
return (bf);
}
void sendRequestMSP(List<Byte> msp) {
byte[] arr = new byte[msp.size()];
int i = 0;
for (byte b: msp) {
arr[i++] = b;
}
g_serial.write(arr); // send the complete byte sequence in one go
}
public void evaluateCommand(byte cmd, int dataSize) {
int i;
int icmd = (int)(cmd&0xFF);
switch(icmd) {
case MSP_IDENT:
version = read8();
multiType = read8();
read8(); // MSP version
multiCapability = read32();// capability
if ((multiCapability&1)>0) {buttonRXbind = controlP5.addButton("bRXbind",1,10,yGraph+205-10,55,10); buttonRXbind.setColorBackground(blue_);buttonRXbind.setLabel("RX Bind");}
if ((multiCapability&4)>0) controlP5.addTab("Motors").show();
if ((multiCapability&8)>0) flaps=true;
if (!GraphicsInited) create_ServoGraphics();
break;
case MSP_STATUS:
cycleTime = read16();
i2cError = read16();
present = read16();
mode = read32();
if ((present&1) >0) {buttonAcc.setColorBackground(green_);} else {buttonAcc.setColorBackground(red_);tACC_ROLL.setState(false); tACC_PITCH.setState(false); tACC_Z.setState(false);}
if ((present&2) >0) {buttonBaro.setColorBackground(green_);} else {buttonBaro.setColorBackground(red_); tBARO.setState(false); }
if ((present&4) >0) {buttonMag.setColorBackground(green_); Mag_=true;} else {buttonMag.setColorBackground(red_); tMAGX.setState(false); tMAGY.setState(false); tMAGZ.setState(false);}
if ((present&8) >0) {buttonGPS.setColorBackground(green_);} else {buttonGPS.setColorBackground(red_); tHEAD.setState(false);}
if ((present&16)>0) {buttonSonar.setColorBackground(green_);} else {buttonSonar.setColorBackground(red_);}
for(i=0;i<CHECKBOXITEMS;i++) {if ((mode&(1<<i))>0) buttonCheckbox[i].setColorBackground(green_); else buttonCheckbox[i].setColorBackground(red_);}
confSetting.setValue(read8());
confSetting.setColorBackground(green_);
break;
case MSP_RAW_IMU:
ax = read16();ay = read16();az = read16();
if (ActiveTab=="Motors"){ // Show unfilterd values in graph.
gx = read16();gy = read16();gz = read16();
magx = read16();magy = read16();magz = read16();
}else{
gx = read16()/8;gy = read16()/8;gz = read16()/8;
magx = read16()/3;magy = read16()/3;magz = read16()/3;
}break;
case MSP_SERVO:for(i=0;i<8;i++) servo[i] = read16(); break;
case MSP_MOTOR: for(i=0;i<8;i++){ mot[i] = read16();}
if (multiType == SINGLECOPTER)servo[7]=mot[0];
if (multiType == DUALCOPTER){servo[7]=mot[0];servo[6]=mot[1];}
break;
case MSP_RC:
for(i=0;i<8;i++) {
RCChan[i]=read16();
TX_StickSlider[i].setValue(RCChan[i]);
}
break;
case MSP_RAW_GPS:
GPS_fix = read8();
GPS_numSat = read8();
GPS_latitude = read32();
GPS_longitude = read32();
GPS_altitude = read16();
GPS_speed = read16(); break;
case MSP_COMP_GPS:
GPS_distanceToHome = read16();
GPS_directionToHome = read16();
GPS_update = read8(); break;
case MSP_ATTITUDE:
angx = read16()/10;angy = read16()/10;
head = read16(); break;
case MSP_ALTITUDE: alt = read32(); break;
case MSP_ANALOG:
bytevbat = read8();
pMeterSum = read16();
rssi = read16(); if(rssi!=0)VBat[5].setValue(rssi).show(); // rssi
amperage = read16(); // amperage
VBat[4].setValue(bytevbat/10.0); // Volt
break;
case MSP_RC_TUNING:
byteRC_RATE = read8();byteRC_EXPO = read8();byteRollPitchRate = read8();
byteYawRate = read8();byteDynThrPID = read8();
byteThrottle_MID = read8();byteThrottle_EXPO = read8();
confRC_RATE.setValue(byteRC_RATE/100.0);
confRC_EXPO.setValue(byteRC_EXPO/100.0);
rollPitchRate.setValue(byteRollPitchRate/100.0);
yawRate.setValue(byteYawRate/100.0);
dynamic_THR_PID.setValue(byteDynThrPID/100.0);
throttle_MID.setValue(byteThrottle_MID/100.0);
throttle_EXPO.setValue(byteThrottle_EXPO/100.0);
confRC_RATE.setColorBackground(green_);confRC_EXPO.setColorBackground(green_);rollPitchRate.setColorBackground(green_);
yawRate.setColorBackground(green_);dynamic_THR_PID.setColorBackground(green_);
throttle_MID.setColorBackground(green_);throttle_EXPO.setColorBackground(green_);
updateModelMSP_SET_RC_TUNING();
break;
case MSP_ACC_CALIBRATION:break;
case MSP_MAG_CALIBRATION:break;
case MSP_PID:
for(i=0;i<PIDITEMS;i++) {
byteP[i] = read8();byteI[i] = read8();byteD[i] = read8();
switch (i) {
case 0:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
case 1:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
case 2:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
case 3:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
case 7:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
case 8:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
case 9:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/1000.0);confD[i].setValue(byteD[i]);break;
//Different rates fot POS-4 POSR-5 NAVR-6
case 4:confP[i].setValue(byteP[i]/100.0);confI[i].setValue(byteI[i]/100.0);confD[i].setValue(byteD[i]/1000.0);break;
case 5:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/100.0);confD[i].setValue(byteD[i]/1000.0);break;
case 6:confP[i].setValue(byteP[i]/10.0);confI[i].setValue(byteI[i]/100.0);confD[i].setValue(byteD[i]/1000.0);break;
}
confP[i].setColorBackground(green_);confI[i].setColorBackground(green_);confD[i].setColorBackground(green_);
}
updateModelMSP_SET_PID();
break;
case MSP_BOX:
for( i=0;i<CHECKBOXITEMS;i++) {
activation[i] = read16();
for(int aa=0;aa<12;aa++) {
if ((activation[i]&(1<<aa))>0) {checkbox[i].activate(aa);}else {checkbox[i].deactivate(aa);}}} break;
case MSP_BOXNAMES:
create_checkboxes(new String(inBuf, 0, dataSize).split(";"));break;
case MSP_PIDNAMES:
/* TODO create GUI elements from this message */
//System.out.println("Got PIDNAMES: "+new String(inBuf, 0, dataSize));
break;
case MSP_SERVO_CONF:
Bbox.deactivateAll();
// min:2 / max:2 / middle:2 / rate:1
for( i=0;i<8;i++){
ServoMIN[i] = read16();
ServoMAX[i] = read16();
ServoMID[i] = read16();
servoRATE[i] = read8() ;
}
if (multiType == AIRPLANE ) { // Airplane OK
if(flaps) {
//ServoSliderC[2].setMin(4).setMax(10);
if(ServoMID[2]==4) {Cau0();}else if(ServoMID[2]==5) {Cau1();}else if(ServoMID[2]==6) {Cau2();}else if(ServoMID[2]==7){Cau3();}else{CauClear();}
}
for( i=0;i<8;i++){
ServoSliderMIN[i].setValue(ServoMIN[i]); //Update sliders
ServoSliderMAX[i].setValue(ServoMAX[i]);
ServoSliderC[i].setValue(ServoMID[i]);
if (servoRATE[i]>127){ // Reverse/Rate servos
Bbox.deactivate(i); RateSlider[i].setValue(abs(servoRATE[i]-256));
}else{
Bbox.activate(i); RateSlider[i].setValue(abs(servoRATE[i]));
}
}
} else if (multiType == FLYING_WING || multiType == TRI || multiType == BI || multiType == DUALCOPTER || multiType == SINGLECOPTER) { // FlyingWing & TRI & BI
int nBoxes;
for( i=0;i<8;i++){ //Update sliders
ServoSliderMIN[i].setValue(ServoMIN[i]);
ServoSliderMAX[i].setValue(ServoMAX[i]);
ServoSliderC[i].setValue(ServoMID[i]);
if (servoRATE[i]>127){ // Reverse/Rate servos
wingDir[i]=-1; RateSlider[i].setValue((servoRATE[i]-256));
}else{ wingDir[i]=1; RateSlider[i].setValue(abs(servoRATE[i])); } // Servo Direction
}
if(multiType == FLYING_WING) { //OK
if ((servoRATE[3]&1)<1) {Wbox.deactivate(2);}else{Wbox.activate(2);} //
if ((servoRATE[3]&2)<1) {Wbox.deactivate(0);}else{Wbox.activate(0);} //
if ((servoRATE[4]&1)<1) {Wbox.deactivate(3);}else{Wbox.activate(3);} //
if ((servoRATE[4]&2)<1) {Wbox.deactivate(1);}else{Wbox.activate(1);} //
} else if(multiType == SINGLECOPTER) { //
if ((servoRATE[3]&1)<1) {Wbox.deactivate(0);}else{Wbox.activate(0);} //
if ((servoRATE[3]&2)<1) {Wbox.deactivate(1);}else{Wbox.activate(1);} //
if ((servoRATE[4]&1)<1) {Wbox.deactivate(2);}else{Wbox.activate(2);} //
if ((servoRATE[4]&2)<1) {Wbox.deactivate(3);}else{Wbox.activate(3);} //
if ((servoRATE[5]&1)<1) {Wbox.deactivate(4);}else{Wbox.activate(4);} //
if ((servoRATE[5]&2)<1) {Wbox.deactivate(5);}else{Wbox.activate(5);} //
if ((servoRATE[6]&1)<1) {Wbox.deactivate(6);}else{Wbox.activate(6);} //
if ((servoRATE[6]&2)<1) {Wbox.deactivate(7);}else{Wbox.activate(7);} //
} else if(multiType == DUALCOPTER) { // OK
if ((servoRATE[4]&1)<1) {Wbox.deactivate(0);}else{Wbox.activate(0);}
if ((servoRATE[5]&1)<1) {Wbox.deactivate(1);}else{Wbox.activate(1);}
} else if (multiType == TRI) {// OK
if ((servoRATE[5]&1)<1) {Wbox.deactivate(0);}else{Wbox.activate(0);}
} else if( multiType == BI) {// OK
if ((servoRATE[4]&2)<1) {Wbox.deactivate(0);}else{Wbox.activate(0);} // L
if ((servoRATE[5]&2)<1) {Wbox.deactivate(1);}else{Wbox.activate(1);}
if ((servoRATE[4]&1)<1) {Wbox.deactivate(2);}else{Wbox.activate(2);} // R
if ((servoRATE[5]&1)<1) {Wbox.deactivate(3);}else{Wbox.activate(3);}
}
}else if (multiType == HELI_120_CCPM || multiType == HELI_90_DEG) {
for( i=0;i<8;i++) { //Update sliders
ServoSliderMIN[i].setValue(ServoMIN[i]);
ServoSliderMAX[i].setValue(ServoMAX[i]);
ServoSliderC[i].setValue(ServoMID[i]);
if (servoRATE[i]>127){ // Reverse/Rate servos
Bbox.deactivate(i); RateSlider[i].setValue((servoRATE[i]-256));
}else{ Bbox.activate(i); RateSlider[i].setValue(abs(servoRATE[i]));}
}
if ((servoRATE[5]&1)<1) {Bbox.deactivate(5);}else{Bbox.activate(5);} // YawReverse
if(multiType == HELI_120_CCPM) { //bbb
if ((servoRATE[3]&1)<1) {Mbox.deactivate(2);}else{Mbox.activate(2);} // roll
if ((servoRATE[3]&2)<1) {Mbox.deactivate(1);}else{Mbox.activate(1);} // nick
if ((servoRATE[3]&4)<1) {Mbox.deactivate(0);}else{Mbox.activate(0);} // coll
if ((servoRATE[4]&1)<1) {Mbox.deactivate(5);}else{Mbox.activate(5);} //
if ((servoRATE[4]&2)<1) {Mbox.deactivate(4);}else{Mbox.activate(4);} //
if ((servoRATE[4]&4)<1) {Mbox.deactivate(3);}else{Mbox.activate(3);} //
if ((servoRATE[6]&1)<1) {Mbox.deactivate(8);}else{Mbox.activate(8);} //
if ((servoRATE[6]&2)<1) {Mbox.deactivate(7);}else{Mbox.activate(7);} //
if ((servoRATE[6]&4)<1) {Mbox.deactivate(6);}else{Mbox.activate(6);} //
}
}else if (multiType == PPM_TO_SERVO ) { // PPM_TO_SERVO
for( i=0;i<8;i++){
ServoSliderMIN[i].setValue(ServoMIN[i]); //Update sliders
ServoSliderMAX[i].setValue(ServoMAX[i]);
ServoSliderC[i] .setValue(ServoMID[i]);
// Reverse/Rate servos
if (servoRATE[i]>127){
Bbox.deactivate(i); RateSlider[i].setValue(abs(servoRATE[i]-256));
}else{Bbox.activate(i); RateSlider[i].setValue(abs(servoRATE[i]));}
}