Skip to content

Commit 5bf7af2

Browse files
committed
joystick
1 parent 7189fcb commit 5bf7af2

File tree

9 files changed

+112
-10
lines changed

9 files changed

+112
-10
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ out/
170170

171171
# Simulation GUI and other tools window save file
172172
*-window.json
173+
simgui.json
174+
simgui-ds.json
175+
networktables.json
173176

174177
# Simulation data log directory
175178
logs/
176179

177180
# Folder that has CTRE Phoenix Sim device config storage
178-
ctre_sim/
181+
ctre_sim/

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
}
2626
},
2727
],
28-
"java.test.defaultConfig": "WPIlibUnitTests"
28+
"java.test.defaultConfig": "WPIlibUnitTests",
29+
"java.debug.settings.onBuildFailureProceed": true
2930
}

src/main/java/frc/robot/examples/DigitalInputExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Examples of using digital inputs.
1111
*/
12-
public final class DigitalInputExamples {
12+
public abstract class DigitalInputExamples {
1313

1414
/**
1515
* Digital Inputs detect a true or false value.

src/main/java/frc/robot/examples/EncoderExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Examples of using encoders
1717
*/
18-
public final class EncoderExamples {
18+
public abstract class EncoderExamples {
1919

2020
/**
2121
* Examples for a Relative Encoder. Relative here means that the value gets erased whenever we turn off the

src/main/java/frc/robot/examples/GyroExamples.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
import edu.wpi.first.wpilibj.SerialPort.Port;
1010

1111
/**
12-
* Examples of using the NavX gyro
12+
* Used to get the robot orientation in 3-dimensional space. Examples are using the NavX gyro.
1313
* https://pdocs.kauailabs.com/navx-mxp/
1414
*/
15-
public final class GyroExamples {
15+
public abstract class GyroExamples {
1616

1717
/**
1818
* https://simple.wikipedia.org/wiki/Pitch,_yaw,_and_roll
1919
*/
2020
private void NavX_GetRobotAngles_Example() {
2121
// Robot has One NavX usually either connected via MXP or USB on the RoboRIO
22+
// AHRS = Attitude and Heading Reference System
2223
// final Port navxPort = Port.kUSB;
2324
final Port navxPort = Port.kMXP;
2425
final AHRS navx = new AHRS(navxPort);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
package frc.robot.examples;
6+
7+
import edu.wpi.first.wpilibj.Joystick;
8+
import edu.wpi.first.wpilibj.XboxController;
9+
import edu.wpi.first.wpilibj2.command.Commands;
10+
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
11+
12+
/**
13+
* Joystick examples.
14+
*/
15+
public abstract class JoystickExamples {
16+
// Get joystick using Port Number on Driver Station
17+
final int PortNumberOnDriverStation = 0;
18+
final Joystick joystick = new Joystick(PortNumberOnDriverStation);
19+
20+
/**
21+
* Buttons - get if a specific button is currently pressed
22+
*/
23+
private void Joystick_GetButtonPress_Example() {
24+
// Buttons start at 1 and not 0
25+
boolean isPressingButton1 = joystick.getRawButton(1);
26+
boolean isPressingButton8 = joystick.getRawButton(8);
27+
}
28+
29+
/**
30+
* Joystick Axis - X, Y, Z
31+
*/
32+
private void Joystick_GetAxis_Example() {
33+
// left/right
34+
// left is negative
35+
// right is positive
36+
// sometimes we negative this depending on the use case
37+
double xInput = joystick.getX();
38+
39+
// forwards/backwards
40+
// forwards is negative
41+
// backwards in postive
42+
// very common we negate this in our code
43+
double yInput = joystick.getY();
44+
45+
// some joysticks twist too
46+
// clockwise postive usually
47+
// counter-clockwise negative usually
48+
double zInput = joystick.getZ();
49+
}
50+
51+
/**
52+
* CommandXboxController by WPILib
53+
*/
54+
private void XboxController_CommandBased_Example() {
55+
// WPILib offers an XboxController class for simplicity
56+
final int PortNumberOnDriverStationForXbox = 1;
57+
final CommandXboxController cmdXboxController = new CommandXboxController(PortNumberOnDriverStationForXbox);
58+
59+
// Buttons to trigger commmands
60+
cmdXboxController.y().onTrue(Commands.print("'Y' button was pressed!"));
61+
cmdXboxController.b().onTrue(Commands.print("'B' button was pressed!"));
62+
cmdXboxController.a().onTrue(Commands.print("'A' button was pressed!"));
63+
cmdXboxController.x().onTrue(Commands.print("'X' button was pressed!"));
64+
cmdXboxController.start().onTrue(Commands.print("'Start' button was pressed!"));
65+
cmdXboxController.back().onTrue(Commands.print("'Back' button was pressed!"));
66+
cmdXboxController.rightStick().onTrue(Commands.print("'Right Stick' was pressed!"));
67+
cmdXboxController.leftStick().onTrue(Commands.print("'Left Stick' was pressed!"));
68+
cmdXboxController.rightBumper().onTrue(Commands.print("'Right Bumper' was pressed!"));
69+
cmdXboxController.leftBumper().onTrue(Commands.print("'Left Bumper' was pressed!"));
70+
71+
// You can get the underlying XboxController for it using getHID()
72+
final XboxController xboxController = cmdXboxController.getHID();
73+
74+
// Buttons
75+
boolean isYPressed = xboxController.getYButton();
76+
boolean isBPressed = xboxController.getBButton();
77+
boolean isAPressed = xboxController.getAButton();
78+
boolean isXPressed = xboxController.getXButton();
79+
boolean isStartPressed = xboxController.getStartButton();
80+
boolean isBackPressed = xboxController.getBackButton();
81+
boolean isRightStickPressed = xboxController.getRightStickButton();
82+
boolean isLeftStickPressed = xboxController.getLeftStickButton();
83+
boolean isRightBumperPressed = xboxController.getRightBumper();
84+
boolean isLeftBumperPressed = xboxController.getLeftBumper();
85+
86+
// Triggers
87+
// left ranges from [0, 1]
88+
// right ranges from [0, 1]
89+
double leftTriggerValue = xboxController.getLeftTriggerAxis();
90+
double rightTriggerValue = xboxController.getRightTriggerAxis();
91+
92+
// D-Pad
93+
// The POV angles start at 0 in the up direction, and increase clockwise (e.g. right is 90, upper-left is 315).
94+
// Returns -1 if the POV is not pressed.
95+
double pov = xboxController.getPOV();
96+
}
97+
}

src/main/java/frc/robot/examples/MotorControllerExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Examples of using motor controllers
1616
*/
17-
public final class MotorControllerExamples {
17+
public abstract class MotorControllerExamples {
1818

1919
/**
2020
* Example for a PWM Motor Controller. This example uses a Spark from RevRobotics.

src/main/java/frc/robot/examples/PneumaticsExamples.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
1111

1212
/**
13-
* Pneumatics examples.
13+
* Pneumatics examples. Pneumatics uses air with a compressor and air tank(s) on the robot to perform actions.
1414
*/
15-
public final class PneumaticsExamples {
15+
public abstract class PneumaticsExamples {
1616

1717
/*
1818
* Solenoids can be used to controller pneumatic cylinders are set to true or false

src/main/java/frc/robot/examples/UltrasonicExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Ultrasonic sensor examples.
1111
*/
12-
public final class UltrasonicExamples {
12+
public abstract class UltrasonicExamples {
1313

1414
/*
1515
* Example Ultrasonic Sensor: https://kb.vex.com/hc/en-us/articles/360038608771-Using-the-V5-3-Wire-UltraSonic-Range-Finder

0 commit comments

Comments
 (0)