- Using Constants.java
- Using the XBox Controller
- Using the SparkMax Controller
Overview
Constants.java is used to store information that is static and does not change throughout the lifecycle of robot operation
Some Information that can be stored here
- Joystick ID's
- CAN ID's (For the SparkMax motors)
- And Other Static Variables!
How to Code
-
Visit Constants.java
-
Create the class for your Subsystem
public final class Constants { //YOUR CLASS BELOW (the example uses the name Storage) public final class Storage { //insert id's here } }
-
Add your own static information
public final class Constants { //YOUR CLASS BELOW (the example uses the name Storage) public final class Storage { public static final int CANID_STORAGE_MOTOR1 = 10; } }
-
Call your Constants.java information in your Subsystem
-
Import Constants.java
import frc.robot.Constants.java;
-
Call your value
private int MOTOR1_ID = Constants.Storage.CANID_STORAGE_MOTOR1;
-
The Controller Workflow
- When you press a button on the controller, it will call a Command
- The command will call method(s) from a Subsystem
Getting Started with Xbox Controller and Commands
- Grab your imports in RobotContainer.java
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
- Create your controller object in RobotContainer.java
public class RobotContainer {
private final XboxController m_joy0 = new XboxController(0); //joystick #0
private final JoystickButton joy0_a = new JoystickButton(m_joy0, 1); //button 'a' on joystick
}
SparkMAX Advantages/Features
- Sparks are a great way to control precise motor movement
- Sparks can operate under a brushless mode making them very powerful — torque!
How To Code
- Create a new subsystem for your SparkMax