YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
yams::mechanisms::velocity::FlyWheel Class Reference

#include <FlyWheel.hpp>

Inheritance diagram for yams::mechanisms::velocity::FlyWheel:
Collaboration diagram for yams::mechanisms::velocity::FlyWheel:

Public Member Functions

 FlyWheel (config::FlyWheelConfig *config, motorcontrollers::SmartMotorController *smc)
void SimIterate () override
void UpdateTelemetry () override
void VisualizationUpdate () override
std::string GetName () const override
wpi::cmd::Trigger Max () override
wpi::cmd::Trigger Min () override
wpi::units::degrees_per_second_t GetVelocity () const
wpi::cmd::CommandPtr Run (wpi::units::degrees_per_second_t velocity)
wpi::cmd::CommandPtr Run (std::function< wpi::units::degrees_per_second_t()> velocity)
wpi::cmd::CommandPtr Run (wpi::units::meters_per_second_t surfaceSpeed)
wpi::cmd::CommandPtr Run (std::function< wpi::units::meters_per_second_t()> surfaceSpeed)
wpi::cmd::CommandPtr RunTo (wpi::units::degrees_per_second_t velocity, wpi::units::degrees_per_second_t tolerance=wpi::units::degrees_per_second_t{5.0})
wpi::cmd::CommandPtr RunTo (std::function< wpi::units::degrees_per_second_t()> velocity, wpi::units::degrees_per_second_t tolerance=wpi::units::degrees_per_second_t{5.0})
wpi::cmd::CommandPtr RunTo (wpi::units::meters_per_second_t velocity, wpi::units::meters_per_second_t tolerance)
wpi::cmd::CommandPtr RunTo (std::function< wpi::units::meters_per_second_t()> velocity, wpi::units::meters_per_second_t tolerance)
wpi::cmd::Trigger Gte (wpi::units::degrees_per_second_t velocity)
wpi::cmd::Trigger Lte (wpi::units::degrees_per_second_t velocity)
wpi::cmd::Trigger Between (wpi::units::degrees_per_second_t start, wpi::units::degrees_per_second_t end)
wpi::cmd::Trigger IsNear (wpi::units::degrees_per_second_t velocity, wpi::units::degrees_per_second_t within=wpi::units::degrees_per_second_t{5.0}) const
void SetVelocity (wpi::units::degrees_per_second_t velocity)
void SetSurfaceSpeed (wpi::units::meters_per_second_t speed)
void SetMeasurementVelocitySetpoint (wpi::units::meters_per_second_t velocity)
wpi::math::Pose3d GetPose3d () const override
const config::FlyWheelConfig & GetConfig () const
Public Member Functions inherited from yams::mechanisms::velocity::SmartVelocityMechanism
 SmartVelocityMechanism ()
virtual ~SmartVelocityMechanism ()=default
wpi::MechanismLigament2d * GetMechanismLigament ()
wpi::MechanismRoot2d * GetMechanismRoot ()
motorcontrollers::SmartMotorController * GetMotor ()
Public Member Functions inherited from yams::mechanisms::SmartMechanism
 SmartMechanism ()
virtual ~SmartMechanism ()=default
wpi::cmd::CommandPtr Set (double dutycycle)
wpi::cmd::CommandPtr Set (std::function< double()> dutycycle)
wpi::cmd::CommandPtr SetVoltage (wpi::units::volt_t volts)
wpi::cmd::CommandPtr SetVoltage (std::function< wpi::units::volt_t()> volts)
void SetMechanismVelocitySetpoint (wpi::units::turns_per_second_t velocity)
void SetMeasurementVelocitySetpoint (wpi::units::meters_per_second_t velocity)
void SetMechanismPositionSetpoint (wpi::units::turn_t angle)
void SetMeasurementPositionSetpoint (wpi::units::meter_t distance)
void SetVoltageSetpoint (wpi::units::volt_t voltage)
void SetDutyCycleSetpoint (double dutycycle)
motorcontrollers::SmartMotorController * GetMotorController ()
std::optional< wpi::units::turn_t > GetMechanismSetpoint ()
std::optional< wpi::units::meter_t > GetMeasurementSetpoint ()
wpi::Mechanism2d * GetMechanismWindow ()

