This repository has been archived by the owner on Mar 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTshirtCannon.java
90 lines (76 loc) · 2.32 KB
/
TshirtCannon.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
package org.usfirst.frc.team6184.robot;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
//Simple drive program for robot
//Allows rotation and basic backward forward movement
public class TshirtCannon extends SampleRobot {
Joystick stick = new Joystick(0); // set to ID 1 in DriverStation
Talon mFL = new Talon(0), mFR = new Talon(3), mBL = new Talon(2), mBR = new Talon(1); //All the motor controllers
Solenoid tshirtSolenoid = new Solenoid(0); //Assumes 0 is the ID of the Pnemuatic Controller and that we are using the 1st output
public TshirtCannon() {
}
@Override
public void operatorControl() {
while (isOperatorControl() && isEnabled()) {
solenoidController(); //Run solenoid function
double m = .7, t = .5; //Motor speed mod and turn speed mod
if(stick.getRawButton(2)) m = 1; //Boost power
else m = .7;
double x = stick.getX()*m; //How much "X" to apply to motors
double y = -stick.getY()*m; //How much "y"
if (y > .1 || y <= -.1) { //If joystick is not at default state
if (x > .005) {
m = 1 - x * t;
mFR.setSpeed(-y * m);
mBR.setSpeed(-y * m);
mFL.setSpeed(y);
mBL.setSpeed(y);
} else if (x < -.005) {
x = -x;
m = 1 - x * t;
mFR.setSpeed(-y);
mBR.setSpeed(-y);
mFL.setSpeed(y * m);
mBL.setSpeed(y * m);
} else if (x < .005 && x > -.005) {
mFR.setSpeed(-y);
mBR.setSpeed(-y);
mFL.setSpeed(y);
mBL.setSpeed(y);
} else {
mFR.setSpeed(0);
mBR.setSpeed(0);
mFL.setSpeed(0);
mBL.setSpeed(0);
}
}
else {
double z = stick.getZ();
mFR.setSpeed(z);
mBR.setSpeed(z);
mFL.setSpeed(z);
mBL.setSpeed(z);
}
}
}
@Override
public void autonomous() { //This runs the moment autonmous is switched into
mFR.setSpeed(-.1);
mBR.setSpeed(-.1);
mFL.setSpeed(.1);
mBL.setSpeed(.1);
Timer.delay(0.1); //Wait 0.5 seconds
mFR.setSpeed(0);
mBR.setSpeed(0);
mFL.setSpeed(0);
mBL.setSpeed(0);
}
private void solenoidController() {
if(stick.getRawButton(1)) tshirtSolenoid.set(true);
else tshirtSolenoid.set(false);
}
}