|
YAMS
Yet Another Mechanism System
|
#include <SwerveDriveConfig.hpp>
Public Types | |
| using | TelemetryVerbosity = motorcontrollers::SmartMotorControllerConfig::TelemetryVerbosity |
Public Member Functions | |
| SwerveDriveConfig ()=default | |
| SwerveDriveConfig & | WithSubsystem (wpi::cmd::SubsystemBase *subsystem) |
| SwerveDriveConfig & | WithModules (std::vector< SwerveModule * > modules) |
| SwerveDriveConfig & | WithGyro (std::function< wpi::units::degree_t()> gyroSupplier) |
| SwerveDriveConfig & | WithGyro (std::function< wpi::math::Rotation3d()> gyroSupplier) |
| SwerveDriveConfig & | WithGyroHeadingAxis (config::GyroAxis axis) |
| SwerveDriveConfig & | WithAntiTipping (wpi::units::meters_per_second_t kP, wpi::units::degree_t tippingThreshold, wpi::units::meters_per_second_t maxCorrectionSpeed) |
| SwerveDriveConfig & | WithAntiTipping (std::optional< wpi::math::AntiTipping > antiTipping) |
| SwerveDriveConfig & | WithModuleStateOptimization (bool enabled) |
| SwerveDriveConfig & | WithGyroVelocity (std::function< wpi::units::degrees_per_second_t()> angularVelocitySupplier) |
| SwerveDriveConfig & | WithGyroOffset (wpi::units::degree_t offset) |
| SwerveDriveConfig & | WithGyroInverted (bool inverted) |
| SwerveDriveConfig & | WithStartingPose (wpi::math::Pose2d pose) |
| SwerveDriveConfig & | WithMaximumChassisSpeed (wpi::units::meters_per_second_t speed, wpi::units::degrees_per_second_t angularVelocity) |
| SwerveDriveConfig & | WithMaximumModuleSpeed (wpi::units::meters_per_second_t speed) |
| SwerveDriveConfig & | WithCenterOfRotation (wpi::math::Translation2d center) |
| SwerveDriveConfig & | WithCenterOfRotation (wpi::units::meter_t forward, wpi::units::meter_t left) |
| SwerveDriveConfig & | WithDiscretizationTime (wpi::units::second_t dt) |
| SwerveDriveConfig & | WithSimDiscretizationTime (wpi::units::second_t dt) |
| SwerveDriveConfig & | WithGyroAngularVelocityScaleFactor (double scaleFactor) |
| SwerveDriveConfig & | WithSimGyroAngularVelocityScaleFactor (double scaleFactor) |
| SwerveDriveConfig & | WithTranslationController (wpi::math::PIDController controller) |
| SwerveDriveConfig & | WithRotationController (wpi::math::PIDController controller) |
| SwerveDriveConfig & | WithSimTranslationController (wpi::math::PIDController controller) |
| SwerveDriveConfig & | WithSimRotationController (wpi::math::PIDController controller) |
| SwerveDriveConfig & | WithTelemetry (const std::string &name, TelemetryVerbosity verbosity) |
| SwerveDriveConfig & | WithTelemetry (const std::string &name, telemetry::SwerveDriveTelemetryConfig telemetryConfig) |
| const std::vector< SwerveModule * > & | GetModules () const |
| wpi::cmd::SubsystemBase * | GetSubsystem () const |
| wpi::math::Pose2d | GetInitialPose () const |
| std::optional< wpi::units::meters_per_second_t > | GetMaximumChassisLinearVelocity () const |
| std::optional< wpi::units::degrees_per_second_t > | GetMaximumChassisAngularVelocity () const |
| std::optional< wpi::units::meters_per_second_t > | GetMaximumModuleLinearVelocity () const |
| std::optional< wpi::math::Translation2d > | GetCenterOfRotation () const |
| std::optional< TelemetryVerbosity > | GetTelemetryVerbosity () const |
| const std::string & | GetTelemetryName () const |
| std::optional< telemetry::SwerveDriveTelemetryConfig > | GetSwerveDriveTelemetryConfig () |
| wpi::units::degree_t | GetGyroOffset () const |
| wpi::units::degree_t | GetGyroAngle () const |
| wpi::math::Rotation3d | GetGyroRotation3d () const |
| wpi::math::ChassisVelocities | GetAntiTippingCorrection () const |
| std::optional< bool > | GetModuleStateOptimization () const |
| std::optional< wpi::units::second_t > | GetDiscretization () const |
| wpi::math::ChassisVelocities | OptimizeRobotRelativeChassisSpeeds (wpi::math::ChassisVelocities speeds) const |
| std::optional< std::reference_wrapper< wpi::math::PIDController > > | GetTranslationPID () |
| std::optional< std::reference_wrapper< wpi::math::PIDController > > | GetRotationPID () |
Static Public Member Functions | |
| static wpi::math::Translation2d | CubeTranslation (wpi::math::Translation2d translation) |
| static wpi::math::Translation2d | ScaleTranslation (wpi::math::Translation2d translation, double scalar) |
Configuration for a SwerveDrive.
Uses a fluent builder pattern; all With* methods return *this for chaining.
| using yams::mechanisms::swerve::SwerveDriveConfig::TelemetryVerbosity = motorcontrollers::SmartMotorControllerConfig::TelemetryVerbosity |
|
default |
|
static |
Cube the polar-coordinate magnitude of a Translation2d.
| wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDriveConfig::GetAntiTippingCorrection | ( | ) | const |
The anti-tipping correction for the current attitude, robot relative. Zero when anti-tipping or the gyro is not configured.
| std::optional< wpi::math::Translation2d > yams::mechanisms::swerve::SwerveDriveConfig::GetCenterOfRotation | ( | ) | const |
| std::optional< wpi::units::second_t > yams::mechanisms::swerve::SwerveDriveConfig::GetDiscretization | ( | ) | const |
The discretization time in use: the simulation one in simulation, the real one otherwise.
| wpi::units::degree_t yams::mechanisms::swerve::SwerveDriveConfig::GetGyroAngle | ( | ) | const |
Get the gyro angle with inversion and offset applied.
| std::runtime_error | if no gyro supplier has been configured. |
| wpi::units::degree_t yams::mechanisms::swerve::SwerveDriveConfig::GetGyroOffset | ( | ) | const |
Get the stored gyro offset (zero if never set).
| wpi::math::Rotation3d yams::mechanisms::swerve::SwerveDriveConfig::GetGyroRotation3d | ( | ) | const |
The robot's attitude: the gyro's attitude rotated into the robot's frame (see WithGyroHeadingAxis), with the gyro inversion and offset applied to its yaw. Its yaw is the robot's heading, and its roll and pitch are the robot's tilt.
| std::runtime_error | if no gyro supplier was set with WithGyro. |
| wpi::math::Pose2d yams::mechanisms::swerve::SwerveDriveConfig::GetInitialPose | ( | ) | const |
Get the starting pose.
| std::optional< wpi::units::degrees_per_second_t > yams::mechanisms::swerve::SwerveDriveConfig::GetMaximumChassisAngularVelocity | ( | ) | const |
| std::optional< wpi::units::meters_per_second_t > yams::mechanisms::swerve::SwerveDriveConfig::GetMaximumChassisLinearVelocity | ( | ) | const |
| std::optional< wpi::units::meters_per_second_t > yams::mechanisms::swerve::SwerveDriveConfig::GetMaximumModuleLinearVelocity | ( | ) | const |
| const std::vector< SwerveModule * > & yams::mechanisms::swerve::SwerveDriveConfig::GetModules | ( | ) | const |
Get the vector of module pointers.
| std::optional< bool > yams::mechanisms::swerve::SwerveDriveConfig::GetModuleStateOptimization | ( | ) | const |
The module state optimization setting from WithModuleStateOptimization, if it was set.
| std::optional< std::reference_wrapper< wpi::math::PIDController > > yams::mechanisms::swerve::SwerveDriveConfig::GetRotationPID | ( | ) |
Get the active rotation PID controller used for drive to pose and heading control (sim variant if in simulation and configured).
| wpi::cmd::SubsystemBase * yams::mechanisms::swerve::SwerveDriveConfig::GetSubsystem | ( | ) | const |
Get the subsystem pointer.
| std::optional< telemetry::SwerveDriveTelemetryConfig > yams::mechanisms::swerve::SwerveDriveConfig::GetSwerveDriveTelemetryConfig | ( | ) |
Get the user-specified SwerveDriveTelemetryConfig, if configured via WithTelemetry(name, SwerveDriveTelemetryConfig). Moves the config out of this SwerveDriveConfig; intended to be called exactly once, when the owning SwerveDrive sets up its telemetry.
| const std::string & yams::mechanisms::swerve::SwerveDriveConfig::GetTelemetryName | ( | ) | const |
| std::optional< TelemetryVerbosity > yams::mechanisms::swerve::SwerveDriveConfig::GetTelemetryVerbosity | ( | ) | const |
| std::optional< std::reference_wrapper< wpi::math::PIDController > > yams::mechanisms::swerve::SwerveDriveConfig::GetTranslationPID | ( | ) |
Get the active translation PID controller used for drive to pose (sim variant if in simulation and configured).
| wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDriveConfig::OptimizeRobotRelativeChassisSpeeds | ( | wpi::math::ChassisVelocities | speeds | ) | const |
Apply angular-velocity skew correction and ChassisSpeeds discretization.
| speeds | Raw robot-relative chassis speeds. |
|
static |
Scale the polar-coordinate magnitude of a Translation2d by a scalar.
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithAntiTipping | ( | std::optional< wpi::math::AntiTipping > | antiTipping | ) |
Push back against tipping with your own controller, or std::nullopt to turn it off.
| antiTipping | The anti-tipping controller. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithAntiTipping | ( | wpi::units::meters_per_second_t | kP, |
| wpi::units::degree_t | tippingThreshold, | ||
| wpi::units::meters_per_second_t | maxCorrectionSpeed | ||
| ) |
Push back against tipping: when the robot leans by more than the threshold, a chassis velocity is added in the direction it is leaning, so the drive base moves back under the robot. It needs the gyro's full attitude, from the Rotation3d overload of WithGyro.
| kP | Correction speed per radian of lean. Must be positive. |
| tippingThreshold | Lean beyond which the correction applies. Between 0 and 90 degrees. |
| maxCorrectionSpeed | The largest correction. Must be positive. |
| std::invalid_argument | if a value is out of range. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithCenterOfRotation | ( | wpi::math::Translation2d | center | ) |
Override the chassis centre of rotation (default is the robot centre).
| center | Translation2d in metres (X forward, Y left). |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithCenterOfRotation | ( | wpi::units::meter_t | forward, |
| wpi::units::meter_t | left | ||
| ) |
Override the chassis centre of rotation via forward/left distances.
| forward | Distance forward from the robot centre. |
| left | Distance left from the robot centre. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithDiscretizationTime | ( | wpi::units::second_t | dt | ) |
Set the discretization timestep used to compensate for ChassisSpeeds skew.
| dt | Discretization period (typically one robot loop period). |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyro | ( | std::function< wpi::math::Rotation3d()> | gyroSupplier | ) |
Supply the gyro's full 3D attitude. See WithGyroHeadingAxis for a gyro that is not mounted flat.
| gyroSupplier | Callable returning the gyro's attitude. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyro | ( | std::function< wpi::units::degree_t()> | gyroSupplier | ) |
Supply the gyro's heading in degrees, for a gyro mounted flat.
The attitude is taken to be this yaw with no roll or pitch, so anti-tipping does nothing and WithGyroHeadingAxis has nothing to rotate. Use the Rotation3d overload for either.
| gyroSupplier | Callable returning the current gyro angle. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyroAngularVelocityScaleFactor | ( | double | scaleFactor | ) |
Set the angular velocity scale factor for skew correction on the real robot.
| scaleFactor | Scale applied to the gyro angular velocity [0, 1]. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyroHeadingAxis | ( | config::GyroAxis | axis | ) |
Set which gyro axis points up through the robot, for a gyro mounted on its side. The attitude from WithGyro is rotated into the robot's frame, so GetGyroRotation3d returns the robot's heading as its yaw and the robot's tilt as its roll and pitch.
| axis | The gyro axis that points up. GyroAxis::YAW, the default, is a gyro mounted flat. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyroInverted | ( | bool | inverted | ) |
Invert the gyro direction.
| inverted | true to negate the raw gyro angle. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyroOffset | ( | wpi::units::degree_t | offset | ) |
Set the gyro offset (subtracted from the raw gyro reading in GetGyroAngle).
| offset | Gyro angle offset. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithGyroVelocity | ( | std::function< wpi::units::degrees_per_second_t()> | angularVelocitySupplier | ) |
Supply the gyro angular velocity in degrees per second.
Required for angular-velocity skew correction.
| angularVelocitySupplier | Callable returning the current gyro angular velocity. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithMaximumChassisSpeed | ( | wpi::units::meters_per_second_t | speed, |
| wpi::units::degrees_per_second_t | angularVelocity | ||
| ) |
Set the maximum chassis linear and angular speeds for wheel speed desaturation.
| speed | Maximum chassis linear speed. |
| angularVelocity | Maximum chassis angular speed. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithMaximumModuleSpeed | ( | wpi::units::meters_per_second_t | speed | ) |
Set the maximum module linear speed for wheel speed desaturation.
| speed | Maximum module speed. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithModules | ( | std::vector< SwerveModule * > | modules | ) |
Set the swerve modules (must match the NumModules template argument of SwerveDrive).
| modules | Vector of module pointers (must outlive this config). |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithModuleStateOptimization | ( | bool | enabled | ) |
Turn swerve module state optimization on or off for every module. It is applied to the modules given so far, and to all of them when the SwerveDrive is created.
| enabled | true to optimize module states. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithRotationController | ( | wpi::math::PIDController | controller | ) |
Set the rotation PID controller for DriveToPose (input units: radians).
Continuous input over [-π, π] is enabled automatically.
| controller | PIDController for heading. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithSimDiscretizationTime | ( | wpi::units::second_t | dt | ) |
Set the discretization timestep used during simulation.
Falls back to WithDiscretizationTime if not set.
| dt | Discretization period for simulation. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithSimGyroAngularVelocityScaleFactor | ( | double | scaleFactor | ) |
Set the angular velocity scale factor for skew correction in simulation.
Falls back to WithGyroAngularVelocityScaleFactor if not set.
| scaleFactor | Scale applied to the gyro angular velocity [0, 1]. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithSimRotationController | ( | wpi::math::PIDController | controller | ) |
Set the simulated rotation PID controller for DriveToPose (input units: radians).
Falls back to WithRotationController if not set. Continuous input is enabled automatically.
| controller | PIDController for heading in simulation. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithSimTranslationController | ( | wpi::math::PIDController | controller | ) |
Set the simulated translation PID controller for DriveToPose (input units: metres).
Falls back to WithTranslationController if not set.
| controller | PIDController for X/Y translation in simulation. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithStartingPose | ( | wpi::math::Pose2d | pose | ) |
Set the starting field pose of the robot.
| pose | Starting Pose2d (field-relative, blue-origin). |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithSubsystem | ( | wpi::cmd::SubsystemBase * | subsystem | ) |
Associate a command subsystem with this drive (used for command requirements).
| subsystem | Pointer to the subsystem (must outlive this config). |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithTelemetry | ( | const std::string & | name, |
| telemetry::SwerveDriveTelemetryConfig | telemetryConfig | ||
| ) |
Configure telemetry for the drive with an explicit SwerveDriveTelemetryConfig, taking precedence over WithTelemetry(name, TelemetryVerbosity).
| name | Telemetry name (defaults to "swerve"). |
| telemetryConfig | Config that specifies what to log. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithTelemetry | ( | const std::string & | name, |
| TelemetryVerbosity | verbosity | ||
| ) |
Set the telemetry name and verbosity for the drive.
| name | Telemetry name (defaults to "swerve"). |
| verbosity | Amount of data to publish. |
| SwerveDriveConfig & yams::mechanisms::swerve::SwerveDriveConfig::WithTranslationController | ( | wpi::math::PIDController | controller | ) |
Set the translation PID controller for DriveToPose (input units: metres).
| controller | PIDController for X/Y translation. |