88package org .usfirst .frc .team199 .Robot2018 ;
99
1010import org .usfirst .frc .team199 .Robot2018 .commands .CloseIntake ;
11+ import org .usfirst .frc .team199 .Robot2018 .commands .FindTurnTimeConstant ;
1112import org .usfirst .frc .team199 .Robot2018 .commands .IntakeCube ;
12- import org .usfirst .frc .team199 .Robot2018 .commands .LowerIntake ;
1313import org .usfirst .frc .team199 .Robot2018 .commands .OpenIntake ;
14- import org .usfirst .frc .team199 .Robot2018 .commands .OutakeCube ;
14+ import org .usfirst .frc .team199 .Robot2018 .commands .OuttakeCube ;
1515import org .usfirst .frc .team199 .Robot2018 .commands .PIDMove ;
1616import org .usfirst .frc .team199 .Robot2018 .commands .PIDTurn ;
1717import org .usfirst .frc .team199 .Robot2018 .commands .ResetEncoders ;
@@ -39,26 +39,28 @@ public class OI {
3939 */
4040
4141 public Joystick leftJoy ;
42+ public Joystick rightJoy ;
4243 private JoystickButton shiftLowGearButton ;
4344 private JoystickButton shiftHighGearButton ;
4445 private JoystickButton shiftDriveTypeButton ;
45- private JoystickButton PIDMoveButton ;
46- private JoystickButton PIDTurnButton ;
46+ private JoystickButton pIDMoveButton ;
47+ private JoystickButton pIDTurnButton ;
4748 private JoystickButton resetEncButton ;
48- private JoystickButton MoveLiftUpButton ;
49- private JoystickButton MoveLiftDownButton ;
50- public Joystick rightJoy ;
49+ private JoystickButton moveLiftUpButton ;
50+ private JoystickButton moveLiftDownButton ;
51+ private JoystickButton findTurnTimeConstantButton ;
5152 private JoystickButton updatePIDConstantsButton ;
5253 private JoystickButton updateEncoderDPPButton ;
54+
5355 public Joystick manipulator ;
54- private JoystickButton closeIntake ;
55- private JoystickButton openIntake ;
56- private JoystickButton raiseIntake ;
57- private JoystickButton lowerIntake ;
58- private JoystickButton intake ;
59- private JoystickButton outake ;
60- private JoystickButton toggleLeftIntake ;
61- private JoystickButton toggleRightIntake ;
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 ;
6264
6365 public int getButton (String key , int def ) {
6466 if (!SmartDashboard .containsKey ("Button/" + key )) {
@@ -70,20 +72,24 @@ public int getButton(String key, int def) {
7072 return (int ) SmartDashboard .getNumber ("Button/" + key , def );
7173 }
7274
73- public OI () {
75+ public OI (Robot robot ) {
7476 leftJoy = new Joystick (0 );
7577 shiftDriveTypeButton = new JoystickButton (leftJoy , getButton ("Shift Drive Type" , 2 ));
7678 shiftDriveTypeButton .whenPressed (new ShiftDriveType ());
77- PIDMoveButton = new JoystickButton (leftJoy , getButton ("PID Move" , 7 ));
78- PIDMoveButton
79+ pIDMoveButton = new JoystickButton (leftJoy , getButton ("PID Move" , 7 ));
80+ pIDMoveButton
7981 .whenPressed (new PIDMove (Robot .sd .getConst ("Move Targ" , 24 ), Robot .dt , Robot .sd , RobotMap .distEncAvg ));
80- PIDTurnButton = new JoystickButton (leftJoy , getButton ("PID Turn" , 8 ));
82+ pIDTurnButton = new JoystickButton (leftJoy , getButton ("PID Turn" , 8 ));
8183 // PIDTurnButton.whenPressed(new PIDTurn(Robot.getConst("Turn Targ", 90),
8284 // Robot.dt, Robot.sd RobotMap.fancyGyro));
83- PIDTurnButton
85+ pIDTurnButton
8486 .whenReleased (new PIDTurn (Robot .getConst ("Turn Targ" , 90 ), Robot .dt , Robot .sd , RobotMap .fancyGyro ));
8587 resetEncButton = new JoystickButton (leftJoy , getButton ("Reset Dist Enc" , 10 ));
8688 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 ));
8793
8894 rightJoy = new Joystick (1 );
8995 shiftHighGearButton = new JoystickButton (rightJoy , getButton ("Shift High Gear" , 3 ));
@@ -94,36 +100,82 @@ public OI() {
94100 updatePIDConstantsButton .whenPressed (new UpdatePIDConstants ());
95101 updateEncoderDPPButton = new JoystickButton (rightJoy , getButton ("Get Encoder Dist Per Pulse" , 9 ));
96102 updateEncoderDPPButton .whenPressed (new SetDistancePerPulse ());
97- MoveLiftUpButton = new JoystickButton (rightJoy , getButton ("Run Lift Motor Up" , 10 ));
98- MoveLiftDownButton = new JoystickButton (rightJoy , getButton ("Run Lift Motor Down" , 11 ));
99- MoveLiftUpButton .whileHeld (new RunLift (Robot .lift , true ));
100- 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 ));
101107
102108 manipulator = new Joystick (2 );
103109 if (manipulator .getButtonCount () == 0 ) {
104110 System .err .println (
105111 "ERROR: manipulator does not appear to be plugged in. Disabling intake code. Restart code with manipulator plugged in to enable intake code" );
106112 } else {
107-
108- closeIntake = new JoystickButton (manipulator , getButton ("Close Intake Button" , 1 ));
109- closeIntake .whenPressed (new CloseIntake ());
110- openIntake = new JoystickButton (manipulator , getButton ("Open Intake Button" , 2 ));
111- openIntake .whenPressed (new OpenIntake ());
113+ closeIntakeButton = new JoystickButton (manipulator , getButton ("Close Intake Button" , 1 ));
114+ closeIntakeButton .whenPressed (new CloseIntake ());
115+ openIntakeButton = new JoystickButton (manipulator , getButton ("Open Intake Button" , 2 ));
116+ openIntakeButton .whenPressed (new OpenIntake ());
112117 // raiseIntake = new JoystickButton(manipulator, getButton("Raise Intake
113118 // Button", 3));
114119 // raiseIntake.whenPressed(new RaiseIntake());
115120 // lowerIntake = new JoystickButton(manipulator, getButton("Lower Intake
116121 // Button", 4));
117- lowerIntake .whenPressed (new LowerIntake ());
118- intake = new JoystickButton (manipulator , getButton ("Intake Button" , 5 ));
119- intake .whenPressed (new IntakeCube ());
120- outake = new JoystickButton (manipulator , getButton ("Outake Button" , 6 ));
121- outake .whenPressed (new OutakeCube ());
122- toggleLeftIntake = new JoystickButton (manipulator , getButton ("Toggle Left Intake Button" , 3 ));
123- toggleLeftIntake .whenPressed (new ToggleLeftIntake ());
124- toggleRightIntake = new JoystickButton (manipulator , getButton ("Toggle Right Intake Button" , 4 ));
125- toggleRightIntake .whenPressed (new ToggleRightIntake ());
126-
122+ // lowerIntake.whenPressed(new LowerIntake());
123+ intakeCubeButton = new JoystickButton (manipulator , getButton ("Intake Button" , 5 ));
124+ intakeCubeButton .whenPressed (new IntakeCube ());
125+ outakeCubeButton = new JoystickButton (manipulator , getButton ("Outake Button" , 6 ));
126+ outakeCubeButton .whenPressed (new OuttakeCube ());
127+ toggleLeftIntakeButton = new JoystickButton (manipulator , getButton ("Toggle Left Intake Button" , 3 ));
128+ toggleLeftIntakeButton .whenPressed (new ToggleLeftIntake ());
129+ toggleRightIntakeButton = new JoystickButton (manipulator , getButton ("Toggle Right Intake Button" , 4 ));
130+ toggleRightIntakeButton .whenPressed (new ToggleRightIntake ());
127131 }
132+
133+ }
134+
135+ // /**
136+ // * Returns the getY from leftJoy squared (preserving sign)
137+ // *
138+ // * @return The y value squared
139+ // */
140+ // public double squareLeftY() {
141+ // return leftJoy.getY() * leftJoy.getY() * Math.signum(leftJoy.getY());
142+ // }
143+ //
144+ // /**
145+ // * Returns the getY from rightJoy squared (preserving sign)
146+ // *
147+ // * @return The y value squared
148+ // */
149+ // public double squareRightY() {
150+ // return rightJoy.getY() * rightJoy.getY() * Math.signum(rightJoy.getY());
151+ // }
152+ //
153+ // /**
154+ // * Returns the getX from leftJoy squared (preserving sign)
155+ // *
156+ // * @return The x value squared
157+ // */
158+ // public double squareLeftX() {
159+ // return leftJoy.getX() * leftJoy.getX() * Math.signum(leftJoy.getX());
160+ // }
161+ //
162+ // /**
163+ // * Returns the getX from rightJoy squared (preserving sign)
164+ // *
165+ // * @return The x value squared
166+ // */
167+ // public double squareRightX() {
168+ // return rightJoy.getX() * rightJoy.getX() * Math.signum(rightJoy.getX());
169+ // }
170+
171+ /**
172+ * Used to square joystick values while keeping sign
173+ *
174+ * @param joyVal
175+ * The joystick value to stick
176+ * @return The squared joystick value with same sign
177+ */
178+ public double squareValueKeepSign (double joyVal ) {
179+ return joyVal * joyVal * Math .signum (joyVal );
128180 }
129181}
0 commit comments