Additional Inherited Members

Protected Member Functions inherited from yams::mechanisms::SmartMechanism
void PublishMechanismWindow ()
Protected Attributes inherited from yams::mechanisms::velocity::SmartVelocityMechanism
wpi::MechanismRoot2d * m_mechanismRoot {nullptr}
wpi::MechanismLigament2d * m_mechanismLigament {nullptr}
Protected Attributes inherited from yams::mechanisms::SmartMechanism
wpi::cmd::SubsystemBase * m_subsystem {nullptr}
motorcontrollers::SmartMotorController * m_smc {nullptr}
std::optional< wpi::Mechanism2d > m_mechanismWindow

Detailed Description

Smart mechanism implementation for a flywheel (velocity-controlled roller).

Drives a spinning element using a SmartMotorController configured for mechanism-space (degrees/second) closed-loop velocity control. If a roller diameter is provided, surface-speed commands and reads are also supported.

Example usage (inside a subsystem constructor)

using namespace yams::motorcontrollers;
using namespace yams::gearing;
// Declare as subsystem members:
// ctre::phoenix6::hardware::TalonFX m_talon{4};
// std::optional<TalonFXWrapper> m_motor;
// FlyWheelConfig m_flyWheelConfig;
// std::optional<FlyWheel> m_flyWheel;
motorCfg.WithSubsystem(this)
.WithFeedback(100.0, 0.0, 0.0)
.WithZeroPower(Cfg::MotorMode::COAST)
.WithFeedforward(wpi::math::SimpleMotorFeedforward<wpi::units::turns>{
0.0_V,
wpi::units::unit_t<wpi::math::SimpleMotorFeedforward<wpi::units::turns>::kv_unit>{1.0},
wpi::units::unit_t<wpi::math::SimpleMotorFeedforward<wpi::units::turns>::ka_unit>{0.0}})
.WithClosedLoopMode()
.WithTelemetry("ShooterMotor", Cfg::TelemetryVerbosity::HIGH);
m_motor.emplace(m_talon, wpi::math::DCMotor::Falcon500(1), motorCfg);
m_flyWheelConfig.WithRollerDiameter(4.0 * 0.0254_m) // 4-inch roller
.WithTelemetryName("Shooter");
m_flyWheel.emplace(&m_flyWheelConfig, &m_motor.value());
// Run at a fixed angular velocity (~2000 RPM):
m_flyWheel->Run(wpi::units::degrees_per_second_t{12000.0});
// Or run at a surface speed (requires roller diameter):
m_flyWheel->Run(10.0_mps);
static GearBox FromReductionStages(std::initializer_list< double > stages)
Definition MechanismGearing.hpp:19
Definition SmartMotorControllerConfig.hpp:66
SmartMotorControllerConfig & WithTelemetry(const std::string &name, TelemetryVerbosity verbosity=TelemetryVerbosity::HIGH)
SmartMotorControllerConfig & WithMotorInverted(bool inverted)
SmartMotorControllerConfig & WithMotorGearing(const gearing::MechanismGearing &gearing)
SmartMotorControllerConfig & WithSubsystem(wpi::cmd::SubsystemBase *subsystem)
SmartMotorControllerConfig & WithFeedforward(const wpi::math::ArmFeedforward &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithFeedback(double kP, double kI, double kD, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithStatorCurrentLimit(wpi::units::ampere_t limit)
Definition GearBox.hpp:11
Definition FlyWheel.hpp:21
Definition TalonFXSWrapper.hpp:38
Definition ADRCConfig.hpp:20

Constructor & Destructor Documentation

◆ FlyWheel()

yams::mechanisms::velocity::FlyWheel::FlyWheel ( config::FlyWheelConfig * config,
motorcontrollers::SmartMotorController * smc )

Construct a FlyWheel from a FlyWheelConfig and a SmartMotorController.

Parameters
configPointer to the flywheel configuration (must outlive this object).
smcPointer to the motor controller (must outlive this object).

Member Function Documentation

◆ Between()

wpi::cmd::Trigger yams::mechanisms::velocity::FlyWheel::Between ( wpi::units::degrees_per_second_t start,
wpi::units::degrees_per_second_t end )

Trigger that fires while the flywheel angular velocity is between start and end (inclusive).

Parameters
startLower bound.
endUpper bound.
Returns
Trigger for the range condition.

◆ GetConfig()

const config::FlyWheelConfig & yams::mechanisms::velocity::FlyWheel::GetConfig ( ) const

Get the configuration used to construct this flywheel.

Returns
Const reference to the FlyWheelConfig.

◆ GetName()

std::string yams::mechanisms::velocity::FlyWheel::GetName ( ) const
overridevirtual

Get the human-readable name of this flywheel.

Implements yams::mechanisms::SmartMechanism.

◆ GetPose3d()

wpi::math::Pose3d yams::mechanisms::velocity::FlyWheel::GetPose3d ( ) const
overridevirtual

Get the flywheel's pose, for publishing to AdvantageScope as a component of a robot model: where its axle is mounted, as set in its MechanismPositionConfig, turned by the wheel's position about the axis normal to its movement plane.

Returns
The pose of the flywheel, relative to the robot.

Implements yams::mechanisms::SmartMechanism.

◆ GetVelocity()

wpi::units::degrees_per_second_t yams::mechanisms::velocity::FlyWheel::GetVelocity ( ) const

Get the current angular velocity of the flywheel.

Returns
Current mechanism velocity in degrees per second.

◆ Gte()

wpi::cmd::Trigger yams::mechanisms::velocity::FlyWheel::Gte ( wpi::units::degrees_per_second_t velocity)

Trigger that fires while the flywheel angular velocity is >= the given velocity.

Parameters
velocityReference angular velocity.
Returns
Trigger for the >= condition.

◆ IsNear()

wpi::cmd::Trigger yams::mechanisms::velocity::FlyWheel::IsNear ( wpi::units::degrees_per_second_t velocity,
wpi::units::degrees_per_second_t within = wpi::units::degrees_per_second_t{5.0} ) const

Trigger that fires while the flywheel is within tolerance of a velocity.

Parameters
velocityReference angular velocity.
withinTolerance.
Returns
Trigger for the near condition.

◆ Lte()

wpi::cmd::Trigger yams::mechanisms::velocity::FlyWheel::Lte ( wpi::units::degrees_per_second_t velocity)

Trigger that fires while the flywheel angular velocity is <= the given velocity.

Parameters
velocityReference angular velocity.
Returns
Trigger for the <= condition.

◆ Max()

wpi::cmd::Trigger yams::mechanisms::velocity::FlyWheel::Max ( )
overridevirtual

Trigger that becomes true when the flywheel is at or above its maximum configured velocity.

Returns
Trigger for the upper velocity limit.

Implements yams::mechanisms::velocity::SmartVelocityMechanism.

◆ Min()

wpi::cmd::Trigger yams::mechanisms::velocity::FlyWheel::Min ( )
overridevirtual

Trigger that becomes true when the flywheel is at or below its minimum configured velocity (e.g. stalled or reversed).

Returns
Trigger for the lower velocity limit.

Implements yams::mechanisms::velocity::SmartVelocityMechanism.

◆ Run() [1/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::Run ( std::function< wpi::units::degrees_per_second_t()> velocity)

Set the flywheel to the given angular velocity via a supplier.

Parameters
velocitySupplier returning the desired angular velocity each loop.
Returns
CommandPtr that sets the flywheel to the desired speed.

◆ Run() [2/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::Run ( std::function< wpi::units::meters_per_second_t()> surfaceSpeed)

Set the flywheel to the given surface speed via a supplier.

Requires that a roller diameter was provided in the config.

Parameters
surfaceSpeedSupplier returning the desired surface speed each loop.
Returns
CommandPtr that sets the flywheel to the desired surface speed.

◆ Run() [3/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::Run ( wpi::units::degrees_per_second_t velocity)

Set the flywheel to the given angular velocity.

Parameters
velocityFlyWheel angular velocity to go to.
Returns
CommandPtr that sets the flywheel to the desired speed.

◆ Run() [4/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::Run ( wpi::units::meters_per_second_t surfaceSpeed)

Set the flywheel to the given surface speed.

Requires that a roller diameter was provided in the config.

Parameters
surfaceSpeedDesired surface speed in metres per second.
Returns
CommandPtr that sets the flywheel to the desired surface speed.

◆ RunTo() [1/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::RunTo ( std::function< wpi::units::degrees_per_second_t()> velocity,
wpi::units::degrees_per_second_t tolerance = wpi::units::degrees_per_second_t{5.0} )

Run the flywheel to a supplier-provided angular velocity within a tolerance, then end the command.

The supplier is read every loop and sent as the setpoint, so a target that changes while the command runs is followed. The command ends once the mechanism has been within tolerance of the supplier's current value for 0.1 s.

Parameters
velocitySupplier returning the target angular velocity.
toleranceAllowable error.
Returns
CommandPtr that ends once the flywheel is near the target velocity.
Note
Do not use with a default command on the subsystem, as it will override the setting after this ends.

◆ RunTo() [2/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::RunTo ( std::function< wpi::units::meters_per_second_t()> velocity,
wpi::units::meters_per_second_t tolerance )

Run the flywheel to a supplier-provided surface speed within a tolerance, then end the command.

Requires that a roller diameter was provided in the config.

Parameters
velocitySupplier returning the target surface speed.
toleranceAllowable error.
Returns
CommandPtr that ends once the flywheel is near the target surface speed.
Note
Do not use with a default command on the subsystem, as it will override the setting after this ends.

◆ RunTo() [3/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::RunTo ( wpi::units::degrees_per_second_t velocity,
wpi::units::degrees_per_second_t tolerance = wpi::units::degrees_per_second_t{5.0} )

Run the flywheel to an angular velocity within a tolerance, then end the command.

Parameters
velocityTarget angular velocity.
toleranceAllowable error.
Returns
CommandPtr that ends once the flywheel is near the target velocity.
Note
Do not use with a default command on the subsystem, as it will override the setting after this ends.

◆ RunTo() [4/4]

wpi::cmd::CommandPtr yams::mechanisms::velocity::FlyWheel::RunTo ( wpi::units::meters_per_second_t velocity,
wpi::units::meters_per_second_t tolerance )

Run the flywheel to a surface speed within a tolerance, then end the command.

Requires that a roller diameter was provided in the config.

Parameters
velocityTarget surface speed.
toleranceAllowable error.
Returns
CommandPtr that ends once the flywheel is near the target surface speed.
Note
Do not use with a default command on the subsystem, as it will override the setting after this ends.

◆ SetMeasurementVelocitySetpoint()

void yams::mechanisms::velocity::FlyWheel::SetMeasurementVelocitySetpoint ( wpi::units::meters_per_second_t velocity)

Set flywheel velocity from a linear surface speed (base-class override).

Converts the surface speed to angular velocity using the configured roller diameter. Requires roller diameter to be configured; no-op otherwise.

Parameters
velocityDesired surface speed.

◆ SetSurfaceSpeed()

void yams::mechanisms::velocity::FlyWheel::SetSurfaceSpeed ( wpi::units::meters_per_second_t speed)

Directly command the flywheel to a surface speed setpoint (non-command).

Requires roller diameter to be configured; no-op otherwise.

Parameters
speedDesired surface speed.

◆ SetVelocity()

void yams::mechanisms::velocity::FlyWheel::SetVelocity ( wpi::units::degrees_per_second_t velocity)

Directly command the flywheel to an angular velocity setpoint (non-command).

Parameters
velocityDesired angular velocity.

◆ SimIterate()

void yams::mechanisms::velocity::FlyWheel::SimIterate ( )
overridevirtual

Advance the flywheel's simulation by one loop iteration.

Implements yams::mechanisms::SmartMechanism.

◆ UpdateTelemetry()

void yams::mechanisms::velocity::FlyWheel::UpdateTelemetry ( )
overridevirtual

Publish flywheel telemetry to NetworkTables / SmartDashboard.

Implements yams::mechanisms::SmartMechanism.

◆ VisualizationUpdate()

void yams::mechanisms::velocity::FlyWheel::VisualizationUpdate ( )
overridevirtual

Update the Mechanism2d ligament to reflect the current velocity.

Implements yams::mechanisms::SmartMechanism.


The documentation for this class was generated from the following file:
  • /home/runner/work/YAMS/YAMS/yams/cpp/include/yams/mechanisms/velocity/FlyWheel.hpp