YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
yams::mechanisms::config::SwerveModuleConfig Class Reference

#include <SwerveModuleConfig.hpp>

Public Types

using TelemetryVerbosity = motorcontrollers::SmartMotorControllerConfig::TelemetryVerbosity
 

Public Member Functions

 SwerveModuleConfig ()=default
 
 SwerveModuleConfig (motorcontrollers::SmartMotorController *drive, motorcontrollers::SmartMotorController *azimuth)
 
SwerveModuleConfig & WithSmartMotorController (motorcontrollers::SmartMotorController *driveMotor, motorcontrollers::SmartMotorController *azimuthMotor)
 
SwerveModuleConfig & WithCosineCompensation (bool compensate)
 
SwerveModuleConfig & WithAbsoluteEncoder (std::function< wpi::units::degree_t()> supplier)
 
SwerveModuleConfig & WithExternalAbsoluteEncoder (std::any absoluteEncoder)
 
SwerveModuleConfig & WithCouplingRatio (std::optional< gearing::GearBox > couplingRatio)
 
SwerveModuleConfig & WithCouplingRatio (double driveMotorRotationsPerAzimuthRotation)
 
SwerveModuleConfig & WithDistanceFromCenterOfRotation (wpi::units::meter_t front, wpi::units::meter_t left)
 
SwerveModuleConfig & WithAbsoluteEncoderGearing (const gearing::GearBox &gearing)
 
SwerveModuleConfig & WithAbsoluteEncoderOffset (wpi::units::degree_t offset)
 
SwerveModuleConfig & WithLocation (wpi::math::Translation2d location)
 
SwerveModuleConfig & WithLocation (wpi::units::meter_t front, wpi::units::meter_t left)
 
SwerveModuleConfig & WithLocation (wpi::units::meter_t distance, wpi::units::degree_t angle)
 
SwerveModuleConfig & WithWheelRadius (wpi::units::meter_t radius)
 
SwerveModuleConfig & WithWheelDiameter (wpi::units::meter_t diameter)
 
SwerveModuleConfig & WithVelocityDeadband (std::optional< wpi::units::meters_per_second_t > speed)
 
SwerveModuleConfig & WithOptimization (bool enable)
 
SwerveModuleConfig & WithTelemetry (const std::string &name, TelemetryVerbosity verbosity)
 
SwerveModuleConfig & WithTelemetry (const std::string &name, telemetry::SwerveModuleTelemetryConfig telemetryConfig)
 
motorcontrollers::SmartMotorController * GetDriveMotor () const
 
motorcontrollers::SmartMotorController * GetAzimuthMotor () const
 
std::optional< std::string > GetTelemetryName () const
 
std::optional< TelemetryVerbosity > GetTelemetryVerbosity () const
 
std::optional< wpi::math::Translation2d > GetLocation () const
 
bool GetStateOptimization () const
 
wpi::units::degree_t GetAbsoluteEncoderAngle () const
 
std::function< wpi::units::degree_t()> GetRawAbsoluteEncoderAngle () const
 
std::optional< std::function< wpi::units::degree_t()> > GetAbsoluteEncoderSupplier () const
 
std::optional< telemetry::SwerveModuleTelemetryConfig > GetSwerveModuleTelemetryConfig ()
 
wpi::math::SwerveModuleVelocity GetOptimizedState (wpi::math::SwerveModuleVelocity state) const
 
wpi::math::SwerveModuleVelocity GetOptimizedState (wpi::math::SwerveModuleVelocity state, const swerve::SwerveModuleVelocityWithAzimuth &measured) const
 
double GetCosineCompensationScalar (wpi::math::Rotation2d desiredAngle) const
 
std::optional< gearing::GearBox > GetCouplingRatio () const
 
wpi::math::SwerveModuleVelocity GetLockedState (wpi::math::Rotation2d angle) const
 
wpi::math::SwerveModuleVelocity GetLockedState (wpi::math::Rotation2d angle, const swerve::SwerveModuleVelocityWithAzimuth &measured) const
 

Detailed Description

Configuration for a single SwerveModule.

