forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedTeamTellyOpWithAutoAim.java
More file actions
214 lines (162 loc) · 9.37 KB
/
Copy pathRedTeamTellyOpWithAutoAim.java
File metadata and controls
214 lines (162 loc) · 9.37 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
package org.firstinspires.ftc.teamcode;
import static org.firstinspires.ftc.teamcode.Util.RobotPosition.TeamColorRED;
import static org.firstinspires.ftc.teamcode.Util.RobotPosition.getRobotCoordinates;
import static org.firstinspires.ftc.teamcode.launcher.SemiAutoAiming.setAimAngle;
import static org.firstinspires.ftc.teamcode.launcher.SemiAutoAiming.siezingMotorTargetRotation;
import static org.firstinspires.ftc.teamcode.limelight.LimelightPosSetting.limelightposupdate;
import com.qualcomm.hardware.gobilda.GoBildaPinpointDriver;
import com.qualcomm.hardware.limelightvision.Limelight3A;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.teamcode.positioning.odometry.FieldOrientedDriving;
@TeleOp(name="redtellyautoaim")
public class RedTeamTellyOpWithAutoAim extends LinearOpMode {
ElapsedTime timer = new ElapsedTime();
ElapsedTime rapidtime = new ElapsedTime();
private Servo DrumServo;
private Servo FiringPinServo;
private GoBildaPinpointDriver odomhub;
private DcMotorEx Scooper;
private DcMotor BR;
private DcMotor BL;
private DcMotor FL;
private DcMotor FR;
private DcMotorEx LauncherFL;
protected boolean isred = true;
@Override
public void runOpMode() {
TeamColorRED = isred;
boolean fullunloadflag = false;
double lasttime = timer.milliseconds();
double[] drumBallColors = {0, 0, 0};
double targetdrumangle = 0;
double targetfiringpinangle = 1;
boolean firing = false;
double motortargetspeedradians = 0;
double currentleftmotorvelocity = 0;
double currentrightmotorvelocity = 0;
double firingpinnullposition = .98;
double rapidloop = 0;
Limelight3A limelight = hardwareMap.get(Limelight3A.class, "limelight");// INitilizes the limelights
limelight.setPollRateHz(100);
limelight.pipelineSwitch(0);
limelight.start();
odomhub = hardwareMap.get(GoBildaPinpointDriver.class, "odomhub");
DrumServo = hardwareMap.get(Servo.class, "DrumServo");
FiringPinServo = hardwareMap.get(Servo.class, "FiringPinServo");
BR = hardwareMap.get(DcMotor.class, "BR");
BL = hardwareMap.get(DcMotor.class, "BL");
FL = hardwareMap.get(DcMotor.class, "FL");
FR = hardwareMap.get(DcMotor.class, "FR");
FL.setDirection(DcMotor.Direction.REVERSE); //so I don't have to think about
BL.setDirection(DcMotor.Direction.REVERSE); //inverting later
FR.setDirection(DcMotor.Direction.FORWARD); //should generally do whenever motors
BR.setDirection(DcMotor.Direction.FORWARD);
LauncherFL = hardwareMap.get(DcMotorEx.class, "LauncherFL");
Scooper = hardwareMap.get(DcMotorEx.class, "Scooper");
limelight.setPollRateHz(100);
limelight.pipelineSwitch(0);
limelight.start();
//zeros the encoders and sets the run using encoder mode
//VariablePowerLauncherAbstract.initializeLauncher(LauncherFL,LauncherFR);
LauncherFL.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
LauncherFL.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
Scooper.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
Scooper.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
odomhub.initialize();
odomhub.resetPosAndIMU(); // resets encoders and IMU
telemetry.addData("Status", "Initialized");
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
// run until the end of the match (driver presses STOP)
while (opModeIsActive()) {
double leftstickinputy = gamepad1.left_stick_y; // Forward/backward negative because it's naturally inverted
double leftstickinputx = gamepad1.left_stick_x; // side to side
double targetturn = gamepad1.right_stick_x; // Turning
//slowermovement for the guner
double leftstickinputy2 = gamepad2.left_stick_y / 6;
double leftstickinputx2 = gamepad2.left_stick_x / 6;
double targetturn2 = gamepad2.right_stick_x / 4;
double[] currentrobotlocation = getRobotCoordinates();
double currentrelativeheading = odomhub.getHeading(AngleUnit.RADIANS);
//Calls FieldOrientedDriving function and sets motor power
double[] motorpowerarray = FieldOrientedDriving.fieldOrientedMath(leftstickinputy, -leftstickinputx, targetturn, currentrelativeheading);
double[] smallmotorpowerarray = FieldOrientedDriving.fieldOrientedMath(leftstickinputy2, -leftstickinputx2, targetturn2, currentrelativeheading);
double BRmotorpower = motorpowerarray[0] + smallmotorpowerarray[0];
double BLmotorpower = motorpowerarray[1] + smallmotorpowerarray[1];
double FRmotorpower = motorpowerarray[2] + smallmotorpowerarray[2];
double FLmotorpower = motorpowerarray[3] + smallmotorpowerarray[3];
//assigns power to each motor based on gamepad inputs
BR.setPower(BRmotorpower);
BL.setPower(BLmotorpower);
FR.setPower(FRmotorpower);
FL.setPower(FLmotorpower);
//limelight
limelightposupdate(limelight);
//auto rangeing commands
motortargetspeedradians = siezingMotorTargetRotation();
// sets the velocity of the motors
LauncherFL.setVelocity(motortargetspeedradians, AngleUnit.RADIANS);
if (gamepad2.a) {//firing bin controls
//auto fire code
setAimAngle();
} else {
targetfiringpinangle = firingpinnullposition;
targetdrumangle =
gamepad1.x ? .27 ://loading angles
gamepad1.y ? .6 :
gamepad1.b ? .92 :
targetdrumangle;
}
double[] firingpositions = {.1,.42,.76};
//MAG Dump code
//test time offsets
if (gamepad2.dpad_up) {//use timesrs use cancle when not held
rapidtime.reset();
fullunloadflag = true;
}
rapidloop = rapidtime.milliseconds();
if (fullunloadflag) {
// state machine this for next comp
if (rapidloop < 500) DrumServo.setPosition(firingpositions[0]);// 500 ms for drumb
if (rapidloop > 500 && rapidloop < 700) FiringPinServo.setPosition(.98 - .32);// 200ms for firing in
if (rapidloop > 700 && rapidloop < 900) FiringPinServo.setPosition(.98);
if (rapidloop > 900 && rapidloop < 1400) DrumServo.setPosition(firingpositions[0]);
if (rapidloop > 1400 && rapidloop < 1600) FiringPinServo.setPosition(.98 - .32);
if (rapidloop > 1600 && rapidloop < 1800) FiringPinServo.setPosition(.98);
if (rapidloop > 1800 && rapidloop < 2300) DrumServo.setPosition(firingpositions[0]);
if (rapidloop > 2500 && rapidloop < 2700) FiringPinServo.setPosition(.98 - .32);
if (rapidloop > 2700 && rapidloop < 2900) FiringPinServo.setPosition(.98);
}
DrumServo.setPosition(targetdrumangle);
FiringPinServo.setPosition(targetfiringpinangle);
if (gamepad1.dpad_down) odomhub.resetPosAndIMU(); // resets encoders and IMU
//wihle holding down the bumpers moves the intake
if (gamepad1.left_bumper) Scooper.setVelocity(999, AngleUnit.RADIANS);
else if (gamepad1.right_bumper) Scooper.setVelocity(-999, AngleUnit.RADIANS);
else Scooper.setVelocity(0, AngleUnit.RADIANS);
odomhub.update();
telemetry.addLine("All Speeds are in Jacks Per Second");
telemetry.addData("Motors' Target Rate of Rotation ", motortargetspeedradians);
telemetry.addData("Left Motor Actual Rate of Rotation", currentleftmotorvelocity);
/*//telemetry.addData("Right Motor Actual Rate of Rotation", currentrightmotorvelocity);
//telemetry.addData("rightmotorraw", rawrightmotorvelocity);
telemetry.addData("Left Motor difference in Rate of Rotation", motortargetspeedradians - currentleftmotorvelocity);
//telemetry.addData("Right Motor difference in Rate of Rotation", motortargetspeedradians+currentrightmotorvelocity);
//telemetry.addData("Left Motor Speed at Wheel Surface meters per second",currentleftmotorvelocity*launcherwheelradiusm);
//telemetry.addData("Right Motor Speed at Wheel Surface meters per second",currentrightmotorvelocity*launcherwheelradiusm);
telemetry.addData("drim target servoangle", targetdrumangle);
telemetry.addData("firingpin target servoangle", targetfiringpinangle);
telemetry.addData("rotation perceived", currentrelativeheading);
telemetry.addData("robotx", currentrobotlocation[0]);
telemetry.addData("roboty", currentrobotlocation[1]);*/
telemetry.update();
}
}
}