WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
frc::SwerveModuleState Struct Reference

Represents the state of one swerve module. More...

#include <frc/kinematics/SwerveModuleState.h>

Public Member Functions

constexpr bool operator== (const SwerveModuleState &other) const
 Checks equality between this SwerveModuleState and another object.
 
constexpr void Optimize (const Rotation2d &currentAngle)
 Minimize the change in the heading this swerve module state would require by potentially reversing the direction the wheel spins.
 
constexpr void CosineScale (const Rotation2d &currentAngle)
 Scales speed by cosine of angle error.
 

Static Public Member Functions

static constexpr SwerveModuleState Optimize (const SwerveModuleState &desiredState, const Rotation2d &currentAngle)
 Minimize the change in heading the desired swerve module state would require by potentially reversing the direction the wheel spins.
 

Public Attributes

units::meters_per_second_t speed = 0_mps
 Speed of the wheel of the module.
 
Rotation2d angle
 Angle of the module.
 

Detailed Description

Represents the state of one swerve module.

Member Function Documentation

◆ CosineScale()

void frc::SwerveModuleState::CosineScale ( const Rotation2d & currentAngle)
inlineconstexpr

Scales speed by cosine of angle error.

This scales down movement perpendicular to the desired direction of travel that can occur when modules change directions. This results in smoother driving.

Parameters
currentAngleThe current module angle.

◆ operator==()

bool frc::SwerveModuleState::operator== ( const SwerveModuleState & other) const
inlineconstexpr

Checks equality between this SwerveModuleState and another object.

Parameters
otherThe other object.
Returns
Whether the two objects are equal.

◆ Optimize() [1/2]

void frc::SwerveModuleState::Optimize ( const Rotation2d & currentAngle)
inlineconstexpr

Minimize the change in the heading this swerve module state would require by potentially reversing the direction the wheel spins.

If this is used with the PIDController class's continuous input functionality, the furthest a wheel will ever rotate is 90 degrees.

Parameters
currentAngleThe current module angle.

◆ Optimize() [2/2]

static constexpr SwerveModuleState frc::SwerveModuleState::Optimize ( const SwerveModuleState & desiredState,
const Rotation2d & currentAngle )
inlinestaticconstexpr

Minimize the change in heading the desired swerve module state would require by potentially reversing the direction the wheel spins.

If this is used with the PIDController class's continuous input functionality, the furthest a wheel will ever rotate is 90 degrees.

Parameters
desiredStateThe desired state.
currentAngleThe current module angle.

Member Data Documentation

◆ angle

Rotation2d frc::SwerveModuleState::angle

Angle of the module.

◆ speed

units::meters_per_second_t frc::SwerveModuleState::speed = 0_mps

Speed of the wheel of the module.


The documentation for this struct was generated from the following file: