YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Public Member Functions | List of all members
yams::mechanisms::swerve::SwerveDrive< NumModules > Class Template Reference

#include <SwerveDrive.hpp>

Public Member Functions

 SwerveDrive (SwerveDriveConfig *config)
 
wpi::cmd::CommandPtr Drive (std::function< wpi::math::ChassisVelocities()> robotRelativeSpeeds)
 
wpi::cmd::CommandPtr DriveToPose (wpi::math::Pose2d pose)
 
wpi::cmd::CommandPtr DriveToPose (wpi::math::Pose2d pose, wpi::units::meter_t translationTolerance, wpi::units::degree_t rotationTolerance)
 
bool IsNear (wpi::math::Pose2d pose, wpi::units::meter_t translationTolerance, wpi::units::degree_t rotationTolerance)
 
void Stop ()
 
wpi::math::ChassisVelocities DriveToPoseSetpoint (wpi::math::Pose2d targetPose)
 
wpi::math::ChassisVelocities DriveToPoseSetpoint (wpi::math::Pose2d targetPose, wpi::math::Pose2d currentPose, wpi::math::Rotation2d heading)
 
void SetSwerveModuleStates (wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > states)
 
void SetSwerveModuleStates (wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > states, std::span< const wpi::units::newton_t > feedforwardForces)
 
wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > GetStateFromRobotRelativeChassisSpeeds (wpi::math::ChassisVelocities robotRelativeSpeeds)
 
wpi::math::ChassisVelocities GetRobotRelativeChassisSpeedsFromState (const wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > &states)
 
void SetRobotRelativeChassisSpeeds (wpi::math::ChassisVelocities robotRelativeSpeeds)
 
void SetRobotRelativeChassisSpeeds (wpi::math::ChassisVelocities robotRelativeSpeeds, std::span< const wpi::units::newton_t > feedforwardForces)
 
void SetFieldRelativeChassisSpeeds (wpi::math::ChassisVelocities fieldRelativeSpeeds)
 
void LockPose ()
 
void SetAzimuthAngles (wpi::math::Rotation2d angle)
 
wpi::math::Pose2d GetPose ()
 
void ResetOdometry (wpi::math::Pose2d pose)
 
void ZeroGyro ()
 
void AddVisionMeasurement (wpi::math::Pose2d robotPose, wpi::units::second_t timestamp)
 
void AddVisionMeasurement (wpi::math::Pose2d robotPose, wpi::units::second_t timestamp, const wpi::util::array< double, 3 > &stdDevs)
 
void UpdateTelemetry ()
 
void SimIterate ()
 
wpi::units::degree_t GetGyroAngle ()
 
wpi::math::Rotation3d GetGyroRotation3d ()
 
void StartDriveToPoseTuning ()
 
void ApplyTuningValues ()
 
wpi::math::Pose2d GetSimPose ()
 
wpi::math::ChassisVelocities GetRobotRelativeSpeed ()
 
wpi::math::ChassisVelocities GetFieldRelativeSpeed ()
 
wpi::util::array< wpi::math::SwerveModulePosition, NumModules > GetModulePositions ()
 
wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > GetModuleStates ()
 
wpi::units::meter_t GetDistanceFromPose (wpi::math::Pose2d pose)
 
wpi::units::degree_t GetAngleDifferenceFromPose (wpi::math::Pose2d pose)
 
std::optional< SwerveModule * > GetModule (const std::string &name)
 
void ResetRotationPID ()
 
void ResetTranslationPID ()
 
void SetRotationPID (wpi::math::PIDController controller)
 
void SetTranslationPID (wpi::math::PIDController controller)
 
void SetVisionMeasurementStdDevs (const wpi::util::array< double, 3 > &stdDevs)
 
std::string GetName () const
 
SwerveDriveConfig & GetConfig ()
 
wpi::math::SwerveDriveKinematics< NumModules > & GetKinematics ()
 
wpi::Field2d & GetField2d ()
 
wpi::math::ChassisVelocities GetDesiredChassisSpeeds ()
 
wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > GetDesiredModuleStates ()
 

Detailed Description

template<size_t NumModules = 4>
class yams::mechanisms::swerve::SwerveDrive< NumModules >

Swerve drive mechanism with pose estimation, telemetry, and simulation support.

