-
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.
-
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 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
-