-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncoderDrive.java
252 lines (199 loc) · 7.66 KB
/
EncoderDrive.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Talon; //If your team uses victors, import them instead
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
/**
* This program sets up a basic robot, with two motors and encoders.
* It then drives for five feet during teleop mode.
*
* @author: Fredric Silberberg
*/
public class EncoderDrive extends SimpleRobot
{
//Drive Motors
Victor leftDriveMotorFront = new Victor(5);
Victor leftDriveMotorBack = new Victor(6);
Victor rightDriveMotorFront = new Victor(1);
Victor rightDriveMotorBack = new Victor(2);
//shooting motors Talon
Talon frontShooterMotor = new Talon(4);
Talon backShooterMotor = new Talon(3);
//climbing motor
Victor climbingMotor = new Victor(7);
//joysticks**incremented by 1
Joystick operatorStick = new Joystick(1);
Joystick leftStick = new Joystick(2);
//Solenoids
Solenoid shooterAngle1 = new Solenoid(3);
Solenoid shooterAngle2 = new Solenoid(4);
Solenoid shooterPistonA = new Solenoid(1);
Solenoid shooterPistonB = new Solenoid(2);
//Timers
Timer shooterResetTimer = new Timer();
Timer shooterPistonTimer = new Timer();
//Variables
// time in seconds
double shooterPistonOutDelay = 1.0;
double shooterPistonInDelay = 1.0;
boolean kickerButtonOn = false;
boolean cDrive = true;
int state = 0;
double shooterPistonDelay = 1.0;
//Compressor compressor = new Compressor( 14 ,1 );
//Relay spike1 = new Relay(1);
RobotDrive drive = new RobotDrive(leftDriveMotorFront, leftDriveMotorBack, rightDriveMotorFront, rightDriveMotorBack);
public EncoderDrive()
{
//Pistons
//invert drive motors
drive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true);
drive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, true);
drive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, true);
drive.setInvertedMotor(RobotDrive.MotorType.kRearRight, true);
}
/**
* This function is called once each time the robot enters operator control.
*/
//Button 1
public void shooter()
{
switch(state)
{
case 0:
//Not shooting, wait for button
if(operatorStick.getRawButton(1))
{
//just for insurance
//System.out.println();
shooterPistonTimer.reset();
state = 1;
}
break;
case 1:
//move piston out, start shooting, start timer
shooterPistonTimer.start();
shooterPistonA.set(false);
shooterPistonB.set(true);
//print 10 times so we can see it
for(int x = 0; x < 10; x++)
{
System.out.println("OUT");
}
state = 2;
break;
case 2:
//wait for timer
if(shooterPistonTimer.get() > shooterPistonOutDelay)
{
state = 3;
}
break;
case 3:
//move piston in, resets timers and shooter
//we stay in this state until we press the trigger again
shooterPistonA.set(true);
shooterPistonB.set(false);
shooterPistonTimer.reset();
// shooterPistonTimer.stop(); for insurance
shooterPistonTimer.stop();
shooterPistonTimer.start();
System.out.println("BACK");
state = 4;
break;
case 4:
//wait for pistons to retract
if(shooterPistonTimer.get() > shooterPistonInDelay)
{
state = 0;
}
break;
}
}
//Button 2
public void shooterWheels()
{
double rps = 0.55;
if(operatorStick.getRawAxis(5) >= 0.1)
{
System.out.println("adding");
rps = rps + 0.5;
}
else if(operatorStick.getRawAxis(5) <= -0.1)
{
System.out.println("subtracting");
rps = rps - 0.5;
}
else if(rps <= 0)
{
rps = 0.55;
}
if(operatorStick.getRawButton(3))
{
frontShooterMotor.set(rps);
backShooterMotor.set(rps);
}
else
{
frontShooterMotor.set(0);
backShooterMotor.set(0);
}
}
//Buttons 5 and 6
public void angler()
{
//if the operator presses button 4, the climber tilts up
if(operatorStick.getRawButton(5))
{
System.out.println("Up");
shooterAngle1.set(true);
shooterAngle2.set(false);
}
//else if the operator presses button 5, the climber tilts down
else if(operatorStick.getRawButton(6))
{
System.out.println("Down");
shooterAngle1.set(false);
shooterAngle2.set(true);
}
}
public void operatorControl()
{
//sets safety off
drive.setSafetyEnabled(false);
//sets the pistons to in at the start
shooterPistonA.set(true);
shooterPistonB.set(false);
while(isOperatorControl() && isEnabled())
{
//System.out.println(operatorStick.getRawAxis(1)+ " " + operatorStick.getRawAxis(0) + " " + operatorStick.getRawAxis(3));
drive.arcadeDrive((0.75 * operatorStick.getY()), (0.75 * operatorStick.getX()), true);
/*//Compressor
if(operatorStick.getRawButton(6))
{
compressor.start();
}
else if(operatorStick.getRawButton(7))
{
compressor.stop();
}*/
shooter();
shooterWheels();
angler();
Timer.delay(0.005);
}
}
}