-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRobot.java
More file actions
167 lines (145 loc) · 5 KB
/
Robot.java
File metadata and controls
167 lines (145 loc) · 5 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
package com.github.mittyrobotics;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.controller.PIDController;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import com.github.mittyrobotics.util.Compressor;
//Java automatically runs this class, and calls the various functions.
/*
* YOUR WIFI MUST BE CONNECTED TO ROMI FOR THIS TO WORK
*/
public class Robot extends TimedRobot {
Spark SparkLeft, SparkRight;
DigitalInput digitalInput1;
DigitalInput input2;
DigitalInput input3;
DigitalInput input4;
XboxController controller;
RomiGyro gyro;
boolean clicked;
boolean released;
//Runs when the robot is first started up and should be used for any initialization code
/*
* INITIALIZE CLASSES HERE
*/
TrapezoidProfile.State start; //start variable from type trapezoidprofile.state
TrapezoidProfile.State end; //end var
TrapezoidProfile.Constraints constraints; //constraints var from .constraints
TrapezoidProfile profile; //profile
int counter;
double kp, ki, kd;
PIDController control = new PIDController(kp, ki, kd);
Encoder encoder;
DoubleSolenoid s;
boolean deadZone;
DoubleSolenoid p;
@Override
public void robotInit() {
SparkLeft = new Spark(Constants.LEFT_MOTOR_ID;
SparkRight = new Spark(Constants.RIGHT_MOTOR_ID);
SparkLeft.setInverted(true);
// digitalInput1 = new DigitalInput(0);
// input2 = new DigitalInput(1);
// input3 = new DigitalInput(2);
// input4 = new DigitalInput(3);
controller = new XboxController(0);
// gyro = new RomiGyro();
// clicked = controller.getAButtonPressed();
// released = controller.getAButtonReleased();
// start = new TrapezoidProfile.State(0, 0);
// end = new TrapezoidProfile.State(1.0, 0);
constraints = new TrapezoidProfile.Constraints(0.2, 0.2);
// profile = new TrapezoidProfile(constraints, end, start);
// encoder = new Encoder(Constants.ENCODER_IDS[0], Constants.ENCODER_IDS[1]);
// s = new DoubleSolenoid(1,2);
deadZone = true;
DriveTrain.getInstance().initHardware();
}
//Runs periodically during teleoperated mode
/*
* WRITE YOUR DRIVE CODE HERE
*/
@Override
public void teleopPeriodic() {
if (clicked){
SparkLeft.set(OI.getInstance().getXboxController().getY(GenericHID.Hand.kLeft);
SparkRight.set(OI.getInstance().getXboxController().getX(GenericHID.Hand.kLeft);
}
TrapezoidProfile.State profileOutput = profile.calculate(0.02*counter);
control.setSetpoint(profileOutput.position);
double output = control.calculate(encoder.getDistance());
SparkLeft.set(output);
SparkRight.set(output);
counter++;
if(OI.getInstance().getXboxController().getAButton()){
s.set(DoubleSolenoid.Value.kForward);
}
else if(OI.getInstance().getXboxController().getBButton()){
s.set(DoubleSolenoid.Value.kReverse);
}
else if(OI.getInstance().getXboxController().getXButton()){
p.set(DoubleSolenoid.Value.kForward);
}
else if(OI.getInstance().getXboxController().getYButton()){
p.set(DoubleSolenoid.Value.kReverse);
}
if(clicked==false){
clicked=false;
}
if(digitalInput1.get()) {
SparkLeft.set(0);
SparkRight.set(1);
}
else if(input2.get()){
SparkLeft.set(1);
SparkRight.set(0);
}
else if(input3.get()){
SparkLeft.set(1);
SparkRight.set(1);
}
else if(input4.get()) {
SparkLeft.set(-1);
SparkRight.set(-1);
}
if(controller.getAButton()){
while(gyro.getAngleZ()<=45){
SparkLeft.set(-0.5);
SparkRight.set(0.5);
}
}
if(clicked){
SparkLeft.set(controller.getY(GenericHID.Hand.kLeft));
SparkRight.set(controller.getY(GenericHID.Hand.kRight));
}
if(controller.getAButton() && gyro.getAngleZ() <= 45){
SparkLeft.set(-0.5);
SparkRight.set(0.5);
}
*/
}
//Runs when antonomous mode (robot runs on its own) first activated via the desktop application
@Override
public void autonomousInit() {
}
//Runs when teleoperated mode (robot controlled by driver) is first activated
@Override
public void teleopInit() {
}
//Runs when test mode is activated
@Override
public void testInit() {
}
//Runs whenever the robot is on, periodically: should be used for command schedulers
@Override
public void robotPeriodic() {
}
//Runs periodically during auto6nomous mode
@Override
public void autonomousPeriodic() {
}
//Runs periodically during test mode
@Override
public void testPeriodic() {
}
}