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

#include <Elevator.hpp>

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

Public Member Functions

 Elevator (config::ElevatorConfig *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::meter_t height)
 
wpi::cmd::CommandPtr Run (std::function< wpi::units::meter_t()> height)
 
wpi::cmd::CommandPtr RunTo (wpi::units::meter_t height, wpi::units::meter_t tolerance=wpi::units::meter_t{0.01})
 
wpi::cmd::CommandPtr RunTo (std::function< wpi::units::meter_t()> height, wpi::units::meter_t tolerance=wpi::units::meter_t{0.01})
 
wpi::units::meter_t GetHeight () const
 
wpi::cmd::Trigger Gte (wpi::units::meter_t height)
 
wpi::cmd::Trigger Lte (wpi::units::meter_t height)
 
wpi::cmd::Trigger Between (wpi::units::meter_t start, wpi::units::meter_t end)
 
wpi::cmd::Trigger IsNear (wpi::units::meter_t height, wpi::units::meter_t within=wpi::units::meter_t{0.01})
 
const config::ElevatorConfig & GetConfig () const
 
wpi::math::Pose3d GetPose3d () const override
 
std::vector< wpi::math::Pose3d > GetCascadePose3d () const
 
std::vector< wpi::math::Pose3d > GetContinuousPose3d (bool carriageFirst) const
 
void SetHeight (wpi::units::meter_t height)
 
- 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 linear elevator.

Drives a carriage along a linear axis using a SmartMotorController configured for measurement-space (meter) closed-loop control.

Example usage (inside a subsystem constructor)

using namespace yams::motorcontrollers;
using namespace yams::gearing;
// Declare as subsystem members:
// rev::spark::SparkMax m_sparkMax{2,
rev::spark::SparkLowLevel::MotorType::kBrushless};
// std::optional<SparkWrapper> m_smc;
// ElevatorConfig m_elevatorConfig;
// std::optional<Elevator> m_elevator;
motorCfg.WithSubsystem(this)
.WithFeedback(1.0, 0.0, 0.0)
.WithMotorGearing(MechanismGearing{GearBox::FromReductionStages({3.0, 4.0})})
.WithMeasurementLimits(0.0_m, 2.0_m)
.WithZeroPower(Cfg::MotorMode::BRAKE)
.WithFeedforward(wpi::math::ElevatorFeedforward{
0.0_V, 0.0_V, wpi::units::unit_t<wpi::math::ElevatorFeedforward::kv_unit>{0.0},
wpi::units::unit_t<wpi::math::ElevatorFeedforward::ka_unit>{0.0}})
.WithClosedLoopMode()
.WithTelemetry("ElevatorMotor", Cfg::TelemetryVerbosity::HIGH);
m_smc.emplace(&m_sparkMax, wpi::math::DCMotor::NEO(1), &motorCfg);
m_elevatorConfig.WithMinimumHeight(0.0_m)
.WithTelemetryName("Elevator");
m_elevator.emplace(&m_elevatorConfig, &m_smc.value());
// In commands or bindings:
m_elevator->RunTo(1.2_m);
Definition MechanismGearing.hpp:19
motorcontrollers::SmartMotorController * m_smc
Definition SmartMechanism.hpp:153
ElevatorConfig & WithMinimumHeight(wpi::units::meter_t height)
ElevatorConfig & WithMaximumHeight(wpi::units::meter_t height)
ElevatorConfig & WithTelemetryName(const std::string &name)
ElevatorConfig & WithCarriageMass(wpi::units::kilogram_t mass)
Definition SmartMotorControllerConfig.hpp:65
SmartMotorControllerConfig & WithTelemetry(const std::string &name, TelemetryVerbosity verbosity=TelemetryVerbosity::HIGH)
SmartMotorControllerConfig & WithSupplyCurrentLimit(wpi::units::ampere_t limit)
SmartMotorControllerConfig & WithMotorInverted(bool inverted)
SmartMotorControllerConfig & WithZeroPower(MotorMode mode)
SmartMotorControllerConfig & WithStartingPosition(wpi::units::degree_t startingAngle)
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 & WithMechanismCircumference(wpi::units::meter_t circumference)
Definition GearBox.hpp:11
Definition Arm.hpp:19
Definition NovaWrapper.hpp:18
Definition SimSensorConfig.hpp:15

Constructor & Destructor Documentation

◆ Elevator()

yams::mechanisms::positional::Elevator::Elevator ( config::ElevatorConfig *  config,
motorcontrollers::SmartMotorController *  smc 
)

Construct an Elevator from an ElevatorConfig and a SmartMotorController.

Parameters
configPointer to the elevator configuration (must outlive this Elevator).
smcPointer to the motor controller (must outlive this Elevator).

Member Function Documentation

◆ Between()

wpi::cmd::Trigger yams::mechanisms::positional::Elevator::Between ( wpi::units::meter_t  start,
wpi::units::meter_t  end 
)

Trigger that fires while the elevator height is between start and end (inclusive).

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

◆ GetCascadePose3d()

std::vector< wpi::math::Pose3d > yams::mechanisms::positional::Elevator::GetCascadePose3d ( ) const

Get the pose of each moving stage of a cascade elevator, for publishing to AdvantageScope as components of a robot model. A cascade elevator's stages all move at once, each by its share of the carriage's height: a stage that travels a third of the elevator's total travel moves a third of the carriage's height relative to the stage below it.

