Class SwerveControllerCommand

  • All Implemented Interfaces:
    Sendable, Command

    public class SwerveControllerCommand
    extends CommandBase
    A command that uses two PID controllers (PIDController) and a ProfiledPIDController (ProfiledPIDController) to follow a trajectory Trajectory with a swerve drive.

    This command outputs the raw desired Swerve Module States (SwerveModuleState) in an array. The desired wheel and module rotation velocities should be taken from those and used in velocity PIDs.

    The robot angle controller does not follow the angle given by the trajectory but rather goes to the angle given in the final state of the trajectory.

    • Constructor Detail

      • SwerveControllerCommand

        public SwerveControllerCommand​(Trajectory trajectory,
                                       Supplier<Pose2d> pose,
                                       SwerveDriveKinematics kinematics,
                                       PIDController xController,
                                       PIDController yController,
                                       ProfiledPIDController thetaController,
                                       Consumer<SwerveModuleState[]> outputModuleStates,
                                       Subsystem... requirements)
        Constructs a new SwerveControllerCommand that when executed will follow the provided trajectory. This command will not return output voltages but rather raw module states from the position controllers which need to be put into a velocity PID.

        Note: The controllers will *not* set the outputVolts to zero upon completion of the path- this is left to the user, since it is not appropriate for paths with nonstationary endstates.

        Note 2: The rotation controller will calculate the rotation based on the final pose in the trajectory, not the poses at each time step.

        trajectory - The trajectory to follow.
        pose - A function that supplies the robot pose - use one of the odometry classes to provide this.
        kinematics - The kinematics for the robot drivetrain.
        xController - The Trajectory Tracker PID controller for the robot's x position.
        yController - The Trajectory Tracker PID controller for the robot's y position.
        thetaController - The Trajectory Tracker PID controller for angle for the robot.
        outputModuleStates - The raw output module states from the position controllers.
        requirements - The subsystems to require.
    • Method Detail

      • initialize

        public void initialize()
        Description copied from interface: Command
        The initial subroutine of a command. Called once when the command is initially scheduled.
      • execute

        public void execute()
        Description copied from interface: Command
        The main body of a command. Called repeatedly while the command is scheduled.
      • end

        public void end​(boolean interrupted)
        Description copied from interface: Command
        The action to take when the command ends. Called when either the command finishes normally, or when it interrupted/canceled.

        Do not schedule commands here that share requirements with this command. Use Command.andThen(Command...) instead.

        interrupted - whether the command was interrupted/canceled
      • isFinished

        public boolean isFinished()
        Description copied from interface: Command
        Whether the command has finished. Once a command finishes, the scheduler will call its end() method and un-schedule it.
        whether the command has finished.