Uses a fluent builder pattern; all With* methods return *this for chaining.

Member Typedef Documentation

◆ TelemetryVerbosity

Constructor & Destructor Documentation

◆ SwerveModuleConfig() [1/2]

yams::mechanisms::config::SwerveModuleConfig::SwerveModuleConfig ( )
default

◆ SwerveModuleConfig() [2/2]

yams::mechanisms::config::SwerveModuleConfig::SwerveModuleConfig ( motorcontrollers::SmartMotorController *  drive,
motorcontrollers::SmartMotorController *  azimuth 
)

Construct with drive and azimuth motor controllers.

Parameters
driveDrive motor controller (must outlive this config).
azimuthAzimuth motor controller (must outlive this config).

Member Function Documentation

◆ GetAbsoluteEncoderAngle()

wpi::units::degree_t yams::mechanisms::config::SwerveModuleConfig::GetAbsoluteEncoderAngle ( ) const

Get the current absolute encoder angle with gearing and offset applied.

Falls back to the azimuth motor's mechanism position if no encoder supplier is set.

Returns
Absolute angle in degrees.

◆ GetAbsoluteEncoderSupplier()

std::optional< std::function< wpi::units::degree_t()> > yams::mechanisms::config::SwerveModuleConfig::GetAbsoluteEncoderSupplier ( ) const

Get the absolute encoder supplier, if configured via WithAbsoluteEncoder().

◆ GetAzimuthMotor()

motorcontrollers::SmartMotorController * yams::mechanisms::config::SwerveModuleConfig::GetAzimuthMotor ( ) const

Get the azimuth motor controller pointer.

◆ GetCosineCompensationScalar()

double yams::mechanisms::config::SwerveModuleConfig::GetCosineCompensationScalar ( wpi::math::Rotation2d  desiredAngle) const

The scale cosine compensation applies to a wheel aimed at the desired angle: the cosine of the azimuth error, and never below zero. It is 1 when cosine compensation is off.

Parameters
desiredAngleAngle the wheel is being sent to.
Returns
Scale from 0 to 1.

◆ GetCouplingRatio()

std::optional< gearing::GearBox > yams::mechanisms::config::SwerveModuleConfig::GetCouplingRatio ( ) const

Get the coupling ratio, if configured via WithCouplingRatio().

◆ GetDriveMotor()

motorcontrollers::SmartMotorController * yams::mechanisms::config::SwerveModuleConfig::GetDriveMotor ( ) const

Get the drive motor controller pointer.

◆ GetLocation()

std::optional< wpi::math::Translation2d > yams::mechanisms::config::SwerveModuleConfig::GetLocation ( ) const

Get the optional module location (Translation2d from centre of rotation).

◆ GetLockedState() [1/2]

wpi::math::SwerveModuleVelocity yams::mechanisms::config::SwerveModuleConfig::GetLockedState ( wpi::math::Rotation2d  angle) const

Get the state that turns the wheel to the given angle without driving it, as for locking the drive in place. Unlike GetOptimizedState(), the velocity deadband does not hold the wheel where it is, since the wheel is meant to turn without driving. With optimization enabled the wheel turns to whichever of the angle and its opposite is nearer, as either holds the drive the same way.

Parameters
angleAngle to turn the wheel to.
Returns
Zero speed state at the angle to turn the wheel to.

◆ GetLockedState() [2/2]

wpi::math::SwerveModuleVelocity yams::mechanisms::config::SwerveModuleConfig::GetLockedState ( wpi::math::Rotation2d  angle,
const swerve::SwerveModuleVelocityWithAzimuth &  measured 
) const

Get the state that turns the wheel to the given angle without driving it, against a measured state.

Parameters
angleAngle to turn the wheel to.
measuredThe module's measured state.
Returns
Zero speed state at the angle to turn the wheel to.

◆ GetOptimizedState() [1/2]

wpi::math::SwerveModuleVelocity yams::mechanisms::config::SwerveModuleConfig::GetOptimizedState ( wpi::math::SwerveModuleVelocity  state) const

Apply all enabled optimizations (velocity deadband, state optimization, cosine compensation) and return the resulting state.

