WPILibC++ 2023.4.3-108-ge5452e3
frc::sim::SingleJointedArmSim Class Reference

Represents a simulated arm mechanism. More...

#include <frc/simulation/SingleJointedArmSim.h>

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

Public Member Functions

 SingleJointedArmSim (const LinearSystem< 2, 1, 1 > &system, const DCMotor &gearbox, double gearing, units::meter_t armLength, units::radian_t minAngle, units::radian_t maxAngle, bool simulateGravity, const std::array< double, 1 > &measurementStdDevs={0.0})
 Creates a simulated arm mechanism. More...
 
 SingleJointedArmSim (const DCMotor &gearbox, double gearing, units::kilogram_square_meter_t moi, units::meter_t armLength, units::radian_t minAngle, units::radian_t maxAngle, bool simulateGravity, const std::array< double, 1 > &measurementStdDevs={0.0})
 Creates a simulated arm mechanism. More...
 
bool WouldHitLowerLimit (units::radian_t armAngle) const
 Returns whether the arm would hit the lower limit. More...
 
bool WouldHitUpperLimit (units::radian_t armAngle) const
 Returns whether the arm would hit the upper limit. More...
 
bool HasHitLowerLimit () const
 Returns whether the arm has hit the lower limit. More...
 
bool HasHitUpperLimit () const
 Returns whether the arm has hit the upper limit. More...
 
units::radian_t GetAngle () const
 Returns the current arm angle. More...
 
units::radians_per_second_t GetVelocity () const
 Returns the current arm velocity. More...
 
units::ampere_t GetCurrentDraw () const override
 Returns the arm current draw. More...
 
void SetInputVoltage (units::volt_t voltage)
 Sets the input voltage for the arm. 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...
 

Static Public Member Functions

static constexpr units::kilogram_square_meter_t EstimateMOI (units::meter_t length, units::kilogram_t mass)
 Calculates a rough estimate of the moment of inertia of an arm given its length and mass. 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 arm. 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
 
Vectord< States > m_x
 
Vectord< Outputs > m_y
 
Vectord< Inputs > m_u
 
std::array< double, Outputs > m_measurementStdDevs
 

Detailed Description

Represents a simulated arm mechanism.

Constructor & Destructor Documentation

◆ SingleJointedArmSim() [1/2]

frc::sim::SingleJointedArmSim::SingleJointedArmSim ( const LinearSystem< 2, 1, 1 > &  system,
const DCMotor gearbox,
double  gearing,
units::meter_t  armLength,
units::radian_t  minAngle,
units::radian_t  maxAngle,
bool  simulateGravity,
const std::array< double, 1 > &  measurementStdDevs = {0.0} 
)

Creates a simulated arm mechanism.

Parameters
systemThe system representing this arm.
gearboxThe type and number of motors on the arm gearbox.
gearingThe gear ratio of the arm (numbers greater than 1 represent reductions).
armLengthThe length of the arm.
minAngleThe minimum angle that the arm is capable of.
maxAngleThe maximum angle that the arm is capable of.
simulateGravityWhether gravity should be simulated or not.
measurementStdDevsThe standard deviations of the measurements.

◆ SingleJointedArmSim() [2/2]

frc::sim::SingleJointedArmSim::SingleJointedArmSim ( const DCMotor gearbox,
double  gearing,
units::kilogram_square_meter_t  moi,
units::meter_t  armLength,
units::radian_t  minAngle,
units::radian_t  maxAngle,
bool  simulateGravity,
const std::array< double, 1 > &  measurementStdDevs = {0.0} 
)

Creates a simulated arm mechanism.

Parameters
gearboxThe type and number of motors on the arm gearbox.
gearingThe gear ratio of the arm (numbers greater than 1 represent reductions).
moiThe moment of inertia of the arm. This can be calculated from CAD software.
armLengthThe length of the arm.
minAngleThe minimum angle that the arm is capable of.
maxAngleThe maximum angle that the arm is capable of.
simulateGravityWhether gravity should be simulated or not.
measurementStdDevsThe standard deviation of the measurement noise.

Member Function Documentation

◆ EstimateMOI()

static constexpr units::kilogram_square_meter_t frc::sim::SingleJointedArmSim::EstimateMOI ( units::meter_t  length,
units::kilogram_t  mass 
)
inlinestaticconstexpr

Calculates a rough estimate of the moment of inertia of an arm given its length and mass.

Parameters
lengthThe length of the arm.
massThe mass of the arm.
Returns
The calculated moment of inertia.

◆ GetAngle()

units::radian_t frc::sim::SingleJointedArmSim::GetAngle ( ) const

Returns the current arm angle.

Returns
The current arm angle.

◆ GetCurrentDraw()

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

Returns the arm current draw.

Returns
The arm current draw.

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

◆ GetVelocity()

units::radians_per_second_t frc::sim::SingleJointedArmSim::GetVelocity ( ) const

Returns the current arm velocity.

Returns
The current arm velocity.

◆ HasHitLowerLimit()

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

Returns whether the arm has hit the lower limit.

Returns
Whether the arm has hit the lower limit.

◆ HasHitUpperLimit()

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

Returns whether the arm has hit the upper limit.

Returns
Whether the arm has hit the upper limit.

◆ SetInputVoltage()

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

Sets the input voltage for the arm.

Parameters
voltageThe input voltage.

◆ UpdateX()

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

Updates the state estimate of the arm.

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

◆ WouldHitLowerLimit()

bool frc::sim::SingleJointedArmSim::WouldHitLowerLimit ( units::radian_t  armAngle) const

Returns whether the arm would hit the lower limit.

Parameters
armAngleThe arm height.
Returns
Whether the arm would hit the lower limit.

◆ WouldHitUpperLimit()

bool frc::sim::SingleJointedArmSim::WouldHitUpperLimit ( units::radian_t  armAngle) const

Returns whether the arm would hit the upper limit.

Parameters
armAngleThe arm height.
Returns
Whether the arm would hit the upper limit.

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