The stages are set with ElevatorConfig::WithStages().

Returns
Each moving stage's pose, relative to the robot, from the stage nearest the fixed stage to the carriage. The last is the carriage, GetPose3d().
Exceptions
ElevatorConfigurationExceptionif the stages are not set, or there are fewer than 2.

◆ GetConfig()

const config::ElevatorConfig & yams::mechanisms::positional::Elevator::GetConfig ( ) const

Get the configuration used to construct this elevator.

Returns
Const reference to the ElevatorConfig.

◆ GetContinuousPose3d()

std::vector< wpi::math::Pose3d > yams::mechanisms::positional::Elevator::GetContinuousPose3d ( bool  carriageFirst) const

Get the pose of each moving stage of a continuous elevator, for publishing to AdvantageScope as components of a robot model. A continuous elevator's stages move one at a time. Which moves first depends on how it is rigged: watch it move to see which it is.

  • Carriage first: the carriage rises the whole of its travel first, then the stage below it, and so on out to the stage nearest the fixed stage. Going down, the stage nearest the fixed stage lowers first.
  • Carriage last: the stage nearest the fixed stage rises the whole of its travel first, then the next, and so on out to the carriage. Going down, the carriage lowers first.

The stages are set with ElevatorConfig::WithStages().

Parameters
carriageFirstTrue if the carriage moves first, false if it moves last.
Returns
Each moving stage's pose, relative to the robot, from the stage nearest the fixed stage to the carriage. The last is the carriage, GetPose3d().
Exceptions
ElevatorConfigurationExceptionif the stages are not set, or there are fewer than 2.

◆ GetHeight()

wpi::units::meter_t yams::mechanisms::positional::Elevator::GetHeight ( ) const

Get the current carriage height from the motor encoder.

Returns
Current height in meters.

◆ GetName()

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

Get the human-readable name of this elevator.

Implements yams::mechanisms::SmartMechanism.

◆ GetPose3d()

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

Get the carriage's pose, for publishing to AdvantageScope as a component of a robot model: where the elevator is mounted, as set in its MechanismPositionConfig, moved up the elevator by its height, at the elevator's angle in its movement plane.

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

Implements yams::mechanisms::SmartMechanism.

◆ Gte()

wpi::cmd::Trigger yams::mechanisms::positional::Elevator::Gte ( wpi::units::meter_t  height)

Trigger that fires while the elevator height is >= the given height.

Parameters
heightReference height.
Returns
Trigger for the >= condition.

◆ IsNear()

wpi::cmd::Trigger yams::mechanisms::positional::Elevator::IsNear ( wpi::units::meter_t  height,
wpi::units::meter_t  within = wpi::units::meter_t{0.01} 
)

Trigger that fires while the elevator is within tolerance of a height.

Parameters
heightReference height.
withinTolerance.
Returns
Trigger for the near condition.

◆ Lte()

wpi::cmd::Trigger yams::mechanisms::positional::Elevator::Lte ( wpi::units::meter_t  height)

Trigger that fires while the elevator height is <= the given height.

Parameters
heightReference height.
Returns
Trigger for the <= condition.

◆ Max()

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

Trigger that becomes true when the elevator is at or above its maximum configured height.

Returns
Trigger for the upper hard limit.

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

◆ Min()

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

Trigger that becomes true when the elevator is at or below its minimum configured height.

Returns
Trigger for the lower hard limit.

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

◆ Run() [1/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Elevator::Run ( std::function< wpi::units::meter_t()>  height)

Set the height of the elevator via a supplier.

Parameters
heightSupplier returning the desired height each loop.
Returns
CommandPtr that sets the elevator height, runs continuously.

◆ Run() [2/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Elevator::Run ( wpi::units::meter_t  height)

Set the height of the elevator.

Parameters
heightHeight of the elevator to reach.
Returns
CommandPtr that sets the elevator height, runs continuously.

◆ RunTo() [1/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Elevator::RunTo ( std::function< wpi::units::meter_t()>  height,
wpi::units::meter_t  tolerance = wpi::units::meter_t{0.01} 
)

Command the elevator to a height from a supplier, then end when within tolerance.

The supplier is evaluated once when the command is created.

Parameters
heightSupplier for the target height.
toleranceAcceptable error.
Returns
CommandPtr that ends once the elevator is near the target.

◆ RunTo() [2/2]

wpi::cmd::CommandPtr yams::mechanisms::positional::Elevator::RunTo ( wpi::units::meter_t  height,
wpi::units::meter_t  tolerance = wpi::units::meter_t{0.01} 
)

Command the elevator to a fixed height, then end when within tolerance.

Parameters
heightTarget carriage height.
toleranceAcceptable error.
Returns
CommandPtr that ends once the elevator is near the target.

◆ SetHeight()

void yams::mechanisms::positional::Elevator::SetHeight ( wpi::units::meter_t  height)

Directly command the elevator to a height setpoint (non-command, for use in periodic).

Parameters
heightDesired carriage height.

◆ SimIterate()

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

Advance the elevator's simulation by one loop iteration.

Implements yams::mechanisms::SmartMechanism.

◆ UpdateTelemetry()

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

Publish elevator telemetry to NetworkTables / SmartDashboard.

Implements yams::mechanisms::SmartMechanism.

◆ VisualizationUpdate()

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

Update the Mechanism2d ligament to reflect the current height.

Implements yams::mechanisms::SmartMechanism.


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