Parameters
stateInput state.
Returns
Optimized state.

◆ GetOptimizedState() [2/2]

wpi::math::SwerveModuleVelocity yams::mechanisms::config::SwerveModuleConfig::GetOptimizedState ( wpi::math::SwerveModuleVelocity  state,
const swerve::SwerveModuleVelocityWithAzimuth &  measured 
) const

Apply all enabled optimizations against a measured state.

Parameters
stateInput state.
measuredThe module's measured state.
Returns
Optimized state.

◆ GetRawAbsoluteEncoderAngle()

std::function< wpi::units::degree_t()> yams::mechanisms::config::SwerveModuleConfig::GetRawAbsoluteEncoderAngle ( ) const

Get the absolute encoder angle as a supplier without offsets applied.

Falls back to the azimuth motor's mechanism position (plus its external encoder zero offset, on a real robot) if no encoder supplier is set.

Returns
Callable returning the absolute encoder angle without offsets.

◆ GetStateOptimization()

bool yams::mechanisms::config::SwerveModuleConfig::GetStateOptimization ( ) const

Returns true if state optimization is enabled.

◆ GetSwerveModuleTelemetryConfig()

std::optional< telemetry::SwerveModuleTelemetryConfig > yams::mechanisms::config::SwerveModuleConfig::GetSwerveModuleTelemetryConfig ( )

Get the user-specified SwerveModuleTelemetryConfig, if configured via WithTelemetry(name, SwerveModuleTelemetryConfig). Moves the config out of this SwerveModuleConfig; intended to be called exactly once, when the owning SwerveModule sets up its telemetry.

Returns
SwerveModuleTelemetryConfig if configured.

◆ GetTelemetryName()

std::optional< std::string > yams::mechanisms::config::SwerveModuleConfig::GetTelemetryName ( ) const

Get the optional telemetry name.

◆ GetTelemetryVerbosity()

std::optional< TelemetryVerbosity > yams::mechanisms::config::SwerveModuleConfig::GetTelemetryVerbosity ( ) const

Get the optional telemetry verbosity.

◆ WithAbsoluteEncoder()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithAbsoluteEncoder ( std::function< wpi::units::degree_t()>  supplier)

Supply an external (cross-vendor) absolute encoder angle in degrees.

Parameters
supplierCallable that returns the current encoder angle.
Returns
*this for chaining.

◆ WithAbsoluteEncoderGearing()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithAbsoluteEncoderGearing ( const gearing::GearBox &  gearing)

Set the gearing between the absolute encoder shaft and the azimuth mechanism.

Parameters
gearingGearBox representing the encoder-to-mechanism ratio.
Returns
*this for chaining.

◆ WithAbsoluteEncoderOffset()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithAbsoluteEncoderOffset ( wpi::units::degree_t  offset)

Set the absolute encoder offset so that zero corresponds to the wheel pointing forward with the bevel gear facing left.

Parameters
offsetOffset angle to subtract from the raw encoder reading.
Returns
*this for chaining.

◆ WithCosineCompensation()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithCosineCompensation ( bool  compensate)

Enable or disable cosine compensation of the drive velocity.

Scales drive speed by cos(angle_error) to reduce skew during steering.

Parameters
compensatetrue to enable.
Returns
*this for chaining.

◆ WithCouplingRatio() [1/2]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithCouplingRatio ( double  driveMotorRotationsPerAzimuthRotation)

Set the coupling ratio as a number. Zero turns it off.

Parameters
driveMotorRotationsPerAzimuthRotationDrive motor rotations per azimuth rotation.
Returns
*this for chaining.

◆ WithCouplingRatio() [2/2]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithCouplingRatio ( std::optional< gearing::GearBox >  couplingRatio)

Set the coupling ratio: how far the drive motor turns when the azimuth turns once with the wheel held still. On most modules turning the azimuth also turns the wheel a little, which shows up as wheel travel that did not happen. With this set, the module takes it out of the wheel's position and velocity, and adds it to the velocity it commands.

