-
Notifications
You must be signed in to change notification settings - Fork 1
/
green_mechanum_tele.java
232 lines (194 loc) · 6.39 KB
/
green_mechanum_tele.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
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.Range;
// they don't move too far)
/**
* Created by Noelle on 11/19/2015.
*/
//register the code so that you can see it in the app
@TeleOp(name = "Green TeleOp Mechanum", group = "Green")
public class green_mechanum_tele extends OpMode { //make sure that you remember to extend OpMode!
//<editor-fold desc="motors used">
public DcMotor LF;
public DcMotor RF;
public DcMotor LB;
public DcMotor RB;
DcMotor shooter;
DcMotor collect;
// DcMotor shooter2;
//</editor-fold>
//<editor-fold desc="variables used">
final static double STOP = 0;
public double LeftF = 0;
public double RightF = 0;
public double LeftB = 0;
public double RightB = 0;
public double speed = .5;
public double colu = 0;
public double shoot1 = 0;
//public double shoot2 = 0;
public double collectingspeed = .5;
private double speedcol = -2.0;
private double speedshoot = 0.6;
private double col = 0;
private double shooting = 0;
double x = 0;
double y = 0;
//</editor-fold>
public void init() {
//<editor-fold desc="hardware mapping all motors">
telemetry.addLine("starting init");
RF = hardwareMap.dcMotor.get("rf");
telemetry.addLine("rf done");
LF = hardwareMap.dcMotor.get("lf");
telemetry.addLine("lf done");
LB = hardwareMap.dcMotor.get("lb");
telemetry.addLine("lb done");
RB = hardwareMap.dcMotor.get("rb");
telemetry.addLine("rb done");
shooter = hardwareMap.dcMotor.get("sho");
collect = hardwareMap.dcMotor.get("co up");
telemetry.addData("Get started!", 6);
telemetry.addLine("motors initialized");
//</editor-fold>
}
public void loop() {
telemetry.addLine("starting loop");
//<editor-fold desc="'x' is x axis, 'y' is y axis, both on left joystick of gamepad 1">
x = gamepad1.left_stick_x;
y = gamepad1.left_stick_y;
//</editor-fold>
//<editor-fold desc="clip joystick range to -1 and 1">
x = Range.clip(x, -1, 1);
y = Range.clip(y, -1, 1);
//</editor-fold>
//<editor-fold desc="8 directions. currently in testing">
//forward
if ((-0.3 < x && x < 0.3) && (y >= 0.3)) {
//move forward
LeftF = speed;
LeftB = -speed;
RightF = speed;
RightB = speed;
}
//backward
if ((-0.3 < x && x < 0.3) && (y <= -0.3)) {
//move backward
LeftF = -speed;
LeftB = speed;
RightF = -speed;
RightB = -speed;
}
//strafe left
if ((x <= -0.3) && (-0.3 < y && y < 0.3)) {
//move left
LeftF = -speed;
LeftB = -speed;
RightF = speed;
RightB = -speed;
}
//strafe right
if ((x >= 0.3) && (-0.3 < y && y < 0.3)) {
//move right
LeftF = speed;
LeftB = speed;
RightF = -speed;
RightB = speed;
}
//Joanna and Gemma have fixed the first 4
//brakes
if ((-0.3 < x && x < 0.3) && (-0.3 < y && y < 0.3)) {
//stop
LeftF = STOP;
LeftB = STOP;
RightF = STOP;
RightB = STOP;
}
//NE
if (x > 0.3 && y > 0) {
LeftF = -speed;
LeftB = STOP;
RightF = STOP;
RightB = -speed;
}
//SE
if (x > 0.3 && y < 0) {
LeftF = STOP;
LeftB = -speed;
RightF = speed;
RightB = STOP;
}
//SW
if (x < -0.3 && y < 0) {
LeftF = speed;
LeftB = STOP;
RightF = -STOP; //why is this not at stop...? I added a sign, even though it shouldn't do anything...
RightB = speed;
}
//NW
if (x < -0.3 && y > 0) {
LeftF = STOP;
LeftB = speed;
RightF = -speed;
RightB = STOP;
}
//8 directions------------------------------------------------------------------------------
//</editor-fold>
//<editor-fold desc="bumpers. THESE WORK, DO NOT CHANGE">
//set bumpers to turn the robot. THESE WORK, DO NOT CHANGE----------------------------------
if (gamepad1.left_bumper) {//turn left
LeftF = speed;
RightF = -speed;
LeftB = -speed;
RightB = -speed;
}
if (gamepad1.right_bumper) {//turn right
LeftF = -speed;
RightF = speed;
LeftB = speed;
RightB = speed;
}
//end bumpers-------------------------------------------------------------------------------
//</editor-fold>
//<editor-fold desc="shooter and collector">
//code for collecting (press button x):
if (gamepad2.x) {
col = speedcol;
telemetry.addData("collecting", col);
collect.setPower(col);
} else {
col = 0;
collect.setPower(col);
}
//code for shooter(press botton y)
if (gamepad2.y) {
shooting = speedshoot;
telemetry.addData("Shooter", shooting);
shooter.setPower(shooting);
} else {
shooting = 0;
shooter.setPower(shooting);
}
//</editor-fold>
//<editor-fold desc="set the motors to the appropriate and corresponding power">
LF.setPower(LeftF);
RF.setPower(RightF);
LB.setPower(LeftB);
RB.setPower(RightB);
//</editor-fold>
//<editor-fold desc="debugging using telemetry">
telemetry.addData("left front", LeftF);
telemetry.addData("right front", RightF);
telemetry.addData("left back", LeftB);
telemetry.addData("right back", RightB);
telemetry.addData("collect", colu);
telemetry.addData("x value", x);
telemetry.addData("y value", y);
telemetry.addData("collect", colu);
telemetry.addData("shooter1", shoot1);
//telemetry.addData("shooter2", shoot2);
//</editor-fold>
}
}