-
Notifications
You must be signed in to change notification settings - Fork 0
/
FTCTeleOP.java
166 lines (142 loc) · 4.64 KB
/
FTCTeleOP.java
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
@TeleOp
public class FTCTeleOP extends OpMode {
DcMotor FLM, FRM, BLM, BRM, clawM;
Servo clawS;
double xaxLisL, yaxisL;
double TOLERANCE = 0.3;
BNO055IMU imu;
double LF = 0;
double RF = 0;
double LB = 0;
double RB = 0;
double vertical;
ElapsedTime SCooldown = new ElapsedTime();
double COOLDOWN = 0.3;
@Override
public void init() {
FLM = hardwareMap.dcMotor.get("FLM");
FRM = hardwareMap.dcMotor.get("FRM");
BLM = hardwareMap.dcMotor.get("BLM");
BRM = hardwareMap.dcMotor.get("BRM");
clawM = hardwareMap.dcMotor.get("clawM");
clawS = hardwareMap.servo.get("clawS");
BRM.setDirection(DcMotor.Direction.REVERSE);
FRM.setDirection(DcMotor.Direction.REVERSE);
imu = (BNO055IMU)hardwareMap.get("imu");
Orientation angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
double yaw = -angles.firstAngle;
double rol = -angles.secondAngle;
double pitch = -angles.thirdAngle;
FLM.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
FRM.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
BLM.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
SCooldown.reset();
update();
}
@Override
public void loop() {
vertical = -gamepad2.left_stick_y;
motorDrive();
clawM.setPower(vertical/2);
// activate claw
if(gamepad2.a && SCooldown.seconds() >= COOLDOWN){
SCooldown.reset();
clawS.setPosition(0.8);
} else if(gamepad2.b && SCooldown.seconds() >= COOLDOWN){
SCooldown.reset();
clawS.setPosition(0);
}
update();
}
//telemetry
public void update(){
telemetry.addData("Directions: ", "b to grab, a to release");
telemetry.addData("Arm Encoder: ", clawM.getCurrentPosition());
telemetry.addData("FLM Power: ", FLM.getPower());
telemetry.addData("FRM Power: ", FRM.getPower());
telemetry.addData("BLM Power: ", BLM.getPower());
telemetry.addData("BRM Power: ", BRM.getPower());
telemetry.update();
}
// speed boost, if bumpers = 0 set speed 1/2
public void motorDrive() {
DirAxes();
if(gamepad1.left_bumper || gamepad1.right_bumper){
FRM.setPower(RF);
FLM.setPower(LF);
BRM.setPower(RB);
BLM.setPower(LB);
} else{
FRM.setPower(RF/2);
FLM.setPower(LF/2);
BRM.setPower(RB/2);
BLM.setPower(LB/2);
}
}
// direction control left
public void DirAxes(){
double yaxL = -gamepad1.left_stick_y;
double xaxL = gamepad1.left_stick_x;
LF = 0;
RF = 0;
LB = 0;
RB = 0;
LF += yaxL;
RF += yaxL;
LB += yaxL;
RB += yaxL;
// strafe left/right
LF += xaxL;
RF -= xaxL;
LB -= xaxL;
RB += xaxL;
// turning left or right
double yaxR = -gamepad1.right_stick_y;
double xaxR = gamepad1.right_stick_x;
LF += xaxR;
RF -= xaxR;
LB += xaxR;
RB -= xaxR;
// Caps the speed to -1 and 1
if(LF > 1 || LF < -1){
if(LF > 1){
LF = 1;
}else{
LF = -1;
}
}
if(RF > 1 || RF < -1){
if(RF > 1){
RF = 1;
}else{
RF = -1;
}
}
if(LB > 1 || LF < -1){
if(LB > 1){
LB = 1;
}else{
LB = -1;
}
}
if(RB > 1 || RB < -1){
if(RB > 1){
RB = 1;
}else{
RB = -1;
}
}
}
}