Parameters
couplingRatioDrive motor rotations per azimuth rotation, as a gearbox.
Returns
*this for chaining.

◆ WithDistanceFromCenterOfRotation()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithDistanceFromCenterOfRotation ( wpi::units::meter_t  front,
wpi::units::meter_t  left 
)

Set where the module is, measured from the center of rotation. The same as WithLocation.

Parameters
frontDistance toward the front of the robot.
leftDistance toward the left of the robot.
Returns
*this for chaining.

◆ WithExternalAbsoluteEncoder()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithExternalAbsoluteEncoder ( std::any  absoluteEncoder)

Use an absolute encoder object from the azimuth motor controller's own vendor as the azimuth's external encoder, as SmartMotorControllerConfig::WithExternalEncoder does. It replaces a supplier given with WithAbsoluteEncoder, and is applied when the motor controllers are given if they have not been yet.

Parameters
absoluteEncoderThe encoder, such as a pointer to a CANcoder.
Returns
*this for chaining.

◆ WithLocation() [1/3]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithLocation ( wpi::math::Translation2d  location)

Set the module location from the robot center as a Cartesian Translation2d (X = forward, Y = left) in metres.

Parameters
locationLocation of the module.
Returns
*this for chaining.

◆ WithLocation() [2/3]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithLocation ( wpi::units::meter_t  distance,
wpi::units::degree_t  angle 
)

Set the module location via polar coordinates.

Parameters
distanceRadial distance from the centre of rotation.
angleAngular position around the centre of rotation.
Returns
*this for chaining.

◆ WithLocation() [3/3]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithLocation ( wpi::units::meter_t  front,
wpi::units::meter_t  left 
)

Set the module location via separate forward (X) and left (Y) distances.

Parameters
frontDistance forward from the centre of rotation.
leftDistance left from the centre of rotation.
Returns
*this for chaining.

◆ WithOptimization()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithOptimization ( bool  enable)

Enable or disable WPILib SwerveModuleState optimization (flip by 180° to minimise rotation).

Parameters
enabletrue to enable (default is true).
Returns
*this for chaining.

◆ WithSmartMotorController()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithSmartMotorController ( motorcontrollers::SmartMotorController *  driveMotor,
motorcontrollers::SmartMotorController *  azimuthMotor 
)

Set both motor controllers (use when constructed with the default constructor).

Parameters
driveMotorDrive motor controller.
azimuthMotorAzimuth motor controller.
Returns
*this for chaining.

◆ WithTelemetry() [1/2]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithTelemetry ( const std::string &  name,
telemetry::SwerveModuleTelemetryConfig  telemetryConfig 
)

Set the telemetry name for this module and configure telemetry with an explicit SwerveModuleTelemetryConfig, taking precedence over WithTelemetry(name, TelemetryVerbosity).

Parameters
nameNetworkTable key for this module's data.
telemetryConfigConfig that specifies what to log.
Returns
*this for chaining.

◆ WithTelemetry() [2/2]

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithTelemetry ( const std::string &  name,
TelemetryVerbosity  verbosity 
)

Set the telemetry name and verbosity for this module.

Parameters
nameNetworkTable key for this module's data.
verbosityAmount of data to publish.
Returns
*this for chaining.

◆ WithVelocityDeadband()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithVelocityDeadband ( std::optional< wpi::units::meters_per_second_t >  speed)

Velocity deadband: a requested wheel speed at or below it stops the module and holds its current azimuth instead of tracking.

The default is 0.1 m/s. Pass std::nullopt to turn it off.

Parameters
speedVelocity deadband.
Returns
*this for chaining.

◆ WithWheelDiameter()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithWheelDiameter ( wpi::units::meter_t  diameter)

Set the wheel diameter (derives the circumference used for linear-distance conversion).

Parameters
diameterWheel diameter.
Returns
*this for chaining.

◆ WithWheelRadius()

SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithWheelRadius ( wpi::units::meter_t  radius)

Set the wheel radius (derives the circumference used for linear-distance conversion).

Parameters
radiusWheel radius.
Returns
*this for chaining.

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