Swerve Overview =============== .. important:: Swerve functionality is only available for FRC users and is limited to Java at this time. New in 2024 is a high performance swerve API. This API simplifies the boilerplate necessary for swerve and maximizes performance. This section focuses on utilizing the Swerve API and configuring it correctly. Tuner X supports a :doc:`swerve project creator ` that greatly simplifies this process and removes common error cases. - Small API surface, easily debuggable * Build robot characteristics using ``SwerveModuleConstants`` (`Java `__) and ``SwerveDrivetrainConstants`` (`Java `__). * Integrates cleanly into WPILib `command-based `__ framework using ``CommandSwerveDrivetrain`` (from our examples or Tuner X). * Telemetrize directly in the odometry loop using the ``registerTelemetry()`` (`Java `__) lambda. * Supports handling the swerve state via ``SwerveRequest`` (`Java `__). * Supports robot-centric, field-centric and field-centric facing angle. * Supports common scenarios such as X mode (point all modules toward the center of the robot). - Simulation * Swerve simulation focuses on usability, and as such isn't perfectly accurate to a real robot. * Simply call ``updateSimState`` (`Java `__) in ``simulationPeriodic()`` (`Java `__). - Performance * Odometry is updated synchronously with the motor controllers. * Odometry is received as fast as possible using a separate thread. * Combine with `Phoenix Pro `__ and a `CANivore `__ with :ref:`timesync ` for improved performance. .. note:: Simulation boilerplate is automatically handled when generating a robot project using Tuner X. Hardware Requirements --------------------- Utilizing the swerve API requires that the robot drivetrain is composed of supported Phoenix 6 devices. At a minimum, these requirements are: - 8 TalonFX motor controllers (4 steer, 4 drive) - 4 CANcoders - 1 Pigeon 2.0 Overview on the API ------------------- Simple usage of the API is comprised of 4 core classes: - ``SwerveDrivetrainConstants`` (`Java `__) * This class handles characteristics of the robot that are not module specific. e.g. CAN bus, Pigeon 2 ID, whether FD is enabled or not. - ``SwerveModuleConstantsFactory`` (`Java `__) * Factory class that is used to instantiate ``SwerveModuleConstants`` for each module on the robot. - ``SwerveModuleConstants`` (`Java `__) * Represents the characteristics for a given module. - ``SwerveDrivetrain`` (`Java `__) * Created using ``SwerveDrivetrainConstants`` and a ``SwerveModuleConstants`` for each module, this is used to control the swerve drivetrain. Usage of these classes is available in the following articles in this section. .. toctree:: :maxdepth: 1 swerve-builder-api swerve-requests swerve-simulation