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

#include <Arm.hpp>

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

Public Member Functions

 Arm (config::ArmConfig *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::ArmConfig & 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 single-jointed arm.

Drives an arm joint using a SmartMotorController configured for mechanism-space (degree) closed-loop angular control.

Example usage (inside a subsystem constructor)

using namespace yams::motorcontrollers;
using namespace yams::gearing;
// Declare as subsystem members:
// ctre::phoenix6::hardware::TalonFX m_talon{1};
// std::optional<TalonFXWrapper> m_smc;
// ArmConfig m_armConfig;
// std::optional<Arm> m_arm;
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("ArmMotor", Cfg::TelemetryVerbosity::HIGH);
m_smc.emplace(m_talon, wpi::math::DCMotor::KrakenX60(1), motorCfg);
m_armConfig.WithMinAngle(-100.0_deg)
.WithMaxAngle(200.0_deg)
.WithArmLength(0.135_m)
.WithTelemetryName("ArmExample");
m_arm.emplace(&m_armConfig, &m_smc.value());
// In commands or bindings:
m_arm->RunTo(45.0_deg);
Definition MechanismGearing.hpp:19
motorcontrollers::SmartMotorController * m_smc
Definition SmartMechanism.hpp:153
ArmConfig & WithTelemetryName(const std::string &name)
ArmConfig & WithMaxAngle(wpi::units::degree_t angle)
ArmConfig & WithArmLength(wpi::units::meter_t length)
ArmConfig & 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

◆ Arm()

yams::mechanisms::positional::Arm::Arm ( config::ArmConfig *  config,
motorcontrollers::SmartMotorController *  smc 
)

Construct an Arm from an ArmConfig pointer and a SmartMotorController pointer.

Parameters
configPointer to the arm configuration (must outlive this Arm).
smcPointer to the motor controller (must outlive this Arm).

Member Function Documentation

◆ Between()

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

Trigger that fires while the arm 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::Arm::GetAngle ( ) const

Get the current joint angle from the motor encoder.

Returns
Current mechanism angle in degrees.

◆ GetConfig()

const config::ArmConfig & yams::mechanisms::positional::Arm::GetConfig ( ) const

Get the configuration used to construct this arm.

Returns
Const reference to the ArmConfig.

◆ GetName()

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

Get the human-readable name of this arm.

Implements yams::mechanisms::SmartMechanism.

◆ GetPose3d()

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

Get the arm'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 arm's angle about the axis normal to its movement plane.

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

Implements yams::mechanisms::SmartMechanism.

◆ Gte()

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

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

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

◆ IsNear()

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

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

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

◆ Lte()

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

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

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

◆ Max()

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

Trigger that becomes true when the arm 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::Arm::Min ( )
overridevirtual

Trigger that becomes true when the arm 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::Arm::Run ( std::function< wpi::units::degree_t()>  angle)

Set the arm to the given angle via a supplier.

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

◆ Run() [2/2]

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

Set the arm to the given angle.

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

◆ RunTo() [1/2]

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

Command the arm 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 arm is near the target.

◆ RunTo() [2/2]

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

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

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

◆ SetAngle()

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

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

Parameters
angleDesired joint angle.

◆ SimIterate()

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

Advance the arm's simulation by one loop iteration.

Implements yams::mechanisms::SmartMechanism.

◆ UpdateTelemetry()

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

Publish arm telemetry to NetworkTables / SmartDashboard.

Implements yams::mechanisms::SmartMechanism.

◆ VisualizationUpdate()

void yams::mechanisms::positional::Arm::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: