|
YAMS
Yet Another Mechanism System
|
#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 () |
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().
| NumModules | Number of swerve modules (default 4). |
|
inlineexplicit |
Construct a SwerveDrive.
| config | Drive configuration. config.GetModules().size() must equal NumModules. |
|
inline |
Add a vision measurement to the pose estimator.
| robotPose | Measured field-relative pose from vision. |
| timestamp | FPGA timestamp of the measurement (seconds). |
|
inline |
Add a vision measurement with custom standard deviations.
| robotPose | Measured field-relative pose from vision. |
| timestamp | FPGA timestamp of the measurement (seconds). |
| stdDevs | Standard deviations {x_m, y_m, theta_rad}. |
|
inline |
Apply the live tuning values from NetworkTables, as the tuning command does each loop.
|
inline |
Create a run command that continuously drives with robot-relative chassis speeds.
| robotRelativeSpeeds | Callable returning the desired ChassisSpeeds. |
|
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.
| pose | Target field-relative pose. |
|
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.
| pose | Target field-relative pose. |
| translationTolerance | Maximum distance from the pose to be considered at the pose. |
| rotationTolerance | Maximum heading error from the pose to be considered at the pose. |
|
inline |
Drive to the target pose, primarily for use in Live Tuning; could also be used for setpoint commands.
| targetPose | Pose to drive towards. |
| SwerveDriveConfigurationException | if the translation or rotation PID controller is not configured. |
|
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.
| targetPose | Pose to drive towards. |
| currentPose | Pose the robot is at. |
| heading | Heading used to turn the field-relative speeds into robot-relative ones. |
| SwerveDriveConfigurationException | if the translation or rotation PID controller is not configured. |
|
inline |
Get the heading difference from the robot's current rotation to the given pose.
| pose | Target pose. |
|
inline |
Get a mutable reference to the drive configuration.
|
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.
|
inline |
Get the last-commanded desired module states of the drive.
|
inline |
Get the Euclidean distance from the robot's current pose to the given pose.
| pose | Target pose. |
|
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.
|
inline |
Get the field-relative chassis speeds derived from the module states and gyro.
|
inline |
Get the current gyro angle.
Returns the simulated angle in simulation, or the real gyro angle on hardware.
|
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.
|
inline |
Get the SwerveDriveKinematics object.
|
inline |
Find a module by name.
| name | Telemetry name of the module. |
|
inline |
Get the current module positions (distance + angle).
|
inline |
Get the current module states (speed + angle).
|
inline |
Get the drive's telemetry name (from SwerveDriveConfig, defaults to "swerve").
|
inline |
Get the current estimated field-relative pose.
|
inline |
Convert module states back to robot-relative chassis speeds.
| states | Module states (one per module, clockwise from front-left). |
|
inline |
Get the robot-relative chassis speeds derived from the module states.
|
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.
|
inline |
Convert robot-relative chassis speeds to module states (with optional optimisation).
| robotRelativeSpeeds | Input chassis speeds. |
|
inline |
Whether the robot is within the given tolerances of a pose.
| pose | Pose to compare against. |
| translationTolerance | Maximum distance from the pose. |
| rotationTolerance | Maximum heading error from the pose. |
|
inline |
Lock all modules to an X-pattern to resist being pushed.
|
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.
| pose | New field-relative pose (blue-origin, 0° facing red alliance wall). |
|
inline |
Reset the auto-align rotational PID controller, if one is configured.
|
inline |
Reset the auto-align translation PID controller, if one is configured.
|
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()).
| angle | Angle to turn every module to. |
|
inline |
Set field-relative chassis speeds.
| fieldRelativeSpeeds | Desired field-relative chassis speeds. |
|
inline |
Set robot-relative chassis speeds.
| robotRelativeSpeeds | Desired robot-relative chassis speeds. |
|
inline |
Drive at robot relative chassis speeds with a feedforward force on each drive wheel, as a trajectory follower supplies.
| robotRelativeSpeeds | Robot relative chassis speeds. |
| feedforwardForces | Empty, or one force per module in the order the modules were given. |
| std::invalid_argument | if the number of forces is not zero or the number of modules. |
|
inline |
Set the auto-align rotational PID controller.
| controller | PIDController to use, input units are radians. |
|
inline |
Directly command the swerve modules to the given states.
| states | Array of states (one per module, clockwise from front-left). |
|
inline |
Set the swerve module states with a feedforward force on each drive wheel.
| states | Module states, in the order the modules were given. |
| feedforwardForces | Force for each module, in the same order. |
|
inline |
Set the auto-align translation PID controller.
| controller | PIDController to use, input units are metres. |
|
inline |
Set the standard deviations used for the vision pose estimator noise model.
| stdDevs | Standard deviations {x_m, y_m, theta_rad}. |
|
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.
|
inline |
Reset the drive to pose controllers, as at the start of a drive to pose tuning run.
|
inline |
Stop the drive by commanding zero chassis speeds.
|
inline |
Update the pose estimator and publish all telemetry to NetworkTables.
Call this once per robot loop.
|
inline |
Zero the gyro and reset odometry to the current translation with 0° heading.