Valkyrie 2026
Loading...
Searching...
No Matches
valor::swerve::Swerve Class Reference
Inheritance diagram for valor::swerve::Swerve:
valor::BaseSubsystem valor::Loggable

Public Member Functions

 Swerve (std::string name, std::vector< std::pair< std::unique_ptr< BaseController >, std::unique_ptr< BaseController > > > modules, std::shared_ptr< gyro::Gyro > gyro, units::meter_t module_radius, units::meter_t _wheelDiameter, std::vector< int > moduleCoordsX, std::vector< int > moduleCoordsY, units::meter_t driveBaseRadius)
void AnalyzeDashboard () override
 Synchronize dashboard data (both read and write).
void LoggablePeriodic () override
 Periodic callback for logging updates.
void Reset () override
 Reset all subsystem state.
void SimulationPeriodic () override
void ResetGyro ()
void ApplyRequest (requests::ApplyChassisSpeeds)
void ApplyRequest (requests::ApplyStates)
void ResetOdometry (FrameWrapper< FieldFrame, frc::Pose2d > pose)
void ResetEncoders ()
std::vector< frc::SwerveModulePosition > GetModulePositions ()
 Retrieves the current position of each swerve module.
std::vector< frc::SwerveModuleState > GetModuleStates ()
 Retrieves the current state (speed and angle) of each swerve module.
double GetSkiddingRatio ()
bool IsRobotSkidding ()
constexpr std::vector< std::unique_ptr< SwerveModule > > & GetModules ()
void UpdateAngularAcceleration ()
 Updates the calculated angular acceleration of the robot. This function uses the current and previous yaw rates from the gyroscope to compute the angular acceleration.
units::angular_acceleration::radians_per_second_squared_t GetSmoothedAngularAcceleration ()
double RotationLerping (double)
void FollowTrajectory (const choreo::SwerveSample &sample)
constexpr units::meter_t GetDriveBaseRadius () const
constexpr const auto & GetState () const
constexpr auto & GetState ()
Public Member Functions inherited from valor::BaseSubsystem
 BaseSubsystem (std::string name)
 Construct a new Valor Subsystem object.
virtual void AssessInputs ()
 Read controller logic and set subsystem state.
virtual void AssignOutputs ()
 Read subsystem state and send motor commands.
void SetGamepads (valor::Gamepad *_operatorGamepad, valor::Gamepad *_driverGamepad)
Public Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 Loggable (std::shared_ptr< nt::NetworkTable > table)
 Construct a Loggable that uses an existing NetworkTable.
 Loggable ()
 Default construct an uninitialized Loggable.
void LogChild (std::string_view name, Loggable *child)
 Register a child Loggable under a named subtree.
void LogChild (std::string_view name, wpi::Sendable *child)
 Register a child Sendable under a named subtree.
void SetPeriodicLevel (LogLevel level)
 Set the logging level for LoggablePeriodic.
template<typename T>
WriteLog (std::string_view field, const T &data, LogLevel level=LogLevel::Normal)
 Publish a value to NetworkTables under the given field.
template<typename T>
ReadLog (std::string_view field, const T &defaultValue={})
 Read a value from NetworkTables for the given field.
template<>
decltype(Loggable::subscribers) ::iterator addSubscriber (std::string_view field, const std::vector< bool > &defaultValue)
template<>
void WriteLogImpl (nt::Publisher *pub, const std::vector< bool > &data)
template<>
std::vector< bool > ReadLogImpl (nt::Subscriber *sub)

Protected Member Functions

void EnableCarpetGrain (double grainMultiplier, bool roughTowardsRed)
FrameWrapper< FieldFrame, frc::ChassisSpeeds > VectorLockedSpeeds (FrameWrapper< FieldFrame, frc::ChassisSpeeds > speeds, FrameWrapper< FieldFrame, frc::Rotation2d > heading)
void StartOdomThread (units::hertz_t freq)
void UpdateOdometry ()
void SetRotationalLerpMap (wpi::interpolating_map< double, double > _interpolationMap)
Protected Member Functions inherited from valor::Loggable
virtual void OnLoggingStart ()
 Hook invoked when logging is started for this object.

