-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoLexington.java
More file actions
215 lines (183 loc) · 7.48 KB
/
AutoLexington.java
File metadata and controls
215 lines (183 loc) · 7.48 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
214
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
@Autonomous(name = "Autonomous 1", group = "Competition2019-2020")
public class AutoLexington extends OpMode {
// Set the team
Team currentTeam = Team.NONE; // NONE, RED, or BLUE
int phase_counter = 0; // This counter determines which movement the robot is currently performing
private ElapsedTime runtime = new ElapsedTime();
//variables --> these names are used within the code...
DcMotor motorFL = null;
DcMotor motorBL = null;
DcMotor motorFR = null;
DcMotor motorBR = null;
DcMotor motorLift = null;
Servo servoHand;
@Override
public void init(){
//what happens on INITIALIZE
//drawing the motors from the hardware map on the robot control station
telemetry.addData("OpMode Status","Initializing hardware");
motorFL = hardwareMap.get(DcMotor.class, "motFL");
motorBL = hardwareMap.get(DcMotor.class, "motBL");
motorFR = hardwareMap.get(DcMotor.class, "motFR");
motorBR = hardwareMap.get(DcMotor.class, "motBR");
motorLift = hardwareMap.get(DcMotor.class, "motLift");
servoHand = hardwareMap.get(Servo.class, "serHand");
//setting the initial direction of the motors
// --> this makes the position the motors are
// in when the code is initialized to be
// considered "forward".
telemetry.addData("OpMode Status","Initializing motor directions");
motorFL.setDirection(DcMotor.Direction.FORWARD);
motorBL.setDirection(DcMotor.Direction.FORWARD);
motorFR.setDirection(DcMotor.Direction.FORWARD);
motorBR.setDirection(DcMotor.Direction.FORWARD);
motorLift.setDirection(DcMotor.Direction.FORWARD);
telemetry.addData("OpMode Status","Initializing servo direction");
servoHand.setDirection(Servo.Direction.FORWARD);
}
@Override
public void start(){
//what happens on START
runtime.restart(); // Start the runtime elapsed timer
phase_counter = 0;
currentTeam = Team.NONE; // you don't really need to change this value
}
@Override
public void loop(){
// ONLY PICK ONE
// foundation_function();
// parking_function();
}
// Fix these if there are driving issues.
// Don't forget that you must tell the motors to stop eventually
public void drive_cardinal(double x, double y){
//DRIVE CODE --> north/south/east/west movement
y = -y; // the analog stick is actually -1.0 for forward, and 1.0 for backward
motorFL.setPower(-y-x);
motorBL.setPower(-y+x);
motorFR.setPower(-y+x);
motorBR.setPower(-y-x);
}
public void drive_rotater(double x, double y){
//DRIVE CODE --> north/south/east/west movement
motorFL.setPower(-y+x);
motorBL.setPower(-y+x);
motorFR.setPower(-y-x);
motorBR.setPower(-y-x);
}
public double distanceToFoundation(){
return 999;
}
public void foundation_function(){
switch(phase_counter){
case 0:
runtime.restart();
phase_counter+=1;
break;
case 1:
// Lift the arm
double power = 0.8;
float time = 1.0;
motorLift.setPower(power); // The action to lift arm
telemetry.addData("Status", "Phase %d: %2.5f S Elapsed", phase_counter, runtime.seconds());
if (runtime.seconds() >= time){
motorLift.setPower(0); // STOP ARM
phase_counter += 1;
runtime.restart();
}
break;
case 2:
// Drive forward to the foundation
double power = 1;
float time = 1.0;
double dist = 10; // desired distance as next to the foundation
drive_cardinal(power,0);
telemetry.addData("Status", "Phase %d: %2.5f S Elapsed", phase_counter, runtime.seconds());
if (runtime.seconds() >= time || distanceToFoundation()<=dist ){
drive_cardinal(0,0); //STOP THE ROBOT
phase_counter += 1;
runtime.restart();
}
break;
case 3:
// Drop the arm
double power = -0.8;
float time = 1.0;
motorLift.setPower(power); // The action to drop arm
telemetry.addData("Status", "Phase %d: %2.5f S Elapsed", phase_counter, runtime.seconds());
if (runtime.seconds() >= time){
motorLift.setPower(0); // STOP ARM
phase_counter += 1;
runtime.restart();
}
break;
case 4:
// Drive backward with the foundation
double power = -0.8;
float time = 1.0;
drive_cardinal(power,0);
telemetry.addData("Status", "Phase %d: %2.5f S Elapsed", phase_counter, runtime.seconds());
if (runtime.seconds() >= time){
drive_cardinal(0,0); //STOP THE ROBOT
phase_counter += 1;
runtime.restart();
}
break;
default:
// STOP EVERYTHING
drive_cardinal(0,0);
motorLift.setPower(0);
telemetry.addData("Status", "Trip completed");
}
telemetry.update();
}
public void parking_function(){
switch(phase_counter){
case 0:
runtime.restart();
phase_counter+=1;
break;
case 1:
// Drive sideways to the left or right
double power = 1;
float time = 1.0;
switch(currentTeam){
case RED: drive_cardinal(0,power); break; // RIGHT
case BLUE: drive_cardinal(0,-power); break; // LEFT
case NONE: phase_counter+=1; runtime.restart(); break; // Quit this for the next part
}
telemetry.addData("Status", "Phase %d: %2.5f S Elapsed", phase_counter, runtime.seconds());
if (runtime.seconds() >= time){
phase_counter += 1;
runtime.restart();
}
break;
case 2:
// Drive forwards
double power = 1;
float time = 1.0;
drive_cardinal(power,0);
telemetry.addData("Status", "Phase %d: %2.5f S Elapsed", phase_counter, runtime.seconds());
if (runtime.seconds() >= time){
phase_counter += 1;
runtime.restart();
}
break;
default:
// STOP EVERYTHING
drive_cardinal(0,0);
telemetry.addData("Status", "Trip completed");
}
telemetry.update();
}
public enum Team {
RED, BLUE, NONE
}
}