-
Notifications
You must be signed in to change notification settings - Fork 2
/
Robot.java
130 lines (105 loc) · 3.34 KB
/
Robot.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
package org.usfirst.frc.team6489.robot;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Spark;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* 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 IterativeRobot {
// Used in teleOp
public Boolean toggle = false;
public Boolean previousToggleButton = false;
public Boolean currentToggleButton = false;
public Boolean open = false;
public Boolean close = false;
/** Negative is forwards! **/
Spark rightWheels;
/** Positive is forwards! **/
Spark leftWheels;
/** ? is up! **/
Spark forklift;
/** ? is out! **/
Spark cubeMotor;
public DoubleSolenoid arm = new DoubleSolenoid(5, 4);
public Compressor comp = new Compressor();
public static OI oi;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
**/
@Override
public void robotInit() {
CameraServer.getInstance().startAutomaticCapture();
comp.start();
// Wheels
rightWheels = new Spark(4);
leftWheels = new Spark(1);
// Forklift (check port)
forklift = new Spark(2);
// Cube input/output (check port)
cubeMotor = new Spark(0);
oi = new OI();
}
@Override
public void autonomousInit() {
comp.start(); // Should start compressor in auto too
}
/**
* This function is called periodically during autonomous.
**/
@Override
public void autonomousPeriodic() {
// until loop?
rightWheels.set(-0.24);
leftWheels.set(0.24);
}
/**
* This function is called periodically during operator control.
**/
@Override
public void teleopPeriodic() {
// Driving (tank style again)
previousToggleButton = currentToggleButton;
currentToggleButton = OI.xbox.getRawButton(3); // X
if (currentToggleButton && !previousToggleButton) {
toggle = toggle ? false : true;
}
// Opens or closes one pneumatic side of our robot's arms
open = OI.xbox.getRawButton(4); // Y
close = OI.xbox.getRawButton(2); // B
if (open) {
arm.set(DoubleSolenoid.Value.kForward);
} else if (close) {
arm.set(DoubleSolenoid.Value.kReverse);
} else {
arm.set(DoubleSolenoid.Value.kOff);
}
// Have to be reversed because something is sketchy
rightWheels.set((double)(toggle ? OI.xbox.getY2() / 2 : OI.xbox.getY2()));
leftWheels.set((double)(toggle ? -OI.xbox.getY1() / 2 : -OI.xbox.getY1()));
// Cube intake/output (uses left bumper for out and right bumper for in) - maybe idk
if (OI.xbox.getRawButton(5)) { // Sucks in
cubeMotor.set(0.5);
} else if (OI.xbox.getRawButton(6)) { // Goes out
cubeMotor.set(-0.5);
} else {
cubeMotor.set(0);
}
double forkliftUp = OI.xbox.getLeftTrigger();
double forkliftDown = OI.xbox.getRightTrigger();
// Forklift (uses left trigger for in and right trigger for out)
if (forkliftUp == 0 && forkliftDown == 0) {
forklift.set(0);
} else if (forkliftUp != 0) { // Goes up!
forklift.set(0.75);
} else if (forkliftDown != 0) { // Goes down!
forklift.set(-0.75);
}
}
}