WPILibC++ 2024.3.2
frc::sim::ElevatorSim Class Reference

Represents a simulated elevator mechanism. More...

#include <frc/simulation/ElevatorSim.h>

Inheritance diagram for frc::sim::ElevatorSim:
frc::sim::LinearSystemSim< 2, 1, 1 >

Public Types

template<typename Distance >
using Velocity_t = units::unit_t< units::compound_unit< Distance, units::inverse< units::seconds > > >
 
template<typename Distance >
using Acceleration_t = units::unit_t< units::compound_unit< units::compound_unit< Distance, units::inverse< units::seconds > >, units::inverse< units::seconds > > >
 

Public Member Functions

 ElevatorSim (const LinearSystem< 2, 1, 1 > &plant, const DCMotor &gearbox, units::meter_t minHeight, units::meter_t maxHeight, bool simulateGravity, units::meter_t startingHeight, const std::array< double, 1 > &measurementStdDevs={0.0})
 Constructs a simulated elevator mechanism. More...
 
 ElevatorSim (const DCMotor &gearbox, double gearing, units::kilogram_t carriageMass, units::meter_t drumRadius, units::meter_t minHeight, units::meter_t maxHeight, bool simulateGravity, units::meter_t startingHeight, const std::array< double, 1 > &measurementStdDevs={0.0})
 Constructs a simulated elevator mechanism. More...
 
template<typename Distance >
requires std::same_as<units::meter, Distance> || std::same_as<units::radian, Distance>
 ElevatorSim (decltype(1_V/Velocity_t< Distance >(1)) kV, decltype(1_V/Acceleration_t< Distance >(1)) kA, const DCMotor &gearbox, units::meter_t minHeight, units::meter_t maxHeight, bool simulateGravity, units::meter_t startingHeight, const std::array< double, 1 > &measurementStdDevs={0.0})
 Constructs a simulated elevator mechanism. More...
 
void SetState (units::meter_t position, units::meters_per_second_t velocity)
 Sets the elevator's state. More...
 
bool WouldHitLowerLimit (units::meter_t elevatorHeight) const
 Returns whether the elevator would hit the lower limit. More...
 
bool WouldHitUpperLimit (units::meter_t elevatorHeight) const
 Returns whether the elevator would hit the upper limit. More...
 
bool HasHitLowerLimit () const
 Returns whether the elevator has hit the lower limit. More...
 
bool HasHitUpperLimit () const
 Returns whether the elevator has hit the upper limit. More...
 
units::meter_t GetPosition () const
 Returns the position of the elevator. More...
 
units::meters_per_second_t GetVelocity () const
 Returns the velocity of the elevator. More...
 
units::ampere_t GetCurrentDraw () const override
 Returns the elevator current draw. More...
 
void SetInputVoltage (units::volt_t voltage)
 Sets the input voltage for the elevator. More...
 
void SetState (const Vectord< States > &state)
 Sets the system state. More...
 
- Public Member Functions inherited from frc::sim::LinearSystemSim< 2, 1, 1 >
 LinearSystemSim (const LinearSystem< States, Inputs, Outputs > &system, const std::array< double, Outputs > &measurementStdDevs={})
 Creates a simulated generic linear system. More...
 
virtual ~LinearSystemSim ()=default
 
void Update (units::second_t dt)
 Updates the simulation. More...
 
const Vectord< Outputs > & GetOutput () const
 Returns the current output of the plant. More...
 
double GetOutput (int row) const
 Returns an element of the current output of the plant. More...
 
void SetInput (const Vectord< Inputs > &u)
 Sets the system inputs (usually voltages). More...
 
void SetInput (int row, double value)
 
void SetState (const Vectord< States > &state)
 Sets the system state. More...
 
virtual units::ampere_t GetCurrentDraw () const
 Returns the current drawn by this simulated system. More...
 

Protected Member Functions

Vectord< 2 > UpdateX (const Vectord< 2 > &currentXhat, const Vectord< 1 > &u, units::second_t dt) override
 Updates the state estimate of the elevator. More...
 
- Protected Member Functions inherited from frc::sim::LinearSystemSim< 2, 1, 1 >
virtual Vectord< States > UpdateX (const Vectord< States > &currentXhat, const Vectord< Inputs > &u, units::second_t dt)
 Updates the state estimate of the system. More...
 
Vectord< Inputs > ClampInput (Vectord< Inputs > u)
 Clamp the input vector such that no element exceeds the given voltage. More...
 

Additional Inherited Members

- Protected Attributes inherited from frc::sim::LinearSystemSim< 2, 1, 1 >
LinearSystem< States, Inputs, Outputs > m_plant
 The plant that represents the linear system. More...
 
Vectord< States > m_x
 State vector. More...
 
Vectord< Inputs > m_u
 Input vector. More...
 
Vectord< Outputs > m_y
 Output vector. More...
 
std::array< double, Outputs > m_measurementStdDevs
 The standard deviations of measurements, used for adding noise to the measurements. More...
 

Detailed Description

Represents a simulated elevator mechanism.

Member Typedef Documentation

◆ Acceleration_t

template<typename Distance >
using frc::sim::ElevatorSim::Acceleration_t = units::unit_t<units::compound_unit< units::compound_unit<Distance, units::inverse<units::seconds> >, units::inverse<units::seconds> >>

◆ Velocity_t

template<typename Distance >
using frc::sim::ElevatorSim::Velocity_t = units::unit_t< units::compound_unit<Distance, units::inverse<units::seconds> >>

Constructor & Destructor Documentation

◆ ElevatorSim() [1/3]

