-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTuning.java
More file actions
1359 lines (1195 loc) · 51.2 KB
/
Tuning.java
File metadata and controls
1359 lines (1195 loc) · 51.2 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
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
package org.firstinspires.ftc.teamcode.pedroPathing;
import static org.firstinspires.ftc.teamcode.pedroPathing.Tuning.changes;
import static org.firstinspires.ftc.teamcode.pedroPathing.Tuning.drawOnlyCurrent;
import static org.firstinspires.ftc.teamcode.pedroPathing.Tuning.draw;
import static org.firstinspires.ftc.teamcode.pedroPathing.Tuning.follower;
import static org.firstinspires.ftc.teamcode.pedroPathing.Tuning.stopRobot;
import static org.firstinspires.ftc.teamcode.pedroPathing.Tuning.telemetryM;
import com.bylazar.configurables.PanelsConfigurables;
import com.bylazar.configurables.annotations.Configurable;
import com.bylazar.configurables.annotations.IgnoreConfigurable;
import com.bylazar.field.FieldManager;
import com.bylazar.field.PanelsField;
import com.bylazar.field.Style;
import com.bylazar.telemetry.PanelsTelemetry;
import com.bylazar.telemetry.TelemetryManager;
import com.pedropathing.ErrorCalculator;
import com.pedropathing.follower.Follower;
import com.pedropathing.geometry.*;
import com.pedropathing.math.*;
import com.pedropathing.paths.*;
import com.pedropathing.telemetry.SelectableOpMode;
import com.pedropathing.util.*;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import java.util.ArrayList;
import java.util.List;
/**
* This is the Tuning class. It contains a selection menu for various tuning OpModes.
*
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 6/26/2025
*/
@Configurable
@TeleOp(name = "Tuning", group = "Pedro Pathing")
public class Tuning extends SelectableOpMode {
public static Follower follower;
@IgnoreConfigurable
static PoseHistory poseHistory;
@IgnoreConfigurable
static TelemetryManager telemetryM;
@IgnoreConfigurable
static ArrayList<String> changes = new ArrayList<>();
public Tuning() {
super("Select a Tuning OpMode", s -> {
s.folder("Localization", l -> {
l.add("Localization Test", LocalizationTest::new);
l.add("Forward Tuner", ForwardTuner::new);
l.add("Lateral Tuner", LateralTuner::new);
l.add("Turn Tuner", TurnTuner::new);
});
s.folder("Automatic", a -> {
a.add("Forward Velocity Tuner", ForwardVelocityTuner::new);
a.add("Lateral Velocity Tuner", LateralVelocityTuner::new);
a.add("Forward Zero Power Acceleration Tuner", ForwardZeroPowerAccelerationTuner::new);
a.add("Lateral Zero Power Acceleration Tuner", LateralZeroPowerAccelerationTuner::new);
});
s.folder("Manual", p -> {
p.add("Translational Tuner", TranslationalTuner::new);
p.add("Heading Tuner", HeadingTuner::new);
p.add("Drive Tuner", DriveTuner::new);
p.add("Line Tuner", Line::new);
p.add("Centripetal Tuner", CentripetalTuner::new);
});
s.folder("Tests", p -> {
p.add("Line", Line::new);
p.add("Triangle", Triangle::new);
p.add("Circle", Circle::new);
});
});
}
@Override
public void onSelect() {
if (follower == null) {
follower = Constants.createFollower(hardwareMap);
PanelsConfigurables.INSTANCE.refreshClass(this);
} else {
follower = Constants.createFollower(hardwareMap);
}
follower.setStartingPose(new Pose());
poseHistory = follower.getPoseHistory();
telemetryM = PanelsTelemetry.INSTANCE.getTelemetry();
Drawing.init();
}
@Override
public void onLog(List<String> lines) {}
public static void drawOnlyCurrent() {
try {
Drawing.drawRobot(follower.getPose());
Drawing.sendPacket();
} catch (Exception e) {
throw new RuntimeException("Drawing failed " + e);
}
}
public static void draw() {
Drawing.drawDebug(follower);
}
/** This creates a full stop of the robot by setting the drive motors to run at 0 power. */
public static void stopRobot() {
follower.startTeleopDrive(true);
follower.setTeleOpDrive(0,0,0,true);
}
}
/**
* This is the LocalizationTest OpMode. This is basically just a simple mecanum drive attached to a
* PoseUpdater. The OpMode will print out the robot's pose to telemetry as well as draw the robot.
* You should use this to check the robot's localization.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 5/6/2024
*/
class LocalizationTest extends OpMode {
@Override
public void init() {
follower.setStartingPose(new Pose(72,72));
}
/** This initializes the PoseUpdater, the mecanum drive motors, and the Panels telemetry. */
@Override
public void init_loop() {
telemetryM.debug("This will print your robot's position to telemetry while "
+ "allowing robot control through a basic mecanum drive on gamepad 1.");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
@Override
public void start() {
follower.startTeleopDrive();
follower.update();
}
/**
* This updates the robot's pose estimate, the simple mecanum drive, and updates the
* Panels telemetry with the robot's position as well as draws the robot's position.
*/
@Override
public void loop() {
follower.setTeleOpDrive(-gamepad1.left_stick_y, -gamepad1.left_stick_x, -gamepad1.right_stick_x, true);
follower.update();
telemetryM.debug("x:" + follower.getPose().getX());
telemetryM.debug("y:" + follower.getPose().getY());
telemetryM.debug("heading:" + follower.getPose().getHeading());
telemetryM.debug("total heading:" + follower.getTotalHeading());
telemetryM.update(telemetry);
draw();
}
}
/**
* This is the ForwardTuner OpMode. This tracks the forward movement of the robot and displays the
* necessary ticks to inches multiplier. This displayed multiplier is what's necessary to scale the
* robot's current distance in ticks to the specified distance in inches. So, to use this, run the
* tuner, then pull/push the robot to the specified distance using a ruler on the ground. When you're
* at the end of the distance, record the ticks to inches multiplier. Feel free to run multiple trials
* and average the results. Then, input the multiplier into the forward ticks to inches in your
* localizer of choice.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 5/6/2024
*/
class ForwardTuner extends OpMode {
public static double DISTANCE = 48;
@Override
public void init() {
follower.setStartingPose(new Pose(72,72));
follower.update();
drawOnlyCurrent();
}
/** This initializes the PoseUpdater as well as the Panels telemetry. */
@Override
public void init_loop() {
telemetryM.debug("Pull your robot forward " + DISTANCE + " inches. Your forward ticks to inches will be shown on the telemetry.");
telemetryM.update(telemetry);
drawOnlyCurrent();
}
/**
* This updates the robot's pose estimate, and updates the Panels telemetry with the
* calculated multiplier and draws the robot.
*/
@Override
public void loop() {
follower.update();
telemetryM.debug("Distance Moved: " + (follower.getPose().getX() - 72));
telemetryM.debug("The multiplier will display what your forward ticks to inches should be to scale your current distance to " + DISTANCE + " inches.");
telemetryM.debug("Multiplier: " + (DISTANCE / ((follower.getPose().getX() - 72) / follower.getPoseTracker().getLocalizer().getForwardMultiplier())));
telemetryM.update(telemetry);
draw();
}
}
/**
* This is the LateralTuner OpMode. This tracks the strafe movement of the robot and displays the
* necessary ticks to inches multiplier. This displayed multiplier is what's necessary to scale the
* robot's current distance in ticks to the specified distance in inches. So, to use this, run the
* tuner, then pull/push the robot to the specified distance using a ruler on the ground. When you're
* at the end of the distance, record the ticks to inches multiplier. Feel free to run multiple trials
* and average the results. Then, input the multiplier into the strafe ticks to inches in your
* localizer of choice.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 2.0, 6/26/2025
*/
class LateralTuner extends OpMode {
public static double DISTANCE = 48;
@Override
public void init() {
follower.setStartingPose(new Pose(72,72));
follower.update();
drawOnlyCurrent();
}
/** This initializes the PoseUpdater as well as the Panels telemetry. */
@Override
public void init_loop() {
telemetryM.debug("Pull your robot to the right " + DISTANCE + " inches. Your strafe ticks to inches will be shown on the telemetry.");
telemetryM.update(telemetry);
drawOnlyCurrent();
}
/**
* This updates the robot's pose estimate, and updates the Panels telemetry with the
* calculated multiplier and draws the robot.
*/
@Override
public void loop() {
follower.update();
telemetryM.debug("Distance Moved: " + (follower.getPose().getY() - 72));
telemetryM.debug("The multiplier will display what your strafe ticks to inches should be to scale your current distance to " + DISTANCE + " inches.");
telemetryM.debug("Multiplier: " + (DISTANCE / ((follower.getPose().getY() - 72) / follower.getPoseTracker().getLocalizer().getLateralMultiplier())));
telemetryM.update(telemetry);
draw();
}
}
/**
* This is the TurnTuner OpMode. This tracks the turning movement of the robot and displays the
* necessary ticks to inches multiplier. This displayed multiplier is what's necessary to scale the
* robot's current angle in ticks to the specified angle in radians. So, to use this, run the
* tuner, then pull/push the robot to the specified angle using a protractor or lines on the ground.
* When you're at the end of the angle, record the ticks to inches multiplier. Feel free to run
* multiple trials and average the results. Then, input the multiplier into the turning ticks to
* radians in your localizer of choice.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 5/6/2024
*/
class TurnTuner extends OpMode {
public static double ANGLE = 2 * Math.PI;
@Override
public void init() {
follower.setStartingPose(new Pose(72,72));
follower.update();
drawOnlyCurrent();
}
/** This initializes the PoseUpdater as well as the Panels telemetry. */
@Override
public void init_loop() {
telemetryM.debug("Turn your robot " + ANGLE + " radians. Your turn ticks to inches will be shown on the telemetry.");
telemetryM.update(telemetry);
drawOnlyCurrent();
}
/**
* This updates the robot's pose estimate, and updates the Panels telemetry with the
* calculated multiplier and draws the robot.
*/
@Override
public void loop() {
follower.update();
telemetryM.debug("Total Angle: " + follower.getTotalHeading());
telemetryM.debug("The multiplier will display what your turn ticks to inches should be to scale your current angle to " + ANGLE + " radians.");
telemetryM.debug("Multiplier: " + (ANGLE / (follower.getTotalHeading() / follower.getPoseTracker().getLocalizer().getTurningMultiplier())));
telemetryM.update(telemetry);
draw();
}
}
/**
* This is the ForwardVelocityTuner autonomous follower OpMode. This runs the robot forwards at max
* power until it reaches some specified distance. It records the most recent velocities, and on
* reaching the end of the distance, it averages them and prints out the velocity obtained. It is
* recommended to run this multiple times on a full battery to get the best results. What this does
* is, when paired with StrafeVelocityTuner, allows FollowerConstants to create a Vector that
* empirically represents the direction your mecanum wheels actually prefer to go in, allowing for
* more accurate following.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 3/13/2024
*/
class ForwardVelocityTuner extends OpMode {
private final ArrayList<Double> velocities = new ArrayList<>();
public static double DISTANCE = 48;
public static double RECORD_NUMBER = 10;
private boolean end;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/** This initializes the drive motors as well as the cache of velocities and the Panels telemetry. */
@Override
public void init_loop() {
telemetryM.debug("The robot will run at 1 power until it reaches " + DISTANCE + " inches forward.");
telemetryM.debug("Make sure you have enough room, since the robot has inertia after cutting power.");
telemetryM.debug("After running the distance, the robot will cut power from the drivetrain and display the forward velocity.");
telemetryM.debug("Press B on game pad 1 to stop.");
telemetryM.debug("pose", follower.getPose());
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
/** This starts the OpMode by setting the drive motors to run forward at full power. */
@Override
public void start() {
for (int i = 0; i < RECORD_NUMBER; i++) {
velocities.add(0.0);
}
follower.startTeleopDrive(true);
follower.update();
end = false;
}
/**
* This runs the OpMode. At any point during the running of the OpMode, pressing B on
* game pad 1 will stop the OpMode. This continuously records the RECORD_NUMBER most recent
* velocities, and when the robot has run forward enough, these last velocities recorded are
* averaged and printed.
*/
@Override
public void loop() {
if (gamepad1.bWasPressed()) {
stopRobot();
requestOpModeStop();
}
follower.update();
draw();
if (!end) {
if (Math.abs(follower.getPose().getX()) > (DISTANCE + 72)) {
end = true;
stopRobot();
} else {
follower.setTeleOpDrive(1,0,0,true);
//double currentVelocity = Math.abs(follower.getVelocity().getXComponent());
double currentVelocity = Math.abs(follower.poseTracker.getLocalizer().getVelocity().getX());
velocities.add(currentVelocity);
velocities.remove(0);
}
} else {
stopRobot();
double average = 0;
for (double velocity : velocities) {
average += velocity;
}
average /= velocities.size();
telemetryM.debug("Forward Velocity: " + average);
telemetryM.debug("\n");
telemetryM.debug("Press A to set the Forward Velocity temporarily (while robot remains on).");
for (int i = 0; i < velocities.size(); i++) {
telemetry.addData(String.valueOf(i), velocities.get(i));
}
telemetryM.update(telemetry);
telemetry.update();
if (gamepad1.aWasPressed()) {
follower.setXVelocity(average);
String message = "XMovement: " + average;
changes.add(message);
}
}
}
}
/**
* This is the StrafeVelocityTuner autonomous follower OpMode. This runs the robot left at max
* power until it reaches some specified distance. It records the most recent velocities, and on
* reaching the end of the distance, it averages them and prints out the velocity obtained. It is
* recommended to run this multiple times on a full battery to get the best results. What this does
* is, when paired with ForwardVelocityTuner, allows FollowerConstants to create a Vector that
* empirically represents the direction your mecanum wheels actually prefer to go in, allowing for
* more accurate following.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 3/13/2024
*/
class LateralVelocityTuner extends OpMode {
private final ArrayList<Double> velocities = new ArrayList<>();
public static double DISTANCE = 48;
public static double RECORD_NUMBER = 10;
private boolean end;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/**
* This initializes the drive motors as well as the cache of velocities and the Panels
* telemetryM.
*/
@Override
public void init_loop() {
telemetryM.debug("The robot will run at 1 power until it reaches " + DISTANCE + " inches to the left.");
telemetryM.debug("Make sure you have enough room, since the robot has inertia after cutting power.");
telemetryM.debug("After running the distance, the robot will cut power from the drivetrain and display the strafe velocity.");
telemetryM.debug("Press B on Gamepad 1 to stop.");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
/** This starts the OpMode by setting the drive motors to run left at full power. */
@Override
public void start() {
for (int i = 0; i < RECORD_NUMBER; i++) {
velocities.add(0.0);
}
follower.startTeleopDrive(true);
follower.update();
}
/**
* This runs the OpMode. At any point during the running of the OpMode, pressing B on
* game pad1 will stop the OpMode. This continuously records the RECORD_NUMBER most recent
* velocities, and when the robot has run sideways enough, these last velocities recorded are
* averaged and printed.
*/
@Override
public void loop() {
if (gamepad1.bWasPressed()) {
stopRobot();
requestOpModeStop();
}
follower.update();
draw();
if (!end) {
if (Math.abs(follower.getPose().getY()) > (DISTANCE + 72)) {
end = true;
stopRobot();
} else {
follower.setTeleOpDrive(0,1,0,true);
double currentVelocity = Math.abs(follower.getVelocity().dot(new Vector(1, Math.PI / 2)));
velocities.add(currentVelocity);
velocities.remove(0);
}
} else {
stopRobot();
double average = 0;
for (double velocity : velocities) {
average += velocity;
}
average /= velocities.size();
telemetryM.debug("Strafe Velocity: " + average);
telemetryM.debug("\n");
telemetryM.debug("Press A to set the Lateral Velocity temporarily (while robot remains on).");
telemetryM.update(telemetry);
if (gamepad1.aWasPressed()) {
follower.setYVelocity(average);
String message = "YMovement: " + average;
changes.add(message);
}
}
}
}
/**
* This is the ForwardZeroPowerAccelerationTuner autonomous follower OpMode. This runs the robot
* forward until a specified velocity is achieved. Then, the robot cuts power to the motors, setting
* them to zero power. The deceleration, or negative acceleration, is then measured until the robot
* stops. The accelerations across the entire time the robot is slowing down is then averaged and
* that number is then printed. This is used to determine how the robot will decelerate in the
* forward direction when power is cut, making the estimations used in the calculations for the
* drive Vector more accurate and giving better braking at the end of Paths.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @version 1.0, 3/13/2024
*/
class ForwardZeroPowerAccelerationTuner extends OpMode {
private final ArrayList<Double> accelerations = new ArrayList<>();
public static double VELOCITY = 30;
private double previousVelocity;
private long previousTimeNano;
private boolean stopping;
private boolean end;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/** This initializes the drive motors as well as the Panels telemetryM. */
@Override
public void init_loop() {
telemetryM.debug("The robot will run forward until it reaches " + VELOCITY + " inches per second.");
telemetryM.debug("Then, it will cut power from the drivetrain and roll to a stop.");
telemetryM.debug("Make sure you have enough room.");
telemetryM.debug("After stopping, the forward zero power acceleration (natural deceleration) will be displayed.");
telemetryM.debug("Press B on Gamepad 1 to stop.");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
/** This starts the OpMode by setting the drive motors to run forward at full power. */
@Override
public void start() {
follower.startTeleopDrive(false);
follower.update();
follower.setTeleOpDrive(1,0,0,true);
}
/**
* This runs the OpMode. At any point during the running of the OpMode, pressing B on
* game pad 1 will stop the OpMode. When the robot hits the specified velocity, the robot will
* record its deceleration / negative acceleration until it stops. Then, it will average all the
* recorded deceleration / negative acceleration and print that value.
*/
@Override
public void loop() {
if (gamepad1.bWasPressed()) {
stopRobot();
requestOpModeStop();
}
follower.update();
draw();
Vector heading = new Vector(1.0, follower.getPose().getHeading());
if (!end) {
if (!stopping) {
if (follower.getVelocity().dot(heading) > VELOCITY) {
previousVelocity = follower.getVelocity().dot(heading);
previousTimeNano = System.nanoTime();
stopping = true;
follower.setTeleOpDrive(0,0,0,true);
}
} else {
double currentVelocity = follower.getVelocity().dot(heading);
accelerations.add((currentVelocity - previousVelocity) / ((System.nanoTime() - previousTimeNano) / Math.pow(10.0, 9)));
previousVelocity = currentVelocity;
previousTimeNano = System.nanoTime();
if (currentVelocity < follower.getConstraints().getVelocityConstraint()) {
end = true;
}
}
} else {
double average = 0;
for (double acceleration : accelerations) {
average += acceleration;
}
average /= accelerations.size();
telemetryM.debug("Forward Zero Power Acceleration (Deceleration): " + average);
telemetryM.debug("\n");
telemetryM.debug("Press A to set the Forward Zero Power Acceleration temporarily (while robot remains on).");
telemetryM.update(telemetry);
if (gamepad1.aWasPressed()) {
follower.getConstants().setForwardZeroPowerAcceleration(average);
String message = "Forward Zero Power Acceleration: " + average;
changes.add(message);
}
}
}
}
/**
* This is the LateralZeroPowerAccelerationTuner autonomous follower OpMode. This runs the robot
* to the left until a specified velocity is achieved. Then, the robot cuts power to the motors, setting
* them to zero power. The deceleration, or negative acceleration, is then measured until the robot
* stops. The accelerations across the entire time the robot is slowing down is then averaged and
* that number is then printed. This is used to determine how the robot will decelerate in the
* forward direction when power is cut, making the estimations used in the calculations for the
* drive Vector more accurate and giving better braking at the end of Paths.
*
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @author Baron Henderson - 20077 The Indubitables
* @version 1.0, 3/13/2024
*/
class LateralZeroPowerAccelerationTuner extends OpMode {
private final ArrayList<Double> accelerations = new ArrayList<>();
public static double VELOCITY = 30;
private double previousVelocity;
private long previousTimeNano;
private boolean stopping;
private boolean end;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/** This initializes the drive motors as well as the Panels telemetry. */
@Override
public void init_loop() {
telemetryM.debug("The robot will run to the left until it reaches " + VELOCITY + " inches per second.");
telemetryM.debug("Then, it will cut power from the drivetrain and roll to a stop.");
telemetryM.debug("Make sure you have enough room.");
telemetryM.debug("After stopping, the lateral zero power acceleration (natural deceleration) will be displayed.");
telemetryM.debug("Press B on game pad 1 to stop.");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
/** This starts the OpMode by setting the drive motors to run forward at full power. */
@Override
public void start() {
follower.startTeleopDrive(false);
follower.update();
follower.setTeleOpDrive(0,1,0,true);
}
/**
* This runs the OpMode. At any point during the running of the OpMode, pressing B on
* game pad 1 will stop the OpMode. When the robot hits the specified velocity, the robot will
* record its deceleration / negative acceleration until it stops. Then, it will average all the
* recorded deceleration / negative acceleration and print that value.
*/
@Override
public void loop() {
if (gamepad1.bWasPressed()) {
stopRobot();
requestOpModeStop();
}
follower.update();
draw();
Vector heading = new Vector(1.0, follower.getPose().getHeading() - Math.PI / 2);
if (!end) {
if (!stopping) {
if (Math.abs(follower.getVelocity().dot(heading)) > VELOCITY) {
previousVelocity = Math.abs(follower.getVelocity().dot(heading));
previousTimeNano = System.nanoTime();
stopping = true;
follower.setTeleOpDrive(0,0,0,true);
}
} else {
double currentVelocity = Math.abs(follower.getVelocity().dot(heading));
accelerations.add((currentVelocity - previousVelocity) / ((System.nanoTime() - previousTimeNano) / Math.pow(10.0, 9)));
previousVelocity = currentVelocity;
previousTimeNano = System.nanoTime();
if (currentVelocity < follower.getConstraints().getVelocityConstraint()) {
end = true;
}
}
} else {
double average = 0;
for (double acceleration : accelerations) {
average += acceleration;
}
average /= accelerations.size();
telemetryM.debug("Lateral Zero Power Acceleration (Deceleration): " + average);
telemetryM.debug("\n");
telemetryM.debug("Press A to set the Lateral Zero Power Acceleration temporarily (while robot remains on).");
telemetryM.update(telemetry);
if (gamepad1.aWasPressed()) {
follower.getConstants().setLateralZeroPowerAcceleration(average);
String message = "Lateral Zero Power Acceleration: " + average;
changes.add(message);
}
}
}
}
/**
* This is the Translational PIDF Tuner OpMode. It will keep the robot in place.
* The user should push the robot laterally to test the PIDF and adjust the PIDF values accordingly.
*
* @author Baron Henderson - 20077 The Indubitables
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @version 1.0, 3/12/2024
*/
class TranslationalTuner extends OpMode {
public static double DISTANCE = 40;
private boolean forward = true;
private Path forwards;
private Path backwards;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/** This initializes the Follower and creates the forward and backward Paths. */
@Override
public void init_loop() {
telemetryM.debug("This will activate the translational PIDF(s)");
telemetryM.debug("The robot will try to stay in place while you push it laterally.");
telemetryM.debug("You can adjust the PIDF values to tune the robot's translational PIDF(s).");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
@Override
public void start() {
follower.deactivateAllPIDFs();
follower.activateTranslational();
forwards = new Path(new BezierLine(new Pose(72,72), new Pose(DISTANCE + 72,72)));
forwards.setConstantHeadingInterpolation(0);
backwards = new Path(new BezierLine(new Pose(DISTANCE + 72,72), new Pose(72,72)));
backwards.setConstantHeadingInterpolation(0);
follower.followPath(forwards);
}
/** This runs the OpMode, updating the Follower as well as printing out the debug statements to the Telemetry */
@Override
public void loop() {
follower.update();
draw();
if (!follower.isBusy()) {
if (forward) {
forward = false;
follower.followPath(backwards);
} else {
forward = true;
follower.followPath(forwards);
}
}
telemetryM.debug("Push the robot laterally to test the Translational PIDF(s).");
telemetryM.addData("Zero Line", 0);
telemetryM.addData("Error X", follower.errorCalculator.getTranslationalError().getXComponent());
telemetryM.addData("Error Y", follower.errorCalculator.getTranslationalError().getYComponent());
telemetryM.update(telemetry);
}
}
/**
* This is the Heading PIDF Tuner OpMode. It will keep the robot in place.
* The user should try to turn the robot to test the PIDF and adjust the PIDF values accordingly.
* It will try to keep the robot at a constant heading while the user tries to turn it.
*
* @author Baron Henderson - 20077 The Indubitables
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @version 1.0, 3/12/2024
*/
class HeadingTuner extends OpMode {
public static double DISTANCE = 40;
private boolean forward = true;
private Path forwards;
private Path backwards;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/**
* This initializes the Follower and creates the forward and backward Paths. Additionally, this
* initializes the Panels telemetry.
*/
@Override
public void init_loop() {
telemetryM.debug("This will activate the heading PIDF(s).");
telemetryM.debug("The robot will try to stay at a constant heading while you try to turn it.");
telemetryM.debug("You can adjust the PIDF values to tune the robot's heading PIDF(s).");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
@Override
public void start() {
follower.deactivateAllPIDFs();
follower.activateHeading();
forwards = new Path(new BezierLine(new Pose(72,72), new Pose(DISTANCE + 72,72)));
forwards.setConstantHeadingInterpolation(0);
backwards = new Path(new BezierLine(new Pose(DISTANCE + 72,72), new Pose(72,72)));
backwards.setConstantHeadingInterpolation(0);
follower.followPath(forwards);
}
/**
* This runs the OpMode, updating the Follower as well as printing out the debug statements to
* the Telemetry, as well as the Panels.
*/
@Override
public void loop() {
follower.update();
draw();
if (!follower.isBusy()) {
if (forward) {
forward = false;
follower.followPath(backwards);
} else {
forward = true;
follower.followPath(forwards);
}
}
telemetryM.debug("Turn the robot manually to test the Heading PIDF(s).");
telemetryM.addData("Zero Line", 0);
telemetryM.addData("Error", follower.errorCalculator.getHeadingError());
telemetryM.update(telemetry);
}
}
/**
* This is the Drive PIDF Tuner OpMode. It will run the robot in a straight line going forward and back.
*
* @author Baron Henderson - 20077 The Indubitables
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @version 1.0, 3/12/2024
*/
class DriveTuner extends OpMode {
public static double DISTANCE = 40;
private boolean forward = true;
private PathChain forwards;
private PathChain backwards;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/**
* This initializes the Follower and creates the forward and backward Paths. Additionally, this
* initializes the Panels telemetry.
*/
@Override
public void init_loop() {
telemetryM.debug("This will run the robot in a straight line going " + DISTANCE + "inches forward.");
telemetryM.debug("The robot will go forward and backward continuously along the path.");
telemetryM.debug("Make sure you have enough room.");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
@Override
public void start() {
follower.deactivateAllPIDFs();
follower.activateDrive();
forwards = follower.pathBuilder()
.setGlobalDeceleration()
.addPath(new BezierLine(new Pose(72,72), new Pose(DISTANCE + 72,72)))
.setConstantHeadingInterpolation(0)
.build();
backwards = follower.pathBuilder()
.setGlobalDeceleration()
.addPath(new BezierLine(new Pose(DISTANCE + 72,72), new Pose(72,72)))
.setConstantHeadingInterpolation(0)
.build();
follower.followPath(forwards);
}
/**
* This runs the OpMode, updating the Follower as well as printing out the debug statements to
* the Telemetry, as well as the Panels.
*/
@Override
public void loop() {
follower.update();
draw();
if (!follower.isBusy()) {
if (forward) {
forward = false;
follower.followPath(backwards);
} else {
forward = true;
follower.followPath(forwards);
}
}
telemetryM.debug("Driving forward?: " + forward);
telemetryM.addData("Zero Line", 0);
telemetryM.addData("Error", follower.errorCalculator.getDriveErrors()[1]);
telemetryM.update(telemetry);
}
}
/**
* This is the Line Test Tuner OpMode. It will drive the robot forward and back
* The user should push the robot laterally and angular to test out the drive, heading, and translational PIDFs.
*
* @author Baron Henderson - 20077 The Indubitables
* @author Anyi Lin - 10158 Scott's Bots
* @author Aaron Yang - 10158 Scott's Bots
* @author Harrison Womack - 10158 Scott's Bots
* @version 1.0, 3/12/2024
*/
class Line extends OpMode {
public static double DISTANCE = 40;
private boolean forward = true;
private Path forwards;
private Path backwards;
@Override
public void init() {
follower.setStartingPose(new Pose(72, 72));
}
/** This initializes the Follower and creates the forward and backward Paths. */
@Override
public void init_loop() {
telemetryM.debug("This will activate all the PIDF(s)");
telemetryM.debug("The robot will go forward and backward continuously along the path while correcting.");
telemetryM.debug("You can adjust the PIDF values to tune the robot's drive PIDF(s).");
telemetryM.update(telemetry);
follower.update();
drawOnlyCurrent();
}
@Override
public void start() {
follower.activateAllPIDFs();
forwards = new Path(new BezierLine(new Pose(72,72), new Pose(DISTANCE + 72,72)));
forwards.setConstantHeadingInterpolation(0);
backwards = new Path(new BezierLine(new Pose(DISTANCE + 72,72), new Pose(72,72)));
backwards.setConstantHeadingInterpolation(0);
follower.followPath(forwards);
}
/** This runs the OpMode, updating the Follower as well as printing out the debug statements to the Telemetry */
@Override