WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::sim::SingleJointedArmSim Class Reference

Represents a simulated arm mechanism. More...

#include <wpi/simulation/SingleJointedArmSim.hpp>

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

Public Member Functions

 SingleJointedArmSim (const wpi::math::LinearSystem< 2, 1, 2 > &system, const wpi::math::DCMotor &gearbox, double gearing, wpi::units::meter_t armLength, wpi::units::radian_t minAngle, wpi::units::radian_t maxAngle, bool simulateGravity, wpi::units::radian_t startingAngle, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
 Creates a simulated arm mechanism.
 SingleJointedArmSim (const wpi::math::DCMotor &gearbox, double gearing, wpi::units::kilogram_square_meter_t moi, wpi::units::meter_t armLength, wpi::units::radian_t minAngle, wpi::units::radian_t maxAngle, bool simulateGravity, wpi::units::radian_t startingAngle, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
 Creates a simulated arm mechanism.
void SetState (wpi::units::radian_t angle, wpi::units::radians_per_second_t velocity)
 Sets the arm's state.
bool WouldHitLowerLimit (wpi::units::radian_t armAngle) const
 Returns whether the arm would hit the lower limit.
bool WouldHitUpperLimit (wpi::units::radian_t armAngle) const
 Returns whether the arm would hit the upper limit.
bool HasHitLowerLimit () const
 Returns whether the arm has hit the lower limit.
bool HasHitUpperLimit () const
 Returns whether the arm has hit the upper limit.
wpi::units::radian_t GetAngle () const
 Returns the current arm angle.
wpi::units::radians_per_second_t GetVelocity () const
 Returns the current arm velocity.
wpi::units::ampere_t GetCurrentDraw () const
 Returns the arm current draw.
void SetInputVoltage (wpi::units::volt_t voltage)
 Sets the input voltage for the arm.
void SetState (const wpi::math::Vectord< States > &state)
 Sets the system state.
Public Member Functions inherited from wpi::sim::LinearSystemSim< 2, 1, 2 >
 LinearSystemSim (const wpi::math::LinearSystem< States, Inputs, Outputs > &system, const std::array< double, Outputs > &measurementStdDevs={})
 Creates a simulated generic linear system.
virtual ~LinearSystemSim ()=default
void Update (wpi::units::second_t dt)
 Updates the simulation.
const wpi::math::Vectord< Outputs > & GetOutput () const
 Returns the current output of the plant.
void SetInput (const wpi::math::Vectord< Inputs > &u)
 Sets the system inputs (usually voltages).
const wpi::math::Vectord< Inputs > & GetInput () const
 Returns the current input of the plant.
void SetState (const wpi::math::Vectord< States > &state)
 Sets the system state.

Static Public Member Functions

static constexpr wpi::units::kilogram_square_meter_t EstimateMOI (wpi::units::meter_t length, wpi::units::kilogram_t mass)
 Calculates a rough estimate of the moment of inertia of an arm given its length and mass.

Protected Member Functions

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

Additional Inherited Members

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

Detailed Description

Represents a simulated arm mechanism.

Constructor & Destructor Documentation

◆ SingleJointedArmSim() [1/2]

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

Creates a simulated arm mechanism.

Parameters
systemThe system representing this arm. This system can be created with wpi::math::Models::SingleJointedArmFromPhysicalConstants().
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, with 0 being horizontal.
maxAngleThe maximum angle that the arm is capable of, with 0 being horizontal.
simulateGravityWhether gravity should be simulated or not.
startingAngleThe initial position of the arm.
measurementStdDevsThe standard deviations of the measurements.

◆ SingleJointedArmSim() [2/2]

wpi::sim::SingleJointedArmSim::SingleJointedArmSim ( const wpi::math::DCMotor & gearbox,
double gearing,
wpi::units::kilogram_square_meter_t moi,
wpi::units::meter_t armLength,
wpi::units::radian_t minAngle,
wpi::units::radian_t maxAngle,
bool simulateGravity,
wpi::units::radian_t startingAngle,
const std::array< double, 2 > & measurementStdDevs = {0.0, 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, with 0 being horizontal.
maxAngleThe maximum angle that the arm is capable of, with 0 being horizontal.
simulateGravityWhether gravity should be simulated or not.
startingAngleThe initial position of the arm.
measurementStdDevsThe standard deviation of the measurement noise.

Member Function Documentation

◆ EstimateMOI()

constexpr wpi::units::kilogram_square_meter_t wpi::sim::SingleJointedArmSim::EstimateMOI ( wpi::units::meter_t length,
wpi::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()

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

Returns the current arm angle.

Returns
The current arm angle.

◆ GetCurrentDraw()

wpi::units::ampere_t wpi::sim::SingleJointedArmSim::GetCurrentDraw ( ) const

Returns the arm current draw.

Returns
The arm current draw.

◆ GetVelocity()

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

Returns the current arm velocity.

Returns
The current arm velocity.

◆ HasHitLowerLimit()

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

Returns whether the arm has hit the lower limit.

Returns
Whether the arm has hit the lower limit.

◆ HasHitUpperLimit()

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

Returns whether the arm has hit the upper limit.

Returns
Whether the arm has hit the upper limit.

◆ SetInputVoltage()

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

Sets the input voltage for the arm.

Parameters
voltageThe input voltage.

◆ SetState() [1/2]

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

Sets the system state.

Parameters
stateThe new state.

◆ SetState() [2/2]

void wpi::sim::SingleJointedArmSim::SetState ( wpi::units::radian_t angle,
wpi::units::radians_per_second_t velocity )

Sets the arm's state.

The new angle will be limited between the minimum and maximum allowed limits.

Parameters
angleThe new angle.
velocityThe new angular velocity.

◆ UpdateX()

wpi::math::Vectord< 2 > wpi::sim::SingleJointedArmSim::UpdateX ( const wpi::math::Vectord< 2 > & currentXhat,
const wpi::math::Vectord< 1 > & u,
wpi::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 wpi::sim::SingleJointedArmSim::WouldHitLowerLimit ( wpi::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 wpi::sim::SingleJointedArmSim::WouldHitUpperLimit ( wpi::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: