-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.java
More file actions
122 lines (98 loc) · 3.89 KB
/
Robot.java
File metadata and controls
122 lines (98 loc) · 3.89 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
package org.usfirst.frc.team5941.robot;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* 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 {
final String defaultAuto = "Default";
final String customAuto = "My Auto";
String autoSelected;
SendableChooser chooser;
VictorSP rightSide = new VictorSP(1), leftSide = new VictorSP(0);
//RobotDrive chassis = new RobotDrive(rightSide, leftSide);
Joystick xbox = new Joystick(0), solo = new Joystick(1);
double leftYAxis = xbox.getRawAxis(4), rightYAxis = xbox.getRawAxis(5);
VictorSP pneumatic = new VictorSP(4);
DoubleSolenoid sol = new DoubleSolenoid(1, 0);
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
chooser = new SendableChooser();
chooser.addDefault("Default Auto", defaultAuto);
chooser.addObject("My Auto", customAuto);
SmartDashboard.putData("Auto choices", chooser);
}
/**
* This autonomous (along with the chooser code above) shows how to select between different autonomous modes
* using the dashboard. The sendable chooser code works with the Java SmartDashboard. If you prefer the LabVIEW
* Dashboard, remove all of the chooser code and uncomment the getString line to get the auto name from the text box
* below the Gyro
*
* You can add additional auto modes by adding additional comparisons to the switch structure below with additional strings.
* If using the SendableChooser make sure to add them to the chooser code above as well.
*/
public void autonomousInit() {
autoSelected = (String) chooser.getSelected();
// autoSelected = SmartDashboard.getString("Auto Selector", defaultAuto);
System.out.println("Auto selected: " + autoSelected);
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
switch(autoSelected) {
case customAuto:
//Put custom auto code here
break;
case defaultAuto:
default:
//Put default auto code here
break;
}
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
// chassis.arcadeDrive(solo); //<---- If the code for tank driving doesn't work
leftYAxis = xbox.getRawAxis(1);
rightYAxis = xbox.getRawAxis(5);
//chassis.tankDrive(leftYAxis, rightYAxis);
leftSide.set(-(leftYAxis/3.0));
rightSide.set((rightYAxis/3.0));
if (solo.getRawAxis(1) > 0.3) {
pneumatic.set(solo.getRawAxis(1));
} else if (solo.getRawAxis(1) < -0.3) {
pneumatic.set(solo.getRawAxis(1));
} else {
pneumatic.set(0.0);
}
if (solo.getRawButton(1) && solo.getRawButton(7)) {
sol.set(DoubleSolenoid.Value.kReverse);
} else if (solo.getRawButton(8)) {
sol.set(DoubleSolenoid.Value.kForward);
//leftSide.set(0);
//rightSide.set(0);
} else {
sol.set(DoubleSolenoid.Value.kOff);
}
}
/**
* This function is called periodically during test mode
*/
public void testPeriodic() {
}
}