YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Public Member Functions | List of all members
yams::mechanisms::positional::Pivot Class Reference

#include <Pivot.hpp>

Inheritance diagram for yams::mechanisms::positional::Pivot:
Inheritance graph
[legend]
Collaboration diagram for yams::mechanisms::positional::Pivot:
Collaboration graph
[legend]

Public Member Functions

 Pivot (config::PivotConfig *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::cmd::CommandPtr Run (wpi::units::degree_t angle)
 
wpi::cmd::CommandPtr Run (std::function< wpi::units::degree_t()> angle)
 
wpi::cmd::CommandPtr RunTo (wpi::units::degree_t angle, wpi::units::degree_t tolerance=wpi::units::degree_t{1.0})
 
wpi::cmd::CommandPtr RunTo (std::function< wpi::units::degree_t()> angle, wpi::units::degree_t tolerance=wpi::units::degree_t{1.0})
 
wpi::units::degree_t GetAngle () const
 
wpi::cmd::Trigger Gte (wpi::units::degree_t angle)
 
wpi::cmd::Trigger Lte (wpi::units::degree_t angle)
 
wpi::cmd::Trigger Between (wpi::units::degree_t start, wpi::units::degree_t end)
 
wpi::cmd::Trigger IsNear (wpi::units::degree_t angle, wpi::units::degree_t within=wpi::units::degree_t{1.0})
 
const config::PivotConfig & GetConfig () const
 
wpi::math::Pose3d GetPose3d () const override
 
void SetAngle (wpi::units::degree_t angle)
 
- Public Member Functions inherited from yams::mechanisms::positional::SmartPositionalMechanism
 SmartPositionalMechanism ()
 
virtual ~SmartPositionalMechanism ()=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 Attributes inherited from yams::mechanisms::positional::SmartPositionalMechanism
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 pivot joint.

Similar to an Arm but intended for mechanisms that rotate a fixed-length assembly (e.g. a shooter hood or wrist) rather than a cantilevered arm with a meaningful length. Uses mechanism-space (degree) closed-loop control.

Example usage (inside a subsystem constructor)

using namespace yams::motorcontrollers;
using namespace yams::gearing;
// Declare as subsystem members:
// ctre::phoenix6::hardware::TalonFXS m_talonFXS{3};
// std::optional<TalonFXSWrapper> m_smc;
// PivotConfig m_pivotConfig;
// std::optional<Pivot> m_pivot;
motorCfg.WithSubsystem(this)
.WithFeedback(4.0, 0.0, 0.0)
.WithTrapezoidProfile(wpi::units::turns_per_second_t{0.5},
wpi::units::turns_per_second_squared_t{0.25})
.WithMotorGearing(MechanismGearing{GearBox::FromReductionStages({3.0, 4.0})})
.WithZeroPower(Cfg::MotorMode::BRAKE)
.WithFeedforward(wpi::math::ArmFeedforward{
0.0_V, 0.0_V, wpi::units::unit_t<wpi::math::ArmFeedforward::kv_unit>{0.0},
wpi::units::unit_t<wpi::math::ArmFeedforward::ka_unit>{0.0}})
.WithClosedLoopMode()
.WithTelemetry("HoodMotor", Cfg::TelemetryVerbosity::HIGH);
m_smc.emplace(m_talonFXS, wpi::math::DCMotor::NEO(1),
TalonFXSWrapper::MotorArrangement::NEO, motorCfg);
m_pivotConfig.WithMinAngle(-100.0_deg)
.WithMaxAngle(200.0_deg)
.WithTelemetryName("HoodExample");
m_pivot.emplace(&m_pivotConfig, &m_smc.value());
// In commands or bindings:
m_pivot->RunTo(30.0_deg);
Definition MechanismGearing.hpp:19
motorcontrollers::SmartMotorController * m_smc
Definition SmartMechanism.hpp:153
PivotConfig & WithMaxAngle(wpi::units::degree_t angle)
PivotConfig & WithTelemetryName(const std::string &name)
PivotConfig & WithMinAngle(wpi::units::degree_t angle)
Definition SmartMotorControllerConfig.hpp:65
SmartMotorControllerConfig & WithTelemetry(const std::string &name, TelemetryVerbosity verbosity=TelemetryVerbosity::HIGH)
SmartMotorControllerConfig & WithTrapezoidProfile(wpi::units::turns_per_second_t maxVelocity, wpi::units::turns_per_second_squared_t maxAcceleration)
SmartMotorControllerConfig & WithMotorInverted(bool inverted)
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 Arm.hpp:19
Definition TalonFXSWrapper.hpp:38
Definition SimSensorConfig.hpp:15

Constructor & Destructor Documentation

◆ Pivot()

yams::mechanisms::positional::Pivot::Pivot ( config::PivotConfig *  config,
motorcontrollers::SmartMotorController *  smc 
)

Construct a Pivot from a PivotConfig and a SmartMotorController.

Parameters
configPointer to the pivot configuration (must outlive this Pivot).
smcPointer to the motor controller (must outlive this Pivot).

Member Function Documentation

◆ Between()

wpi::cmd::Trigger yams::mechanisms::positional::Pivot::Between ( wpi::units::degree_t  start,
wpi::units::degree_t  end 
)

Trigger that fires while the pivot angle is between start and end (inclusive).

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

◆ GetAngle()

wpi::units::degree_t yams::mechanisms::positional::Pivot::GetAngle ( ) const

Get the current pivot angle from the motor encoder.

Returns
Current mechanism angle in degrees.

◆ GetConfig()

const config::PivotConfig & yams::mechanisms::positional::Pivot::GetConfig ( ) const

Get the configuration used to construct this pivot.

Returns
Const reference to the PivotConfig.

◆ GetName()

std::string yams::mechanisms::positional::Pivot::GetName ( ) const
overridevirtual

Get the human-readable name of this pivot.

Implements yams::mechanisms::SmartMechanism.

◆ GetPose3d()

wpi::math::Pose3d yams::mechanisms::positional::Pivot::GetPose3d ( ) const
overridevirtual

Get the pivot's pose, for publishing to AdvantageScope as a component of a robot model: where it is mounted, as set in its MechanismPositionConfig, turned to the pivot's angle about the axis normal to its movement plane. A turret turns in the XY plane.

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

Implements yams::mechanisms::SmartMechanism.

◆ Gte()

wpi::cmd::Trigger yams::mechanisms::positional::Pivot::Gte ( wpi::units::degree_t  angle)

Trigger that fires while the pivot angle is >= the given angle.

Parameters
angleReference angle.
Returns
Trigger for the >= condition.

◆ IsNear()

wpi::cmd::Trigger yams::mechanisms::positional::Pivot::IsNear ( wpi::units::degree_t  angle,
wpi::units::degree_t  within = wpi::units::degree_t{1.0} 
)

Trigger that fires while the pivot is within tolerance of an angle.

Parameters
angleReference angle.
withinTolerance.
Returns
Trigger for the near condition.

◆ Lte()

wpi::cmd::Trigger yams::mechanisms::positional::Pivot::Lte ( wpi::units::degree_t  angle)

Trigger that fires while the pivot angle is <= the given angle.

Parameters
angleReference angle.
Returns
Trigger for the <= condition.

◆ Max()

wpi::cmd::Trigger yams::mechanisms::positional::Pivot::Max ( )
overridevirtual

Trigger that becomes true when the pivot is at or past its maximum configured angle.

Returns
Trigger for the upper angular hard limit.

Implements yams::mechanisms::positional::SmartPositionalMechanism.

◆ Min()

wpi::cmd::Trigger yams::mechanisms::positional::Pivot::Min ( )
overridevirtual

Trigger that becomes true when the pivot is at or past its minimum configured angle.

Returns
Trigger for the lower angular hard limit.

Implements yams::mechanisms::positional::SmartPositionalMechanism.

◆ Run() [1/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Pivot::Run ( std::function< wpi::units::degree_t()>  angle)

Set the pivot to the given angle via a supplier.

Parameters
angleSupplier returning the desired pivot angle each loop.
Returns
CommandPtr that requires the configured subsystem.

◆ Run() [2/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Pivot::Run ( wpi::units::degree_t  angle)

Set the pivot to the given angle.

Parameters
anglePivot angle to go to.
Returns
CommandPtr that requires the configured subsystem.

◆ RunTo() [1/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Pivot::RunTo ( std::function< wpi::units::degree_t()>  angle,
wpi::units::degree_t  tolerance = wpi::units::degree_t{1.0} 
)

Command the pivot to an angle from a supplier, then end when within tolerance.

The supplier is evaluated once when the command is created.

Parameters
angleSupplier for the target angle.
toleranceAcceptable error.
Returns
CommandPtr that ends once the pivot is near the target.

◆ RunTo() [2/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Pivot::RunTo ( wpi::units::degree_t  angle,
wpi::units::degree_t  tolerance = wpi::units::degree_t{1.0} 
)

Command the pivot to a fixed angle, then end when within tolerance.

Parameters
angleTarget pivot angle.
toleranceAcceptable error.
Returns
CommandPtr that ends once the pivot is near the target.

◆ SetAngle()

void yams::mechanisms::positional::Pivot::SetAngle ( wpi::units::degree_t  angle)

Directly command the pivot to an angle setpoint (non-command, for use in periodic).

Parameters
angleDesired pivot angle.

◆ SimIterate()

void yams::mechanisms::positional::Pivot::SimIterate ( )
overridevirtual

Advance the pivot's simulation by one loop iteration.

Implements yams::mechanisms::SmartMechanism.

◆ UpdateTelemetry()

void yams::mechanisms::positional::Pivot::UpdateTelemetry ( )
overridevirtual

Publish pivot telemetry to NetworkTables / SmartDashboard.

Implements yams::mechanisms::SmartMechanism.

◆ VisualizationUpdate()

void yams::mechanisms::positional::Pivot::VisualizationUpdate ( )
overridevirtual

Update the Mechanism2d ligament to reflect the current angle.

Implements yams::mechanisms::SmartMechanism.


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