|
YAMS
Yet Another Mechanism System
|
#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 |
Configuration for a single SwerveModule.
Uses a fluent builder pattern; all With* methods return *this for chaining.
| using yams::mechanisms::config::SwerveModuleConfig::TelemetryVerbosity = motorcontrollers::SmartMotorControllerConfig::TelemetryVerbosity |
|
default |
| yams::mechanisms::config::SwerveModuleConfig::SwerveModuleConfig | ( | motorcontrollers::SmartMotorController * | drive, |
| motorcontrollers::SmartMotorController * | azimuth | ||
| ) |
Construct with drive and azimuth motor controllers.
| drive | Drive motor controller (must outlive this config). |
| azimuth | Azimuth motor controller (must outlive this config). |
| 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.
| std::optional< std::function< wpi::units::degree_t()> > yams::mechanisms::config::SwerveModuleConfig::GetAbsoluteEncoderSupplier | ( | ) | const |
Get the absolute encoder supplier, if configured via WithAbsoluteEncoder().
| motorcontrollers::SmartMotorController * yams::mechanisms::config::SwerveModuleConfig::GetAzimuthMotor | ( | ) | const |
Get the azimuth motor controller pointer.
| 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.
| desiredAngle | Angle the wheel is being sent to. |
| std::optional< gearing::GearBox > yams::mechanisms::config::SwerveModuleConfig::GetCouplingRatio | ( | ) | const |
Get the coupling ratio, if configured via WithCouplingRatio().
| motorcontrollers::SmartMotorController * yams::mechanisms::config::SwerveModuleConfig::GetDriveMotor | ( | ) | const |
Get the drive motor controller pointer.
| std::optional< wpi::math::Translation2d > yams::mechanisms::config::SwerveModuleConfig::GetLocation | ( | ) | const |
Get the optional module location (Translation2d from centre of rotation).
| 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.
| angle | Angle to turn the wheel to. |
| 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.
| angle | Angle to turn the wheel to. |
| measured | The module's measured state. |
| 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.
| state | Input state. |
| 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.
| state | Input state. |
| measured | The module's measured state. |
| 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.
| bool yams::mechanisms::config::SwerveModuleConfig::GetStateOptimization | ( | ) | const |
Returns true if state optimization is enabled.
| 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.
| std::optional< std::string > yams::mechanisms::config::SwerveModuleConfig::GetTelemetryName | ( | ) | const |
Get the optional telemetry name.
| std::optional< TelemetryVerbosity > yams::mechanisms::config::SwerveModuleConfig::GetTelemetryVerbosity | ( | ) | const |
Get the optional telemetry verbosity.
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithAbsoluteEncoder | ( | std::function< wpi::units::degree_t()> | supplier | ) |
Supply an external (cross-vendor) absolute encoder angle in degrees.
| supplier | Callable that returns the current encoder angle. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithAbsoluteEncoderGearing | ( | const gearing::GearBox & | gearing | ) |
Set the gearing between the absolute encoder shaft and the azimuth mechanism.
| gearing | GearBox representing the encoder-to-mechanism ratio. |
| 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.
| offset | Offset angle to subtract from the raw encoder reading. |
| 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.
| compensate | true to enable. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithCouplingRatio | ( | double | driveMotorRotationsPerAzimuthRotation | ) |
Set the coupling ratio as a number. Zero turns it off.
| driveMotorRotationsPerAzimuthRotation | Drive motor rotations per azimuth rotation. |
| 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.
| couplingRatio | Drive motor rotations per azimuth rotation, as a gearbox. |
| 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.
| front | Distance toward the front of the robot. |
| left | Distance toward the left of the robot. |
| 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.
| absoluteEncoder | The encoder, such as a pointer to a CANcoder. |
| 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.
| location | Location of the module. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithLocation | ( | wpi::units::meter_t | distance, |
| wpi::units::degree_t | angle | ||
| ) |
Set the module location via polar coordinates.
| distance | Radial distance from the centre of rotation. |
| angle | Angular position around the centre of rotation. |
| 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.
| front | Distance forward from the centre of rotation. |
| left | Distance left from the centre of rotation. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithOptimization | ( | bool | enable | ) |
Enable or disable WPILib SwerveModuleState optimization (flip by 180° to minimise rotation).
| enable | true to enable (default is true). |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithSmartMotorController | ( | motorcontrollers::SmartMotorController * | driveMotor, |
| motorcontrollers::SmartMotorController * | azimuthMotor | ||
| ) |
Set both motor controllers (use when constructed with the default constructor).
| driveMotor | Drive motor controller. |
| azimuthMotor | Azimuth motor controller. |
| 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).
| name | NetworkTable key for this module's data. |
| telemetryConfig | Config that specifies what to log. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithTelemetry | ( | const std::string & | name, |
| TelemetryVerbosity | verbosity | ||
| ) |
Set the telemetry name and verbosity for this module.
| name | NetworkTable key for this module's data. |
| verbosity | Amount of data to publish. |
| 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.
| speed | Velocity deadband. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithWheelDiameter | ( | wpi::units::meter_t | diameter | ) |
Set the wheel diameter (derives the circumference used for linear-distance conversion).
| diameter | Wheel diameter. |
| SwerveModuleConfig & yams::mechanisms::config::SwerveModuleConfig::WithWheelRadius | ( | wpi::units::meter_t | radius | ) |
Set the wheel radius (derives the circumference used for linear-distance conversion).
| radius | Wheel radius. |