-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDLC
255 lines (208 loc) · 10.2 KB
/
DDLC
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
package org.firstinspires.ftc.teamcode.Auto;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
import org.firstinspires.ftc.robotcore.external.Telemetry;
import static org.firstinspires.ftc.robotcore.external.BlocksOpModeCompanion.hardwareMap;
public class DDLC {
DcMotor frontLeft;
DcMotor backLeft;
DcMotor frontRight;
DcMotor backRight;
Servo leftClaw;
Servo rightClaw;
DcMotor Arm;
DcMotor Lift;
DcMotor Wrist;;
public Telemetry telem;
boolean clawClose;
private final ElapsedTime runtime = new ElapsedTime();
static final double Counts_PER_MOTOR_REV = 1440;
static final double DRIVE_GEAR_REDUCTION = 1.0;
static final double WHEEL_DIAMETER_INCHES = 4.0;
static final double COUNTS_PER_INCH = (Counts_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) / (WHEEL_DIAMETER_INCHES * 3.1415);
static final double DRIVE_SPEED = 0.4;
static final double TURN_SPEED = 0.3;
public void init(HardwareMap hwmap, Telemetry telem) {
frontLeft = hardwareMap.dcMotor.get("fL");
backLeft = hardwareMap.dcMotor.get("bL");
frontRight = hardwareMap.dcMotor.get("fR");
backRight = hardwareMap.dcMotor.get("bR");
leftClaw = hardwareMap.servo.get("LS");
rightClaw = hardwareMap.servo.get("RS");
Arm = hardwareMap.dcMotor.get("Arm");
Wrist = hardwareMap.dcMotor.get("Wrist");
Lift = hardwareMap.dcMotor.get("Lift");
frontLeft.setDirection(DcMotorSimple.Direction.REVERSE);
backLeft.setDirection(DcMotorSimple.Direction.REVERSE);
this.telem = telem;
}
public void encoderDrive(double speed, double leftInches, double rightInches, double timeouts) {
int newLeftFrontTarget;
int newRightFrontTarget;
int newLeftBackTarget;
int newRightBackTarget;
newLeftFrontTarget =frontLeft.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRightFrontTarget = frontRight.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
newLeftBackTarget = backLeft.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRightBackTarget = backRight.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
frontLeft.setTargetPosition(newLeftFrontTarget);
frontRight.setTargetPosition(newRightFrontTarget);
backLeft.setTargetPosition(newLeftBackTarget);
backRight.setTargetPosition(newRightBackTarget);
frontLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
frontRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
backLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
backRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
runtime.reset();
frontLeft.setPower(speed);
frontRight.setPower(speed);
backLeft.setPower(speed);
backRight.setPower(speed);
while (runtime.seconds() < timeouts && (frontLeft.isBusy() && frontRight.isBusy() && backLeft.isBusy() && backRight.isBusy())) {
//telemetry.addData("Pat1", "Running to %7d :%7d", newLeftFrontTarget, newRightFrontTarget);
//telemetry.addData("Path2", "Running to %7d :%7d", frontLeft.getCurrentPosition(), frontRight.getCurrentPosition());
telem.addData("fL pos", frontLeft.getCurrentPosition());
telem.addData("fR pos", frontRight.getCurrentPosition());
telem.addData("bL pos", backLeft.getCurrentPosition());
telem.addData("bR pos", backRight.getCurrentPosition());
telem.addData("fL goal", newLeftFrontTarget);
telem.addData("fR goal", newRightFrontTarget);
telem.addData("bL goal", newLeftBackTarget);
telem.addData("bR goal", newRightBackTarget);
telem.update();
}
frontLeft.setPower(0);
frontRight.setPower(0);
backLeft.setPower(0);
backRight.setPower(0);
frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
backLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
backRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
public void encoderLeftDrive(double speed, double rightInches, double timeouts) {
//int newLeftFrontTarget;
int newRightFrontTarget;
//int newLeftBackTarget;
int newRightBackTarget;
//newLeftFrontTarget =frontLeft.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRightFrontTarget = frontRight.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
// newLeftBackTarget = backLeft.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRightBackTarget = backRight.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
// frontLeft.setTargetPosition(newLeftFrontTarget);
frontRight.setTargetPosition(newRightFrontTarget);
//backLeft.setTargetPosition(newLeftBackTarget);
backRight.setTargetPosition(newRightBackTarget);
// frontLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
frontRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
// backLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
backRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
runtime.reset();
// frontLeft.setPower(speed);
frontRight.setPower(speed);
//backLeft.setPower(speed);
backRight.setPower(speed);
while (runtime.seconds() < timeouts && (frontRight.isBusy() && backRight.isBusy())) {
//telemetry.addData("Pat1", "Running to %7d :%7d", newLeftFrontTarget, newRightFrontTarget);
//telemetry.addData("Path2", "Running to %7d :%7d", frontLeft.getCurrentPosition(), frontRight.getCurrentPosition());
// telem.addData("fL pos", frontLeft.getCurrentPosition());
telem.addData("fR pos", frontRight.getCurrentPosition());
// telem.addData("bL pos", backLeft.getCurrentPosition());
telem.addData("bR pos", backRight.getCurrentPosition());
// telem.addData("fL goal", newLeftFrontTarget);
telem.addData("fR goal", newRightFrontTarget);
// telem.addData("bL goal", newLeftBackTarget);
telem.addData("bR goal", newRightBackTarget);
telem.update();
}
// frontLeft.setPower(0);
frontRight.setPower(0);
// backLeft.setPower(0);
backRight.setPower(0);
// frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// backLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
backRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
public void encoderRightDrive(double speed, double leftInches, double timeouts) {
int newLeftFrontTarget;
// int newRightFrontTarget;
int newLeftBackTarget;
// int newRightBackTarget;
newLeftFrontTarget =frontLeft.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
// newRightFrontTarget = frontRight.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
newLeftBackTarget = backLeft.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
// newRightBackTarget = backRight.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
frontLeft.setTargetPosition(newLeftFrontTarget);
//frontRight.setTargetPosition(newRightFrontTarget);
backLeft.setTargetPosition(newLeftBackTarget);
// backRight.setTargetPosition(newRightBackTarget);
frontLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
// frontRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
backLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
// backRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
runtime.reset();
frontLeft.setPower(speed);
// frontRight.setPower(speed);
backLeft.setPower(speed);
// backRight.setPower(speed);
while (runtime.seconds() < timeouts && (frontLeft.isBusy() && backLeft.isBusy())) {
//telemetry.addData("Pat1", "Running to %7d :%7d", newLeftFrontTarget, newRightFrontTarget);
//telemetry.addData("Path2", "Running to %7d :%7d", frontLeft.getCurrentPosition(), frontRight.getCurrentPosition());
telem.addData("fL pos", frontLeft.getCurrentPosition());
// telem.addData("fR pos", frontRight.getCurrentPosition());
telem.addData("bL pos", backLeft.getCurrentPosition());
//telem.addData("bR pos", backRight.getCurrentPosition());
telem.addData("fL goal", newLeftFrontTarget);
// telem.addData("fR goal", newRightFrontTarget);
telem.addData("bL goal", newLeftBackTarget);
// telem.addData("bR goal", newRightBackTarget);
telem.update();
}
frontLeft.setPower(0);
// frontRight.setPower(0);
backLeft.setPower(0);
// backRight.setPower(0);
frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
backLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// backRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
public void StrafeLeft() {
frontLeft.setPower(-.4);
backLeft.setPower(.4);
frontRight.setPower(.4);
backRight.setPower(-.4);
}
public void StrafeRight() {
frontLeft.setPower(.4);
backLeft.setPower(-.4);
frontRight.setPower(-.4);
backRight.setPower(.4);
}
public void hold(){
leftClaw.setPosition(0);
rightClaw.setPosition(1.0);
clawClose = true;
}
public void letGo(){
leftClaw.setPosition(1);
rightClaw.setPosition(0.6);
clawClose = false;
}
public void letGoAll(){
leftClaw.setPosition(1);
rightClaw.setPosition(0);
clawClose = false;
}
public void stayConnected(){
frontLeft.setPower(.0);
backLeft.setPower(.0);
frontRight.setPower(.01);
backRight.setPower(.01);
}
}