-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2024.java
More file actions
311 lines (223 loc) · 7.72 KB
/
2024.java
File metadata and controls
311 lines (223 loc) · 7.72 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.cameraserver.CameraServer;
import com.kauailabs.navx.frc.AHRS;
import edu.wpi.first.wpilibj.SPI;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the
* name of this class or
* the package after creating this project, you must also update the manifest
* file in the resource
* directory.
*/
public class Robot extends TimedRobot {
private final WPI_TalonSRX leftMotor = new WPI_TalonSRX(1);
private final WPI_TalonSRX leftRearMotor = new WPI_TalonSRX(2);
private final WPI_VictorSPX leftHookMotor = new WPI_VictorSPX(8);
private final WPI_VictorSPX rightHookMotor = new WPI_VictorSPX(9);
private final WPI_TalonSRX rightMotor = new WPI_TalonSRX(3);
private final WPI_TalonSRX rightRearMotor = new WPI_TalonSRX(4);
private final WPI_TalonSRX armMotor = new WPI_TalonSRX(7);
private final WPI_TalonSRX rightIntakeMotor = new WPI_TalonSRX(5);
private final WPI_TalonSRX leftIntakeMotor = new WPI_TalonSRX(6);
private final Servo rearDoor = new Servo(0);
// private final Servo pusher = new Servo(1);
private final DifferentialDrive m_robotDrive = new DifferentialDrive(leftMotor, rightMotor);
private final XboxController m_controller = new XboxController(0);
private final Timer m_timer = new Timer();
private final Encoder encoderLeft = new Encoder(0, 1);
private final Encoder encoderRight = new Encoder(2,3);
public boolean hookTop = false;
public boolean backDoor = false;
public boolean intake = false;
public boolean reverse = false;
public boolean hook = false;
public int num;
// private static final double whd = 6; //inches
//private static final double cpr = 7/4; //if am-2861a
// private static final double cpr = 360; //if am-3132
// private static final double cpr = 5; //if am-3314a
// private static final double cpr = 1024; //if am-3445
// private static final double cpr = 64; //if am-4027
public Robot() {
SendableRegistry.addChild(m_robotDrive, leftMotor);
SendableRegistry.addChild(m_robotDrive, rightMotor);
//armMotor.configSupplyCurrentLimit(null);
}
/**
* This function is run when the robot is first started up and should be used
* for any
* initialization code.
*/
@Override
public void robotInit() {
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
leftMotor.setInverted(true);
leftRearMotor.setInverted(true);
leftRearMotor.follow(leftMotor);
rightRearMotor.follow(rightMotor);
leftHookMotor.setInverted(true);
// encoderLeft.setReverseDirection(true);
// encoderLeft.setDistancePerPulse(Math.PI*whd/cpr);
// encoderRight.setDistancePerPulse(Math.PI*whd/cpr);
// encoderLeft.reset();
// encoderRight.reset();
CameraServer.startAutomaticCapture();
}
/** This function is run once each time the robot enters autonomous mode. */
@Override
public void autonomousInit() {
m_timer.restart();
rearDoor.set(0);
}
/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {
// Drive for 2 seconds
if (m_timer.get() < 2.0) {
// Drive forwards half speed, make sure to turn input squaring off
m_robotDrive.arcadeDrive(-0.5, 0.0, false);
} else {
m_robotDrive.stopMotor(); // stop robot
}
// double distance = encoderLeft.getDistance();
// if (distance<92){
// m_robotDrive.arcadeDrive(0.5, 0);
// }
}
/**
* This function is called once each time the robot enters teleoperated mode.
*/
@Override
public void teleopInit() {
rearDoor.set(0 );
// armMotor.set(1.0);
}
/** This function is called periodically during teleoperated mode. */
@Override
public void teleopPeriodic() {
// robot drive code
// REMOVE THE "/2" FROM BOTH LEFT AND RIGHT
m_robotDrive.arcadeDrive(m_controller.getLeftY() , -m_controller.getRightX()); //
// Climer code
// if(m_timer.get()>125){
// if (m_controller.getPOV() == 180 || hook){
// hook = true;
// leftHookMotor.set(-0.5);
// rightHookMotor.set(-0.5);
// }
// }
SmartDashboard.putBoolean("hookTop", hookTop);
// if (m_controller.getYButtonPressed()) {
// if (hookTop) {
// leftHookMotor.set(-1);
// rightHookMotor.set(-1);
// } else {
// leftHookMotor.set(1);
// rightHookMotor.set(1);
// }
// } else if (m_controller.getYButtonReleased()) {
// leftHookMotor.stopMotor();
// rightHookMotor.stopMotor();
// hookTop = !hookTop;
// }
// end of climber code
// Arm Code
if (m_controller.getXButtonPressed()) {
armMotor.set(-1.0);
num = 1;
}
else if (m_controller.getXButtonReleased()){
armMotor.stopMotor();
}
if (m_controller.getBButtonPressed()) {
armMotor.set(1.0);
num=0;
}
else if(m_controller.getBButtonReleased()){
armMotor.stopMotor();
}
if (num == 1){
if (m_controller.getLeftBumperPressed()){
armMotor.set(0.7);
}
}
else if (num == 0){
if(m_controller.getLeftBumperPressed()){
armMotor.set(-0.7);
}
}
// else {
// armMotor.stopMotor();
// }
// if (m_controller.getBButtonPressed()) {
// armMotor.set(-1.0);
// } else if (m_controller.getBButtonReleased()) {
// armMotor.stopMotor();
// }
// arm code end
// intake code
// if (m_controller.getRightTriggerAxis()>0.2 ) {
// if (intake){
// leftIntakeMotor.set(.75);
// rightIntakeMotor.set(.75);
// }
// else
// {
// leftIntakeMotor.stopMotor();
// rightIntakeMotor.stopMotor();
// }
// intake = !intake;
// }
leftIntakeMotor.set(m_controller.getLeftTriggerAxis()-m_controller.getRightTriggerAxis());
rightIntakeMotor.set((m_controller.getLeftTriggerAxis()-m_controller.getRightTriggerAxis()));
//shooter starts
// if (m_controller.getStartButtonPressed() ) {
// if (reverse){
// leftIntakeMotor.set(-.75);
// rightIntakeMotor.set(-.75);
// }
// else
// {
// leftIntakeMotor.stopMotor();
// rightIntakeMotor.stopMotor();
// }
// reverse = !reverse;
// }
// Back door code
if (m_controller.getRightBumperPressed()) {
if (backDoor){
rearDoor.set(1);
}
else{
rearDoor.set(0);
}
backDoor = !backDoor;
}
}
/** This function is called once each time the robot enters test mode. */
@Override
public void testInit() {
}
/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {
}
}