77
88package org .usfirst .frc .team199 .Robot2018 ;
99
10+ import org .usfirst .frc .team199 .Robot2018 .commands .CloseIntake ;
11+ import org .usfirst .frc .team199 .Robot2018 .commands .FindTurnTimeConstant ;
12+ import org .usfirst .frc .team199 .Robot2018 .commands .IntakeCube ;
13+ import org .usfirst .frc .team199 .Robot2018 .commands .OpenIntake ;
14+ import org .usfirst .frc .team199 .Robot2018 .commands .OuttakeCube ;
1015import org .usfirst .frc .team199 .Robot2018 .commands .PIDMove ;
1116import org .usfirst .frc .team199 .Robot2018 .commands .PIDTurn ;
1217import org .usfirst .frc .team199 .Robot2018 .commands .ResetEncoders ;
1520import org .usfirst .frc .team199 .Robot2018 .commands .ShiftDriveType ;
1621import org .usfirst .frc .team199 .Robot2018 .commands .ShiftHighGear ;
1722import org .usfirst .frc .team199 .Robot2018 .commands .ShiftLowGear ;
23+ import org .usfirst .frc .team199 .Robot2018 .commands .ToggleLeftIntake ;
24+ import org .usfirst .frc .team199 .Robot2018 .commands .ToggleRightIntake ;
1825import org .usfirst .frc .team199 .Robot2018 .commands .UpdatePIDConstants ;
1926
2027import edu .wpi .first .wpilibj .Joystick ;
@@ -32,24 +39,28 @@ public class OI {
3239 */
3340
3441 public Joystick leftJoy ;
42+ public Joystick rightJoy ;
3543 private JoystickButton shiftLowGearButton ;
3644 private JoystickButton shiftHighGearButton ;
3745 private JoystickButton shiftDriveTypeButton ;
38- private JoystickButton PIDMoveButton ;
39- private JoystickButton PIDTurnButton ;
46+ private JoystickButton pIDMoveButton ;
47+ private JoystickButton pIDTurnButton ;
4048 private JoystickButton resetEncButton ;
41- private JoystickButton MoveLiftUpButton ;
42- private JoystickButton MoveLiftDownButton ;
43- public Joystick rightJoy ;
49+ private JoystickButton moveLiftUpButton ;
50+ private JoystickButton moveLiftDownButton ;
51+ private JoystickButton findTurnTimeConstantButton ;
4452 private JoystickButton updatePIDConstantsButton ;
4553 private JoystickButton updateEncoderDPPButton ;
54+
4655 public Joystick manipulator ;
47- private JoystickButton closeIntake ;
48- private JoystickButton openIntake ;
49- private JoystickButton raiseIntake ;
50- private JoystickButton lowerIntake ;
51- private JoystickButton intake ;
52- private JoystickButton outake ;
56+ private JoystickButton closeIntakeButton ;
57+ private JoystickButton openIntakeButton ;
58+ private JoystickButton raiseIntakeButton ;
59+ private JoystickButton lowerIntakeButton ;
60+ private JoystickButton intakeCubeButton ;
61+ private JoystickButton outakeCubeButton ;
62+ private JoystickButton toggleLeftIntakeButton ;
63+ private JoystickButton toggleRightIntakeButton ;
5364
5465 public int getButton (String key , int def ) {
5566 if (!SmartDashboard .containsKey ("Button/" + key )) {
@@ -61,20 +72,24 @@ public int getButton(String key, int def) {
6172 return (int ) SmartDashboard .getNumber ("Button/" + key , def );
6273 }
6374
64- public OI () {
75+ public OI (Robot robot ) {
6576 leftJoy = new Joystick (0 );
6677 shiftDriveTypeButton = new JoystickButton (leftJoy , getButton ("Shift Drive Type" , 2 ));
6778 shiftDriveTypeButton .whenPressed (new ShiftDriveType ());
68- PIDMoveButton = new JoystickButton (leftJoy , getButton ("PID Move" , 7 ));
69- PIDMoveButton
79+ pIDMoveButton = new JoystickButton (leftJoy , getButton ("PID Move" , 7 ));
80+ pIDMoveButton
7081 .whenPressed (new PIDMove (Robot .sd .getConst ("Move Targ" , 24 ), Robot .dt , Robot .sd , RobotMap .distEncAvg ));
71- PIDTurnButton = new JoystickButton (leftJoy , getButton ("PID Turn" , 8 ));
82+ pIDTurnButton = new JoystickButton (leftJoy , getButton ("PID Turn" , 8 ));
7283 // PIDTurnButton.whenPressed(new PIDTurn(Robot.getConst("Turn Targ", 90),
7384 // Robot.dt, Robot.sd RobotMap.fancyGyro));
74- PIDTurnButton
85+ pIDTurnButton
7586 .whenReleased (new PIDTurn (Robot .getConst ("Turn Targ" , 90 ), Robot .dt , Robot .sd , RobotMap .fancyGyro ));
7687 resetEncButton = new JoystickButton (leftJoy , getButton ("Reset Dist Enc" , 10 ));
7788 resetEncButton .whenPressed (new ResetEncoders ());
89+ findTurnTimeConstantButton = new JoystickButton (leftJoy , getButton ("Find Turn Time Constant" , 11 ));
90+ // the command will only run in test mode
91+ findTurnTimeConstantButton
92+ .whenPressed (new FindTurnTimeConstant (robot , Robot .dt , Robot .rmap .fancyGyro , Robot .sd ));
7893
7994 rightJoy = new Joystick (1 );
8095 shiftHighGearButton = new JoystickButton (rightJoy , getButton ("Shift High Gear" , 3 ));
@@ -85,27 +100,80 @@ public OI() {
85100 updatePIDConstantsButton .whenPressed (new UpdatePIDConstants ());
86101 updateEncoderDPPButton = new JoystickButton (rightJoy , getButton ("Get Encoder Dist Per Pulse" , 9 ));
87102 updateEncoderDPPButton .whenPressed (new SetDistancePerPulse ());
88- MoveLiftUpButton = new JoystickButton (rightJoy , getButton ("Run Lift Motor Up" , 10 ));
89- MoveLiftDownButton = new JoystickButton (rightJoy , getButton ("Run Lift Motor Down" , 11 ));
90- MoveLiftUpButton .whileHeld (new RunLift (Robot .lift , true ));
91- MoveLiftDownButton .whileHeld (new RunLift (Robot .lift , false ));
103+ moveLiftUpButton = new JoystickButton (rightJoy , getButton ("Run Lift Motor Up" , 10 ));
104+ moveLiftDownButton = new JoystickButton (rightJoy , getButton ("Run Lift Motor Down" , 11 ));
105+ moveLiftUpButton .whileHeld (new RunLift (Robot .lift , true ));
106+ moveLiftDownButton .whileHeld (new RunLift (Robot .lift , false ));
92107
93108 manipulator = new Joystick (2 );
94- // closeIntake = new JoystickButton(manipulator, getButton("Close Intake
95- // Button", 1));
96- // closeIntake.whenPressed(new CloseIntake());
97- // openIntake = new JoystickButton(manipulator, getButton("Open Intake Button",
98- // 2));
99- // openIntake.whenPressed(new OpenIntake());
100- // raiseIntake = new JoystickButton(manipulator, getButton("Raise Intake
101- // Button", 3));
102- // raiseIntake.whenPressed(new RaiseIntake());
103- // lowerIntake = new JoystickButton(manipulator, getButton("Lower Intake
104- // Button", 4));
105- // lowerIntake.whenPressed(new LowerIntake());
106- // intake = new JoystickButton(manipulator, getButton("Intake Button", 5));
107- // intake.whenPressed(new IntakeCube());
108- // outake = new JoystickButton(manipulator, getButton("Outake Button", 6));
109- // outake.whenPressed(new OutakeCube());
109+ if (manipulator .getButtonCount () == 0 ) {
110+ System .out .println ("Manipulator not plugged in!" );
111+ } else {
112+ closeIntakeButton = new JoystickButton (manipulator , getButton ("Close Intake Button" , 1 ));
113+ closeIntakeButton .whenPressed (new CloseIntake ());
114+ openIntakeButton = new JoystickButton (manipulator , getButton ("Open Intake Button" , 2 ));
115+ openIntakeButton .whenPressed (new OpenIntake ());
116+ // raiseIntake = new JoystickButton(manipulator, getButton("Raise Intake
117+ // Button", 3));
118+ // raiseIntake.whenPressed(new RaiseIntake());
119+ // lowerIntake = new JoystickButton(manipulator, getButton("Lower Intake
120+ // Button", 4));
121+ // lowerIntake.whenPressed(new LowerIntake());
122+ intakeCubeButton = new JoystickButton (manipulator , getButton ("Intake Button" , 5 ));
123+ intakeCubeButton .whenPressed (new IntakeCube ());
124+ outakeCubeButton = new JoystickButton (manipulator , getButton ("Outake Button" , 6 ));
125+ outakeCubeButton .whenPressed (new OuttakeCube ());
126+ toggleLeftIntakeButton = new JoystickButton (manipulator , getButton ("Toggle Left Intake Button" , 3 ));
127+ toggleLeftIntakeButton .whenPressed (new ToggleLeftIntake ());
128+ toggleRightIntakeButton = new JoystickButton (manipulator , getButton ("Toggle Right Intake Button" , 4 ));
129+ toggleRightIntakeButton .whenPressed (new ToggleRightIntake ());
130+ }
131+ }
132+
133+ // /**
134+ // * Returns the getY from leftJoy squared (preserving sign)
135+ // *
136+ // * @return The y value squared
137+ // */
138+ // public double squareLeftY() {
139+ // return leftJoy.getY() * leftJoy.getY() * Math.signum(leftJoy.getY());
140+ // }
141+ //
142+ // /**
143+ // * Returns the getY from rightJoy squared (preserving sign)
144+ // *
145+ // * @return The y value squared
146+ // */
147+ // public double squareRightY() {
148+ // return rightJoy.getY() * rightJoy.getY() * Math.signum(rightJoy.getY());
149+ // }
150+ //
151+ // /**
152+ // * Returns the getX from leftJoy squared (preserving sign)
153+ // *
154+ // * @return The x value squared
155+ // */
156+ // public double squareLeftX() {
157+ // return leftJoy.getX() * leftJoy.getX() * Math.signum(leftJoy.getX());
158+ // }
159+ //
160+ // /**
161+ // * Returns the getX from rightJoy squared (preserving sign)
162+ // *
163+ // * @return The x value squared
164+ // */
165+ // public double squareRightX() {
166+ // return rightJoy.getX() * rightJoy.getX() * Math.signum(rightJoy.getX());
167+ // }
168+
169+ /**
170+ * Used to square joystick values while keeping sign
171+ *
172+ * @param joyVal
173+ * The joystick value to stick
174+ * @return The squared joystick value with same sign
175+ */
176+ public double squareValueKeepSign (double joyVal ) {
177+ return joyVal * joyVal * Math .signum (joyVal );
110178 }
111179}
0 commit comments