-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasketAuto.java
More file actions
143 lines (134 loc) · 5.21 KB
/
BasketAuto.java
File metadata and controls
143 lines (134 loc) · 5.21 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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import org.firstinspires.ftc.vision.VisionPortal;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.util.ElapsedTime;
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;
import java.util.List;
@Autonomous(name = "BasketAuto", preselectTeleOp = "finalDrive")
public class BasketAuto extends LinearOpMode
{
// keep this constant, even though it is duplicated in AutoCommon
final static double DRIVE_POWER = 0.5;
boolean gyroInit = false;
/**
* This function is executed when this OpMode is selected & Init is pressed
*/
@Override
public void runOpMode()
{
ElapsedTime programTime = new ElapsedTime();
AutoCommon lib = new AutoCommon(
hardwareMap);
lib.initAprilTag();
//double distanceToWall = lib.getAprilTagDetection(13, "y");
double deltaX = 0, deltaY = 0, deltaZ = 0;
while (!opModeIsActive() & !isStopRequested())
{
lib.resetArmEncoders();
lib.holdSpec();
//telemetry.addData("current detections", lib.getCurrentAprilTagIds());
telemetry.addData("tag 13 output", (lib.getAprilTag_BlueRight() == null));
if (lib.getAprilTag_BlueRight() != null) {
telemetry.addData("Distance to wall", lib.getAprilTag_BlueRight().ftcPose.y);
deltaY = lib.getAprilTag_BlueRight().ftcPose.y;
deltaX = lib.getAprilTag_BlueRight().ftcPose.x;
deltaZ = lib.getAprilTag_BlueRight().ftcPose.yaw;
telemetry.addLine("=============");
if (Math.abs(deltaZ-2) > 0.75) {
telemetry.addLine("CORRECTING ORIENTATION");
lib.drive(0, 0, -deltaZ-2, 0.1);
}
telemetry.addLine("READY TO START");
telemetry.addLine("DETECTED BLUE");
telemetry.addLine("=============");
if (gyroInit) {
telemetry.addData("Imu Orientation", lib.getImuYaw());
} else {
lib.initGyro();
gyroInit = true;
}
telemetry.addData("deltax", deltaX);
telemetry.addData("deltaY", deltaY);
telemetry.addData("deltaZ", deltaZ);
} else if (lib.getAprilTag_RedRight() != null) {
telemetry.addData("Distance to wall", lib.getAprilTag_RedRight().ftcPose.y);
deltaY = lib.getAprilTag_RedRight().ftcPose.y;
deltaX = lib.getAprilTag_RedRight().ftcPose.x;
deltaZ = lib.getAprilTag_RedRight().ftcPose.yaw;
telemetry.addLine("=============");
if (Math.abs(deltaZ-2) > 0.75) {
telemetry.addLine("CORRECTING ORIENTATION");
lib.drive(0, 0, -deltaZ-2, 0.1);
}
telemetry.addLine("READY TO START");
telemetry.addLine("DETECTED RED");
telemetry.addLine("=============");
if (gyroInit) {
telemetry.addData("Imu Orientation", lib.getImuYaw());
} else if (deltaZ < 0.75) {
lib.initGyro();
gyroInit = true;
}
telemetry.addData("deltax", deltaX);
telemetry.addData("deltaY", deltaY);
telemetry.addData("deltaZ", deltaZ);
} else {
telemetry.addLine("=============");
telemetry.addLine("NO TAGS DETECTED");
telemetry.addLine("=============");
}
telemetry.update();
}
// wait for user to press start on Driver Station
waitForStart();
lib.closeAprilTag();
if (opModeIsActive()) {
/************************************************************************
* START / RUN OPMODE CODE:
* -perform autonomous driving based on identified april tag
************************************************************************/
lib.driveRaiseArm(deltaY - 23, deltaX + 0.5, -deltaZ, 0.6); // drive so we're 30" off the wall (while arm is moving)
lib.driveWait(5,0,-30, 0.5);
sleep(100);
lib.dropSpec(); // Open grabber
// First Spec Dropped
lib.driveWait(0, 0, lib.getImuYaw() - deltaZ, 0.5);
lib.driveWaitDrive(deltaZ);
lib.checkArmRes();
lib.extendArm();
lib.grabSpec();
// Second Spec Grabbed
lib.driveWait(7.5, 0, 0, 0.2);
lib.holdSpec();
lib.driveRaiseArm(11, -29, 0, 0.7);
lib.driveWait(0, 0, -45, 0.4);
sleep(100);
lib.dropSpec();
// Second Spec Dropped
lib.driveWait(-6, 0, lib.getImuYaw()-deltaZ, 0.4);
lib.driveWait(0, 0, lib.getImuYaw()-deltaZ, 0.7);
lib.driveLowerArm(0, 26, 0, 0.6);
lib.checkArmRes();
lib.grabSpec();
// Third Spec Grabbed
lib.driveWait(7.5, 0, 0, 0.2);
lib.holdSpec();
lib.driveRaiseArm(-1, -29, 0, 0.7);
lib.driveWait(0, 0, -50, 0.6);
sleep(350);
lib.dropSpec();
// Third Spec Dropped
lib.driveWait(-5, 0, lib.getImuYaw()-deltaZ, 0.6);
lib.driveLowerArm(-3, 40, 0, 0.7);
lib.driveWait(-12, 0, 0, 0.6);
telemetry.addLine("Opmode COMPLETE");
telemetry.update();
while (opModeIsActive()) {
sleep(100); // this opMode doesn't use the boilerplate loop pattern, if this changes, be sure to remove the sleep
}
}
}
}