Owns the kinematics, pose estimator, and all NT4 struct publishers. Modules are created separately and handed in by pointer via SwerveDriveConfig. Call UpdateTelemetry() every loop and SimIterate() in SimulationPeriodic().

Template Parameters
NumModulesNumber of swerve modules (default 4).

Example usage (inside a four-module subsystem)

using namespace yams::motorcontrollers;
using namespace yams::gearing;
using namespace yams::mechanisms::swerve;
using namespace yams::mechanisms::config;
// Declare as subsystem members:
// ctre::phoenix6::hardware::Pigeon2 m_pigeon{0};
// // Four sets of: TalonFX, TalonFX, CANcoder, optional<TalonFXWrapper> ×2,
// // SwerveModuleConfig, optional<SwerveModule>
// std::optional<SwerveDrive<4>> m_drive;
// --- build modules (front-left shown; repeat for FR, BL, BR) ---
driveCfg.WithSubsystem(this)
.WithMechanismCircumference(wpi::units::meter_t{4.0 * 0.0254 * std::numbers::pi})
.WithFeedback(0.1, 0.0, 0.0)
.WithMotorGearing(MechanismGearing{GearBox::FromStages({"6.75:1"})})
.WithStatorCurrentLimit(40.0_A)
.WithZeroPower(Cfg::MotorMode::BRAKE)
.WithTelemetry("FL_Drive", Cfg::TelemetryVerbosity::HIGH);
azimuthCfg.WithSubsystem(this)
.WithFeedback(50.0, 0.0, 0.5)
.WithMotorGearing(MechanismGearing{GearBox::FromStages({"21.43:1"})})
.WithStatorCurrentLimit(20.0_A)
.WithTelemetry("FL_Azimuth", Cfg::TelemetryVerbosity::HIGH);
m_flDriveSMC.emplace(m_flDrive, wpi::math::DCMotor::KrakenX60(1), driveCfg);
m_flAzimuthSMC.emplace(m_flAzimuth, wpi::math::DCMotor::KrakenX60(1), azimuthCfg);
auto* enc = &m_flEncoder;
SwerveModuleConfig flCfg{&m_flDriveSMC.value(), &m_flAzimuthSMC.value()};
flCfg.WithAbsoluteEncoder([enc]() -> wpi::units::degree_t {
return wpi::units::degree_t{wpi::units::turn_t{enc->GetAbsolutePosition().GetValue()}};
})
.WithAbsoluteEncoderOffset(15.0_deg)
.WithWheelDiameter(4.0 * 0.0254_m)
.WithLocation(wpi::units::inch_t{12}, wpi::units::inch_t{12})
.WithOptimization(true)
.WithTelemetry("FrontLeft", Cfg::TelemetryVerbosity::HIGH);
m_fl.emplace(flCfg);
// ... repeat for m_fr, m_bl, m_br ...
// --- build the drive ---
driveCfg.WithSubsystem(this)
.WithModules({&m_fl.value(), &m_fr.value(), &m_bl.value(), &m_br.value()})
.WithGyro([this]() -> wpi::units::degree_t {
return wpi::units::degree_t{wpi::units::turn_t{m_pigeon.GetYaw().GetValue()}};
})
.WithMaximumChassisSpeed(4.5_mps, wpi::units::degrees_per_second_t{540})
.WithDiscretizationTime(0.02_s)
.WithStartingPose(wpi::math::Pose2d{})
.WithTranslationController(wpi::math::PIDController{2.0, 0.0, 0.0})
.WithRotationController(wpi::math::PIDController{4.0, 0.0, 0.0});
m_drive.emplace(&m_driveConfig);
// --- in Periodic() ---
// m_drive->UpdateTelemetry();
// --- in SimulationPeriodic() ---
// m_drive->SimIterate();
// --- drive with a joystick ---
// wpi::cmd::CommandPtr driveCmd = m_drive->Drive([this]() -> wpi::math::ChassisVelocities {
// return wpi::math::ChassisVelocities{xSpeed, ySpeed, rotSpeed};
// });
Definition MechanismGearing.hpp:19
Definition SwerveModuleConfig.hpp:30
SwerveModuleConfig & WithAbsoluteEncoder(std::function< wpi::units::degree_t()> supplier)
SwerveModuleConfig & WithTelemetry(const std::string &name, TelemetryVerbosity verbosity)
SwerveModuleConfig & WithLocation(wpi::math::Translation2d location)
SwerveModuleConfig & WithWheelDiameter(wpi::units::meter_t diameter)
Definition SwerveDriveConfig.hpp:38
SwerveDriveConfig & WithModules(std::vector< SwerveModule * > modules)
SwerveDriveConfig & WithStartingPose(wpi::math::Pose2d pose)
SwerveDriveConfig & WithSubsystem(wpi::cmd::SubsystemBase *subsystem)
Definition SmartMotorControllerConfig.hpp:65
SmartMotorControllerConfig & WithTelemetry(const std::string &name, TelemetryVerbosity verbosity=TelemetryVerbosity::HIGH)
SmartMotorControllerConfig & WithZeroPower(MotorMode mode)
SmartMotorControllerConfig & WithClosedLoopMode()
SmartMotorControllerConfig & WithMotorGearing(const gearing::MechanismGearing &gearing)
SmartMotorControllerConfig & WithSubsystem(wpi::cmd::SubsystemBase *subsystem)
SmartMotorControllerConfig & WithFeedback(double kP, double kI, double kD, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithMechanismCircumference(wpi::units::meter_t circumference)
Definition GearBox.hpp:11
Definition ArmConfig.hpp:17
Definition SwerveDrive.hpp:49
Definition TalonFXSWrapper.hpp:38
Definition SimSensorConfig.hpp:15

Constructor & Destructor Documentation

◆ SwerveDrive()

template<size_t NumModules = 4>
yams::mechanisms::swerve::SwerveDrive< NumModules >::SwerveDrive ( SwerveDriveConfig *  config)
inlineexplicit

Construct a SwerveDrive.

Parameters
configDrive configuration. config.GetModules().size() must equal NumModules.

Member Function Documentation

◆ AddVisionMeasurement() [1/2]

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::AddVisionMeasurement ( wpi::math::Pose2d  robotPose,
wpi::units::second_t  timestamp 
)
inline

Add a vision measurement to the pose estimator.

Parameters
robotPoseMeasured field-relative pose from vision.
timestampFPGA timestamp of the measurement (seconds).

◆ AddVisionMeasurement() [2/2]

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::AddVisionMeasurement ( wpi::math::Pose2d  robotPose,
wpi::units::second_t  timestamp,
const wpi::util::array< double, 3 > &  stdDevs 
)
inline

Add a vision measurement with custom standard deviations.

Parameters
robotPoseMeasured field-relative pose from vision.
timestampFPGA timestamp of the measurement (seconds).
stdDevsStandard deviations {x_m, y_m, theta_rad}.

◆ ApplyTuningValues()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::ApplyTuningValues ( )
inline

Apply the live tuning values from NetworkTables, as the tuning command does each loop.

◆ Drive()

template<size_t NumModules = 4>
wpi::cmd::CommandPtr yams::mechanisms::swerve::SwerveDrive< NumModules >::Drive ( std::function< wpi::math::ChassisVelocities()>  robotRelativeSpeeds)
inline

Create a run command that continuously drives with robot-relative chassis speeds.

Parameters
robotRelativeSpeedsCallable returning the desired ChassisSpeeds.
Returns
RunCommand requiring the configured subsystem.

◆ DriveToPose() [1/2]

template<size_t NumModules = 4>
wpi::cmd::CommandPtr yams::mechanisms::swerve::SwerveDrive< NumModules >::DriveToPose ( wpi::math::Pose2d  pose)
inline

Create a command that drives the robot to a target field-relative pose using PID. It keeps driving to the pose until it is interrupted, and stops the drive when it ends.

Requires translation and rotation PID controllers to be configured.

Parameters
poseTarget field-relative pose.
Returns
Command requiring the configured subsystem.

◆ DriveToPose() [2/2]

template<size_t NumModules = 4>
wpi::cmd::CommandPtr yams::mechanisms::swerve::SwerveDrive< NumModules >::DriveToPose ( wpi::math::Pose2d  pose,
wpi::units::meter_t  translationTolerance,
wpi::units::degree_t  rotationTolerance 
)
inline

Create a command that drives the robot to a target field-relative pose using PID, ending once the robot is within the given tolerances. The drive is stopped when the command ends or is interrupted.

Requires translation and rotation PID controllers to be configured.

Parameters
poseTarget field-relative pose.
translationToleranceMaximum distance from the pose to be considered at the pose.
rotationToleranceMaximum heading error from the pose to be considered at the pose.
Returns
Command requiring the configured subsystem.

◆ DriveToPoseSetpoint() [1/2]

template<size_t NumModules = 4>
wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDrive< NumModules >::DriveToPoseSetpoint ( wpi::math::Pose2d  targetPose)
inline

Drive to the target pose, primarily for use in Live Tuning; could also be used for setpoint commands.

Parameters
targetPosePose to drive towards.
Returns
robot-relative ChassisSpeeds to drive the robot to the given pose.
Note
Remember to call ResetTranslationPID() and ResetRotationPID() before calling this method in a loop.
Exceptions
SwerveDriveConfigurationExceptionif the translation or rotation PID controller is not configured.

◆ DriveToPoseSetpoint() [2/2]

template<size_t NumModules = 4>
wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDrive< NumModules >::DriveToPoseSetpoint ( wpi::math::Pose2d  targetPose,
wpi::math::Pose2d  currentPose,
wpi::math::Rotation2d  heading 
)
inline

Robot-relative chassis speeds that drive from a given pose to the target pose, for callers that have their own pose or heading, such as a simulated ground truth.

Parameters
targetPosePose to drive towards.
currentPosePose the robot is at.
headingHeading used to turn the field-relative speeds into robot-relative ones.
Returns
robot-relative ChassisSpeeds to drive the robot to the given pose.
Exceptions
SwerveDriveConfigurationExceptionif the translation or rotation PID controller is not configured.

◆ GetAngleDifferenceFromPose()

template<size_t NumModules = 4>
wpi::units::degree_t yams::mechanisms::swerve::SwerveDrive< NumModules >::GetAngleDifferenceFromPose ( wpi::math::Pose2d  pose)
inline

Get the heading difference from the robot's current rotation to the given pose.

Parameters
poseTarget pose.
Returns
Heading difference in degrees.

◆ GetConfig()

template<size_t NumModules = 4>
SwerveDriveConfig & yams::mechanisms::swerve::SwerveDrive< NumModules >::GetConfig ( )
inline

Get a mutable reference to the drive configuration.

◆ GetDesiredChassisSpeeds()

template<size_t NumModules = 4>
wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDrive< NumModules >::GetDesiredChassisSpeeds ( )
inline

Get the last-commanded desired robot-relative chassis speeds. This is the value cached by SetRobotRelativeChassisSpeeds() (which SetFieldRelativeChassisSpeeds() and Drive() funnel through) and published on every UpdateTelemetry() call; it is a setpoint, not a measurement of actual robot motion. Use GetRobotRelativeSpeed() or GetFieldRelativeSpeed() instead if you need the drive's actual measured speed.

Returns
Robot-relative chassis speeds last commanded to the drive. Defaults to a zeroed wpi::math::ChassisVelocities if the drive has never been commanded.

◆ GetDesiredModuleStates()

template<size_t NumModules = 4>
wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > yams::mechanisms::swerve::SwerveDrive< NumModules >::GetDesiredModuleStates ( )
inline

Get the last-commanded desired module states of the drive.

Returns
Module states last commanded to the drive. Defaults to a zeroed set of module states if the drive has never been commanded.

◆ GetDistanceFromPose()

template<size_t NumModules = 4>
wpi::units::meter_t yams::mechanisms::swerve::SwerveDrive< NumModules >::GetDistanceFromPose ( wpi::math::Pose2d  pose)
inline

Get the Euclidean distance from the robot's current pose to the given pose.

Parameters
poseTarget pose.
Returns
Distance in metres.

◆ GetField2d()

template<size_t NumModules = 4>
wpi::Field2d & yams::mechanisms::swerve::SwerveDrive< NumModules >::GetField2d ( )
inline

Get the Field2d used to display the robot's pose, so callers (e.g. vision subsystems) can publish additional objects onto the same field widget instead of creating their own.

◆ GetFieldRelativeSpeed()

template<size_t NumModules = 4>
wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDrive< NumModules >::GetFieldRelativeSpeed ( )
inline

Get the field-relative chassis speeds derived from the module states and gyro.

◆ GetGyroAngle()

template<size_t NumModules = 4>
wpi::units::degree_t yams::mechanisms::swerve::SwerveDrive< NumModules >::GetGyroAngle ( )
inline

Get the current gyro angle.

Returns the simulated angle in simulation, or the real gyro angle on hardware.

◆ GetGyroRotation3d()

template<size_t NumModules = 4>
wpi::math::Rotation3d yams::mechanisms::swerve::SwerveDrive< NumModules >::GetGyroRotation3d ( )
inline

The robot's attitude. Its yaw is the robot's heading, and its roll and pitch are the robot's tilt. In simulation it is the simulated heading with no tilt.

Returns
The robot's attitude.

◆ GetKinematics()

template<size_t NumModules = 4>
wpi::math::SwerveDriveKinematics< NumModules > & yams::mechanisms::swerve::SwerveDrive< NumModules >::GetKinematics ( )
inline

Get the SwerveDriveKinematics object.

◆ GetModule()

template<size_t NumModules = 4>
std::optional< SwerveModule * > yams::mechanisms::swerve::SwerveDrive< NumModules >::GetModule ( const std::string &  name)
inline

Find a module by name.

Parameters
nameTelemetry name of the module.
Returns
Pointer to the module if found, or empty optional.

◆ GetModulePositions()

template<size_t NumModules = 4>
wpi::util::array< wpi::math::SwerveModulePosition, NumModules > yams::mechanisms::swerve::SwerveDrive< NumModules >::GetModulePositions ( )
inline

Get the current module positions (distance + angle).

◆ GetModuleStates()

template<size_t NumModules = 4>
wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > yams::mechanisms::swerve::SwerveDrive< NumModules >::GetModuleStates ( )
inline

Get the current module states (speed + angle).

◆ GetName()

template<size_t NumModules = 4>
std::string yams::mechanisms::swerve::SwerveDrive< NumModules >::GetName ( ) const
inline

Get the drive's telemetry name (from SwerveDriveConfig, defaults to "swerve").

◆ GetPose()

template<size_t NumModules = 4>
wpi::math::Pose2d yams::mechanisms::swerve::SwerveDrive< NumModules >::GetPose ( )
inline

Get the current estimated field-relative pose.

◆ GetRobotRelativeChassisSpeedsFromState()

template<size_t NumModules = 4>
wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDrive< NumModules >::GetRobotRelativeChassisSpeedsFromState ( const wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > &  states)
inline

Convert module states back to robot-relative chassis speeds.

Parameters
statesModule states (one per module, clockwise from front-left).
Returns
Robot-relative chassis speeds corresponding to the given states.

◆ GetRobotRelativeSpeed()

template<size_t NumModules = 4>
wpi::math::ChassisVelocities yams::mechanisms::swerve::SwerveDrive< NumModules >::GetRobotRelativeSpeed ( )
inline

Get the robot-relative chassis speeds derived from the module states.

◆ GetSimPose()

template<size_t NumModules = 4>
wpi::math::Pose2d yams::mechanisms::swerve::SwerveDrive< NumModules >::GetSimPose ( )
inline

Get the simulated pose of the robot, assuming the commanded module states are met perfectly. Useful for feeding a simulated vision system with ground-truth poses under perfect-world conditions.

Only updated in simulation by SimIterate(); on a real robot this remains the configured starting pose.

◆ GetStateFromRobotRelativeChassisSpeeds()

template<size_t NumModules = 4>
wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules > yams::mechanisms::swerve::SwerveDrive< NumModules >::GetStateFromRobotRelativeChassisSpeeds ( wpi::math::ChassisVelocities  robotRelativeSpeeds)
inline

Convert robot-relative chassis speeds to module states (with optional optimisation).

Parameters
robotRelativeSpeedsInput chassis speeds.
Returns
Corresponding module states.

◆ IsNear()

template<size_t NumModules = 4>
bool yams::mechanisms::swerve::SwerveDrive< NumModules >::IsNear ( wpi::math::Pose2d  pose,
wpi::units::meter_t  translationTolerance,
wpi::units::degree_t  rotationTolerance 
)
inline

Whether the robot is within the given tolerances of a pose.

Parameters
posePose to compare against.
translationToleranceMaximum distance from the pose.
rotationToleranceMaximum heading error from the pose.
Returns
True if the robot is within both tolerances of the pose.

◆ LockPose()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::LockPose ( )
inline

Lock all modules to an X-pattern to resist being pushed.

◆ ResetOdometry()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::ResetOdometry ( wpi::math::Pose2d  pose)
inline

Reset odometry to the given pose, and set the gyro to read the pose's heading. Field relative driving and heading control use the gyro, so keeping it aligned with the pose makes them agree with the reset pose.

Parameters
poseNew field-relative pose (blue-origin, 0° facing red alliance wall).

◆ ResetRotationPID()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::ResetRotationPID ( )
inline

Reset the auto-align rotational PID controller, if one is configured.

◆ ResetTranslationPID()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::ResetTranslationPID ( )
inline

Reset the auto-align translation PID controller, if one is configured.

◆ SetAzimuthAngles()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetAzimuthAngles ( wpi::math::Rotation2d  angle)
inline

Turn every module to the given angle without driving, as for tuning the azimuth motors. The velocity deadband does not hold the wheels where they are (see SwerveModule::SetAzimuthAngle()).

Parameters
angleAngle to turn every module to.

◆ SetFieldRelativeChassisSpeeds()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetFieldRelativeChassisSpeeds ( wpi::math::ChassisVelocities  fieldRelativeSpeeds)
inline

Set field-relative chassis speeds.

Parameters
fieldRelativeSpeedsDesired field-relative chassis speeds.

◆ SetRobotRelativeChassisSpeeds() [1/2]

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetRobotRelativeChassisSpeeds ( wpi::math::ChassisVelocities  robotRelativeSpeeds)
inline

Set robot-relative chassis speeds.

Parameters
robotRelativeSpeedsDesired robot-relative chassis speeds.

◆ SetRobotRelativeChassisSpeeds() [2/2]

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetRobotRelativeChassisSpeeds ( wpi::math::ChassisVelocities  robotRelativeSpeeds,
std::span< const wpi::units::newton_t >  feedforwardForces 
)
inline

Drive at robot relative chassis speeds with a feedforward force on each drive wheel, as a trajectory follower supplies.

Parameters
robotRelativeSpeedsRobot relative chassis speeds.
feedforwardForcesEmpty, or one force per module in the order the modules were given.
Exceptions
std::invalid_argumentif the number of forces is not zero or the number of modules.

◆ SetRotationPID()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetRotationPID ( wpi::math::PIDController  controller)
inline

Set the auto-align rotational PID controller.

Parameters
controllerPIDController to use, input units are radians.

◆ SetSwerveModuleStates() [1/2]

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetSwerveModuleStates ( wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules >  states)
inline

Directly command the swerve modules to the given states.

Parameters
statesArray of states (one per module, clockwise from front-left).

◆ SetSwerveModuleStates() [2/2]

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetSwerveModuleStates ( wpi::util::array< wpi::math::SwerveModuleVelocity, NumModules >  states,
std::span< const wpi::units::newton_t >  feedforwardForces 
)
inline

Set the swerve module states with a feedforward force on each drive wheel.

Parameters
statesModule states, in the order the modules were given.
feedforwardForcesForce for each module, in the same order.

◆ SetTranslationPID()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetTranslationPID ( wpi::math::PIDController  controller)
inline

Set the auto-align translation PID controller.

Parameters
controllerPIDController to use, input units are metres.

◆ SetVisionMeasurementStdDevs()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SetVisionMeasurementStdDevs ( const wpi::util::array< double, 3 > &  stdDevs)
inline

Set the standard deviations used for the vision pose estimator noise model.

Parameters
stdDevsStandard deviations {x_m, y_m, theta_rad}.

◆ SimIterate()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::SimIterate ( )
inline

Advance the simulation model.

Iterates each module's sim model, integrates the simulated ground-truth pose from the commanded (desired) module states assuming they are met perfectly, and integrates the simulated gyro angle from the measured chassis angular velocity.

◆ StartDriveToPoseTuning()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::StartDriveToPoseTuning ( )
inline

Reset the drive to pose controllers, as at the start of a drive to pose tuning run.

◆ Stop()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::Stop ( )
inline

Stop the drive by commanding zero chassis speeds.

◆ UpdateTelemetry()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::UpdateTelemetry ( )
inline

Update the pose estimator and publish all telemetry to NetworkTables.

Call this once per robot loop.

◆ ZeroGyro()

template<size_t NumModules = 4>
void yams::mechanisms::swerve::SwerveDrive< NumModules >::ZeroGyro ( )
inline

Zero the gyro and reset odometry to the current translation with 0° heading.


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