Package edu.wpi.first.wpilibj.simulation
Class SingleJointedArmSim
java.lang.Object
edu.wpi.first.wpilibj.simulation.LinearSystemSim<N2,N1,N1>
edu.wpi.first.wpilibj.simulation.SingleJointedArmSim
public class SingleJointedArmSim extends LinearSystemSim<N2,N1,N1>
Represents a simulated single jointed arm mechanism.
-
Field Summary
Fields inherited from class edu.wpi.first.wpilibj.simulation.LinearSystemSim
m_measurementStdDevs, m_plant, m_u, m_x, m_y
-
Constructor Summary
Constructors Constructor Description SingleJointedArmSim(LinearSystem<N2,N1,N1> plant, DCMotor gearbox, double gearing, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity)
Creates a simulated arm mechanism.SingleJointedArmSim(LinearSystem<N2,N1,N1> plant, DCMotor gearbox, double gearing, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity, Matrix<N1,N1> measurementStdDevs)
Creates a simulated arm mechanism.SingleJointedArmSim(DCMotor gearbox, double gearing, double jKgMetersSquared, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity)
Creates a simulated arm mechanism.SingleJointedArmSim(DCMotor gearbox, double gearing, double jKgMetersSquared, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity, Matrix<N1,N1> measurementStdDevs)
Creates a simulated arm mechanism. -
Method Summary
Modifier and Type Method Description static double
estimateMOI(double lengthMeters, double massKg)
Calculates a rough estimate of the moment of inertia of an arm given its length and mass.double
getAngleRads()
Returns the current arm angle.double
getCurrentDrawAmps()
Returns the arm current draw.double
getVelocityRadPerSec()
Returns the current arm velocity.boolean
hasHitLowerLimit()
Returns whether the arm has hit the lower limit.boolean
hasHitUpperLimit()
Returns whether the arm has hit the upper limit.void
setInputVoltage(double volts)
Sets the input voltage for the arm.protected Matrix<N2,N1>
updateX(Matrix<N2,N1> currentXhat, Matrix<N1,N1> u, double dtSeconds)
Updates the state of the arm.boolean
wouldHitLowerLimit(double currentAngleRads)
Returns whether the arm would hit the lower limit.boolean
wouldHitUpperLimit(double currentAngleRads)
Returns whether the arm would hit the upper limit.Methods inherited from class edu.wpi.first.wpilibj.simulation.LinearSystemSim
clampInput, getOutput, getOutput, setInput, setInput, setInput, setState, update
-
Constructor Details
-
SingleJointedArmSim
public SingleJointedArmSim(LinearSystem<N2,N1,N1> plant, DCMotor gearbox, double gearing, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity)Creates a simulated arm mechanism.- Parameters:
plant
- The linear system that represents the arm.gearbox
- The type of and number of motors in the arm gearbox.gearing
- The gearing of the arm (numbers greater than 1 represent reductions).armLengthMeters
- The length of the arm.minAngleRads
- The minimum angle that the arm is capable of.maxAngleRads
- The maximum angle that the arm is capable of.simulateGravity
- Whether gravity should be simulated or not.
-
SingleJointedArmSim
public SingleJointedArmSim(LinearSystem<N2,N1,N1> plant, DCMotor gearbox, double gearing, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity, Matrix<N1,N1> measurementStdDevs)Creates a simulated arm mechanism.- Parameters:
plant
- The linear system that represents the arm.gearbox
- The type of and number of motors in the arm gearbox.gearing
- The gearing of the arm (numbers greater than 1 represent reductions).armLengthMeters
- The length of the arm.minAngleRads
- The minimum angle that the arm is capable of.maxAngleRads
- The maximum angle that the arm is capable of.simulateGravity
- Whether gravity should be simulated or not.measurementStdDevs
- The standard deviations of the measurements.
-
SingleJointedArmSim
public SingleJointedArmSim(DCMotor gearbox, double gearing, double jKgMetersSquared, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity)Creates a simulated arm mechanism.- Parameters:
gearbox
- The type of and number of motors in the arm gearbox.gearing
- The gearing of the arm (numbers greater than 1 represent reductions).jKgMetersSquared
- The moment of inertia of the arm, can be calculated from CAD software.armLengthMeters
- The length of the arm.minAngleRads
- The minimum angle that the arm is capable of.maxAngleRads
- The maximum angle that the arm is capable of.simulateGravity
- Whether gravity should be simulated or not.
-
SingleJointedArmSim
public SingleJointedArmSim(DCMotor gearbox, double gearing, double jKgMetersSquared, double armLengthMeters, double minAngleRads, double maxAngleRads, boolean simulateGravity, Matrix<N1,N1> measurementStdDevs)Creates a simulated arm mechanism.- Parameters:
gearbox
- The type of and number of motors in the arm gearbox.gearing
- The gearing of the arm (numbers greater than 1 represent reductions).jKgMetersSquared
- The moment of inertia of the arm; can be calculated from CAD software.armLengthMeters
- The length of the arm.minAngleRads
- The minimum angle that the arm is capable of.maxAngleRads
- The maximum angle that the arm is capable of.simulateGravity
- Whether gravity should be simulated or not.measurementStdDevs
- The standard deviations of the measurements.
-
-
Method Details
-
wouldHitLowerLimit
Returns whether the arm would hit the lower limit.- Parameters:
currentAngleRads
- The current arm height.- Returns:
- Whether the arm would hit the lower limit.
-
wouldHitUpperLimit
Returns whether the arm would hit the upper limit.- Parameters:
currentAngleRads
- The current arm height.- Returns:
- Whether the arm would hit the upper limit.
-
hasHitLowerLimit
Returns whether the arm has hit the lower limit.- Returns:
- Whether the arm has hit the lower limit.
-
hasHitUpperLimit
Returns whether the arm has hit the upper limit.- Returns:
- Whether the arm has hit the upper limit.
-
getAngleRads
Returns the current arm angle.- Returns:
- The current arm angle.
-
getVelocityRadPerSec
Returns the current arm velocity.- Returns:
- The current arm velocity.
-
getCurrentDrawAmps
Returns the arm current draw.- Overrides:
getCurrentDrawAmps
in classLinearSystemSim<N2,N1,N1>
- Returns:
- The aram current draw.
-
setInputVoltage
Sets the input voltage for the arm.- Parameters:
volts
- The input voltage.
-
estimateMOI
Calculates a rough estimate of the moment of inertia of an arm given its length and mass.- Parameters:
lengthMeters
- The length of the arm.massKg
- The mass of the arm.- Returns:
- The calculated moment of inertia.
-
updateX
Updates the state of the arm.- Overrides:
updateX
in classLinearSystemSim<N2,N1,N1>
- Parameters:
currentXhat
- The current state estimate.u
- The system inputs (voltage).dtSeconds
- The time difference between controller updates.- Returns:
- The new state.
-