frc::sim::ElevatorSim::ElevatorSim ( const LinearSystem< 2, 1, 1 > &  plant,
const DCMotor gearbox,
units::meter_t  minHeight,
units::meter_t  maxHeight,
bool  simulateGravity,
units::meter_t  startingHeight,
const std::array< double, 1 > &  measurementStdDevs = {0.0} 
)

Constructs a simulated elevator mechanism.

Parameters
plantThe linear system that represents the elevator. This system can be created with LinearSystemId::ElevatorSystem().
gearboxThe type of and number of motors in your elevator gearbox.
minHeightThe minimum allowed height of the elevator.
maxHeightThe maximum allowed height of the elevator.
simulateGravityWhether gravity should be simulated or not.
startingHeightThe starting height of the elevator.
measurementStdDevsThe standard deviation of the measurements.

◆ ElevatorSim() [2/3]

frc::sim::ElevatorSim::ElevatorSim ( const DCMotor gearbox,
double  gearing,
units::kilogram_t  carriageMass,
units::meter_t  drumRadius,
units::meter_t  minHeight,
units::meter_t  maxHeight,
bool  simulateGravity,
units::meter_t  startingHeight,
const std::array< double, 1 > &  measurementStdDevs = {0.0} 
)

Constructs a simulated elevator mechanism.

Parameters
gearboxThe type of and number of motors in your elevator gearbox.
gearingThe gearing of the elevator (numbers greater than 1 represent reductions).
carriageMassThe mass of the elevator carriage.
drumRadiusThe radius of the drum that your cable is wrapped around.
minHeightThe minimum allowed height of the elevator.
maxHeightThe maximum allowed height of the elevator.
simulateGravityWhether gravity should be simulated or not.
startingHeightThe starting height of the elevator.
measurementStdDevsThe standard deviation of the measurements.

◆ ElevatorSim() [3/3]

template<typename Distance >
requires std::same_as<units::meter, Distance> || std::same_as<units::radian, Distance>
frc::sim::ElevatorSim::ElevatorSim ( decltype(1_V/Velocity_t< Distance >(1))  kV,
decltype(1_V/Acceleration_t< Distance >(1))  kA,
const DCMotor gearbox,
units::meter_t  minHeight,
units::meter_t  maxHeight,
bool  simulateGravity,
units::meter_t  startingHeight,
const std::array< double, 1 > &  measurementStdDevs = {0.0} 
)

Constructs a simulated elevator mechanism.

Parameters
kVThe velocity gain.
kAThe acceleration gain.
gearboxThe type of and number of motors in your elevator gearbox.
minHeightThe minimum allowed height of the elevator.
maxHeightThe maximum allowed height of the elevator.
simulateGravityWhether gravity should be simulated or not.
startingHeightThe starting height of the elevator.
measurementStdDevsThe standard deviation of the measurements.

Member Function Documentation

◆ GetCurrentDraw()

units::ampere_t frc::sim::ElevatorSim::GetCurrentDraw ( ) const
overridevirtual

Returns the elevator current draw.

Returns
The elevator current draw.

Reimplemented from frc::sim::LinearSystemSim< 2, 1, 1 >.

◆ GetPosition()

units::meter_t frc::sim::ElevatorSim::GetPosition ( ) const

Returns the position of the elevator.

Returns
The position of the elevator.

◆ GetVelocity()

units::meters_per_second_t frc::sim::ElevatorSim::GetVelocity ( ) const

Returns the velocity of the elevator.

Returns
The velocity of the elevator.

◆ HasHitLowerLimit()

bool frc::sim::ElevatorSim::HasHitLowerLimit ( ) const

Returns whether the elevator has hit the lower limit.

Returns
Whether the elevator has hit the lower limit.

◆ HasHitUpperLimit()

bool frc::sim::ElevatorSim::HasHitUpperLimit ( ) const

Returns whether the elevator has hit the upper limit.

Returns
Whether the elevator has hit the upper limit.

◆ SetInputVoltage()

void frc::sim::ElevatorSim::SetInputVoltage ( units::volt_t  voltage)

Sets the input voltage for the elevator.

Parameters
voltageThe input voltage.

◆ SetState() [1/2]

void frc::sim::LinearSystemSim< States, Inputs, Outputs >::SetState ( const Vectord< States > &  state)
inline

Sets the system state.

Parameters
stateThe new state.

◆ SetState() [2/2]

void frc::sim::ElevatorSim::SetState ( units::meter_t  position,
units::meters_per_second_t  velocity 
)

Sets the elevator's state.

The new position will be limited between the minimum and maximum allowed heights.

Parameters
positionThe new position
velocityThe new velocity

◆ UpdateX()

Vectord< 2 > frc::sim::ElevatorSim::UpdateX ( const Vectord< 2 > &  currentXhat,
const Vectord< 1 > &  u,
units::second_t  dt 
)
overrideprotected

Updates the state estimate of the elevator.

Parameters
currentXhatThe current state estimate.
uThe system inputs (voltage).
dtThe time difference between controller updates.

◆ WouldHitLowerLimit()

bool frc::sim::ElevatorSim::WouldHitLowerLimit ( units::meter_t  elevatorHeight) const

Returns whether the elevator would hit the lower limit.

Parameters
elevatorHeightThe elevator height.
Returns
Whether the elevator would hit the lower limit.

◆ WouldHitUpperLimit()

bool frc::sim::ElevatorSim::WouldHitUpperLimit ( units::meter_t  elevatorHeight) const

Returns whether the elevator would hit the upper limit.

Parameters
elevatorHeightThe elevator height.
Returns
Whether the elevator would hit the upper limit.

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