frc538 / 2020-infinite-recharge

Robot code for FRC Team 538.
0 stars 0 forks source link

Determine what Control Panel command(s) need to be used. #14

Closed drewwhis closed 4 years ago

drewwhis commented 4 years ago

Create a task for each command

First glance, it appears we will need commands to:

Others?

drewwhis commented 4 years ago

When we create commands, there are a few steps we want to follow.

  1. In the commands directory, we want to create a command file for the command we're writing.
  2. We cannot make a command until after we've made any subsystems it'll work on. We have to pass those subsystem(s) into the construction. For one subsystem, the constructor will look like public CommandName(SubsystemUsed subsystemName).
  3. Inside the constructor, we need to assign the subsystem(s) used to member variables. In this case, we need to create a field at the top of the class (private SubsystemUsed mSubsystemName;) and we need to assign the field inside the constructor (mSubsystemName = subsystemName;).
  4. At the end of the constructor, we have to specify that we are requiring the subsystem(s). This prevents competition with other commands. This is done with a line to addRequirements (in this case, addRequirements(mSubsystemName);).
  5. Now we can fill out the other methods, especially execute (what the command is supposed to do) and isFinished.
drewwhis commented 4 years ago

After we've defined the command, we can assign it to a button or trigger. Default commands are handled differently (see #16).

  1. In RobotContainer, go to the configureButtonBindings method.
  2. Make sure your controller has been defined (like step 0 in #16).
  3. Create a Joystick button (description here: https://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj2/command/button/JoystickButton.html)
  4. Determine what state will trigger the command (pressing, releasing, etc.), and choose the appropriate method.
  5. Pass a new CommandToBeUsed(mSubsystem) argument into the method chosen.

If you need to rely on something more complicated than a button press/release, you'll need to consider the use of triggers. (https://docs.wpilib.org/en/latest/docs/software/commandbased/binding-commands-to-triggers.html)