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

Represents a simulated DC motor mechanism. More...

#include <frc/simulation/DCMotorSim.h>

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

Public Member Functions

 DCMotorSim (const LinearSystem< 2, 1, 2 > &plant, const DCMotor &gearbox, double gearing, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
 Creates a simulated DC motor mechanism. More...
 
 DCMotorSim (const DCMotor &gearbox, double gearing, units::kilogram_square_meter_t moi, const std::array< double, 2 > &measurementStdDevs={0.0, 0.0})
 Creates a simulated DC motor mechanism. More...
 
void SetState (units::radian_t angularPosition, units::radians_per_second_t angularVelocity)
 Sets the state of the DC motor. More...
 
units::radian_t GetAngularPosition () const
 Returns the DC motor position. More...
 
units::radians_per_second_t GetAngularVelocity () const
 Returns the DC motor velocity. More...
 
units::ampere_t GetCurrentDraw () const override
 Returns the DC motor current draw. More...
 
void SetInputVoltage (units::volt_t voltage)
 Sets the input voltage for the DC motor. More...
 
void SetState (const Vectord< States > &state)
 Sets the system state. More...
 
- Public Member Functions inherited from frc::sim::LinearSystemSim< 2, 1, 2 >
 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...
 

Additional Inherited Members

- Protected Member Functions inherited from frc::sim::LinearSystemSim< 2, 1, 2 >
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...
 
- Protected Attributes inherited from frc::sim::LinearSystemSim< 2, 1, 2 >
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 DC motor mechanism.

Constructor & Destructor Documentation

◆ DCMotorSim() [1/2]

frc::sim::DCMotorSim::DCMotorSim ( const LinearSystem< 2, 1, 2 > &  plant,
const DCMotor gearbox,
double  gearing,
const std::array< double, 2 > &  measurementStdDevs = {0.0, 0.0} 
)

Creates a simulated DC motor mechanism.

Parameters
plantThe linear system representing the DC motor. This system can be created with LinearSystemId::DCMotorSystem().
gearboxThe type of and number of motors in the DC motor gearbox.
gearingThe gearing of the DC motor (numbers greater than 1 represent reductions).
measurementStdDevsThe standard deviation of the measurement noise.

◆ DCMotorSim() [2/2]

frc::sim::DCMotorSim::DCMotorSim ( const DCMotor gearbox,
double  gearing,
units::kilogram_square_meter_t  moi,
const std::array< double, 2 > &  measurementStdDevs = {0.0, 0.0} 
)

Creates a simulated DC motor mechanism.

Parameters
gearboxThe type of and number of motors in the DC motor gearbox.
gearingThe gearing of the DC motor (numbers greater than 1 represent reductions).
moiThe moment of inertia of the DC motor.
measurementStdDevsThe standard deviation of the measurement noise.

Member Function Documentation

◆ GetAngularPosition()

units::radian_t frc::sim::DCMotorSim::GetAngularPosition ( ) const

Returns the DC motor position.

Returns
The DC motor position.

◆ GetAngularVelocity()

units::radians_per_second_t frc::sim::DCMotorSim::GetAngularVelocity ( ) const

Returns the DC motor velocity.

Returns
The DC motor velocity.

◆ GetCurrentDraw()

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

Returns the DC motor current draw.

Returns
The DC motor current draw.

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

◆ SetInputVoltage()

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

Sets the input voltage for the DC motor.

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::DCMotorSim::SetState ( units::radian_t  angularPosition,
units::radians_per_second_t  angularVelocity 
)

Sets the state of the DC motor.

Parameters
angularPositionThe new position
angularVelocityThe new velocity

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