Static Protected Member Functions

static FrameWrapper< FieldFrame, frc::ChassisSpeeds > ReflectDriveSpeeds (FrameWrapper< FieldFrame, frc::ChassisSpeeds > unreflectedSpeeds)

Protected Attributes

FrameWrapper< FieldFrame, frc::ChassisSpeeds > commandedSpeeds
units::meters_per_second_t maxDriveSpeed
units::radians_per_second_t maxRotationSpeed
std::shared_ptr< gyro::Gyrogyro
std::unique_ptr< ctre::phoenix6::swerve::impl::SwerveDriveKinematics > kinematics
util::Locked< std::unique_ptr< ctre::phoenix6::swerve::impl::SwerveDrivePoseEstimator > > rawEstimator
util::Locked< std::unique_ptr< ctre::phoenix6::swerve::impl::SwerveDrivePoseEstimator > > calcEstimator
bool toast
std::vector< std::unique_ptr< SwerveModule > > swerveModules
frc::Timer resetOdom
Protected Attributes inherited from valor::BaseSubsystem
valor::GamepadoperatorGamepad
valor::GamepaddriverGamepad

Additional Inherited Members

Static Public Member Functions inherited from valor::Loggable
static units::millisecond_t GetLoggingTime ()
static constexpr LoggableGetRoot ()

Member Function Documentation

◆ AnalyzeDashboard()

void valor::swerve::Swerve::AnalyzeDashboard ( )
overridevirtual

Synchronize dashboard data (both read and write).

The analyzeDashboard function runs at all times (disabled, auto, and teleop). The intent of the function is to send sensor and state information from the robot to the Driver Station for debugging. Additionally, driver commands and data can be sent from the Driver Station to the robot and collected in this function.

ALL network table and sensor logic should be in this function as both network table and sensor information should be read at all times, not just during teleop since auto will never get that information.

This function is a virtual function and should be implemented by the subsystem.

Reimplemented from valor::BaseSubsystem.

◆ GetModulePositions()

std::vector< frc::SwerveModulePosition > valor::swerve::Swerve::GetModulePositions ( )

Retrieves the current position of each swerve module.

Returns
An array of frc::SwerveModulePosition objects, representing the position of each module.

◆ GetModuleStates()

std::vector< frc::SwerveModuleState > valor::swerve::Swerve::GetModuleStates ( )

Retrieves the current state (speed and angle) of each swerve module.

Returns
An array of frc::SwerveModuleState objects, representing the state of each module.

◆ LoggablePeriodic()

void valor::swerve::Swerve::LoggablePeriodic ( )
overridevirtual

Periodic callback for logging updates.

If a derived class needs to perform periodic updates to published values, override this method. It is intended to be called by the logging framework; this base class provides an empty implementation.

Reimplemented from valor::Loggable.

◆ Reset()

void valor::swerve::Swerve::Reset ( )
overridevirtual

Reset all subsystem state.

Use this function to set the subsystem state to default values, as well as set the motor outputs to 0 so the robot doesn't "lurch" when booting up due to phantom state (aka. state that was previously set but hasn't been reset yet).

This function is a virtual function and should be implemented by the subsystem.

Reimplemented from valor::BaseSubsystem.

◆ ResetOdometry()

void valor::swerve::Swerve::ResetOdometry ( FrameWrapper< FieldFrame, frc::Pose2d > pose)

Reset the robot's position on the field. Any accumulted gyro drift will be noted and accounted for in subsequent calls to getPoseMeters()

Parameters
poseThe robot's actual position on the field

The documentation for this class was generated from the following file:
  • src/main/include/valkyrie/drivetrain/swerve/Swerve.h