-
Notifications
You must be signed in to change notification settings - Fork 0
Subsystems and code structure
The robot has 6 main subsystems which control its various actions. These are:
- Driving:
SwerveSubsystem
- Intake:
IntakeSubsytem
- Shooter/Indexer:
ShooterSubsystem
- Arm:
ArmSubsystem
- Climbers:
ClimberSubsystem
- LEDs:
LEDController
Additionally, the Vision
class contains static methods for getting data from the two limelights, and the SwerveModule
class contains data about a swerve module and methods to set and get its state.
Each subsystem has a corresponding static subclass in the Constants
file where its CAN IDs, control constants, distances, etc. are stored.
-
private SwerveModule[] swerveModules
- an array of all four SwerveModules. #0 is the front left wheel, and we count up counterclockwise -
private SwerveDrivePoseEstimator odometry
- WPIlib pose estimator which combines wheel measurements with vision measurements to estimate the robot's location on the field -
private Field2d field
- used to display the robot's pose estimate on Shuffleboard -
private final Pigeon2 pigeon
- CTRE Pigeon sensor which measures changes in the robot's direction
-
SwerveModulePosition[] getPositions()
: gets theSwerveModulePosition
(distance traveled and current direction) for each module and returns them in an array -
SwerveModuleState[] getStates()
: gets theSwerveModuleState
(speed and direction) for each module and returns them in an array
-
void drive()
- drive function used during teleop control. Sets the robot to drive at a given speed, and uses open loop control to set the modules' speeds- Inputs:
-
double x
,double y
: the speed to move the robot on the x and y axes in meters/second -
double rotation
: the speed to spin the robot in radians/second -
boolean isFieldRelative
: if set totrue
, the robot will use the field's coordinate system instead of its own to determine driving speeds
-
- Inputs:
-
void closedLoopDrive()
- drive function used by the PathPlanner library while following trajectories. Sets the robot to drive at a givenChassisSpeeds
and uses closed loop control to set the modules' speeds -
void driveFromChassisSpeeds()
- the core drive function of the robot, used by both other drive functions and during auto-aligning. Calculates the correct speed and direction for each wheel and passes them to the four modules.- Inputs:
-
ChassisSpeeds speeds
: the speed to move the robot (ChassisSpeeds
contains both translation and rotational speeds) -
boolean isOpenLoop
: whether the modules should control their speed with open- or closed-loop control
-
- Inputs:
-
void resetOdometry()
: sets the robot's pose to a givenPose2d
-
void zeroGyro()
: sets the pigeon's "zero" direction to be the direction the robot is currently facing -
Pose2d getPose()
: returns the robots pose in meters as estimated by theodometry
-
ChassisSpeeds getRobotRelativeSpeeds()
: gets the robot's current velocity and angular velocity of the robot in meters/second and radians/second. Returns the data as aChassisSpeeds
-
double getYawAsDouble()
: gets the current heading measurement in degrees from the pigeon2. This value is not limited to 0-360, so if you spin around twice, the pigeon would read 720 degrees -
Rotation2d getYaw()
: constructs aRotation2d
with the heading measurement from the pigeon2 -
void periodic()
: this function gets called every 20ms while the robot is powered (even if it's disabled). Anything that needs to be constantly updated goes here:-
if an AprilTag is in view of the limelight, update the
odometry
with the limelight's estimated pose -
supply info about the drivebase and swerve modules to the driverstation
-
- the arm is actuated by two Falcon500 motors. They operate in sync, but rotate in opposite directions.
-
private final TalonFX motorR
- The leader motor, configured to run a MotionMagic control loop -
private final TalonFX motorL
- the follower motor, configured to copymotorR
's motion, but in the opposite direction
-
-
private MotionMagicConfig MMconfig
- configures the maximum velocity and acceleration for the motion profile generation -
private SoftwareLimitSwitchConfigs limitConfig
- configures the arms minimum and maximum positions -
private Slot0Config PIDConfig
- configures PID and Feedforward control loop. The constants themselves are inConstants.ArmConstants
-
private double setpoint
- the goal position of the arm
-
void setTarget()
: sets the goal angle of the arm to a number of degrees. 0 is horizontal. -
double getArmPosition()
: gets the current angle of the arm in degrees -
boolean isAtTarget()
: returnstrue
if the arm is at the goal position (plus or minus a small threshold value)
-
private final CANSparkMax intakeMotor
: The motor that runs the intake -
private final DigitalInput beamSensor
: unused
-
void runIntake(double speed)
: Runs the intake at currently undetermined speed -
boolean isNoteInIntake()
: Checks whether or not the note is in the intake
- There are two motors on the climber
-
private final CANSparkMax motorL
: Left motor for the climber -
private final CANSparkMax motorR
: Right motor for the climber
-
Command climb(DoubleSupplier leftSpeed, DoubleSupplier rightSpeed)
: Sets to an undetermined speed
-
private AddressableLED leds
: The strip of leds on the robot -
private AddressableLEDBuffer buffer
: -
private LedPattern currentPattern
: This variable controls the pattern displayed by the leds
-
private final CANSparkMax beltMotor
: The motor that controls the belt -
private final CANSparkMax shooterMotor
: The motor that controls the shooter -
private final DigitalInput beamSensor
: unused -
private final RelativeEncoder shooterEncoder
: An encoder for theshooterMotor
position -
private final SparkPIDController shooterSpeedController
: Allows us to use PID to control theshooterMotor
-
private final SimpleMotorFeedForward shooterFeedforward
: A variable that accounts for the force of gravity -
private double setpoint
: Undefined set point
-
boolean isNoteInShooter()
: Checking if the note is in the shooter -
double getShooterWheelSpeed()
: Getting the shooter wheel speed through the shooter encoder -
boolean isAtShootingSpeed()
: Checking if the shooter is at the shooter speed -
void setBeltSpeed(double speed)
: Setting the belt speed to a currently undetermined speed -
void setShooterSpeed(double speed)
: Setting the shooter speed to a currently undetermined speed -
void setTargetShooterSpeed(double rotationsPerSec)
: Setting the target shooter speed using PID velocity control