Class SingleJointedArmSim
Represents a simulated single jointed arm mechanism.
-
Field Summary
Fields inherited from class LinearSystemSim
m_measurementStdDevs, m_plant, m_u, m_x, m_y -
Constructor Summary
ConstructorsConstructorDescriptionSingleJointedArmSim(DCMotor gearbox, double gearing, double j, double armLength, double minAngleRads, double maxAngleRads, boolean simulateGravity, double startingAngleRads, double... measurementStdDevs) Creates a simulated arm mechanism.SingleJointedArmSim(LinearSystem<N2, N1, N2> plant, DCMotor gearbox, double gearing, double armLength, double minAngleRads, double maxAngleRads, boolean simulateGravity, double startingAngleRads, double... measurementStdDevs) Creates a simulated arm mechanism. -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleestimateMOI(double length, double mass) Calculates a rough estimate of the moment of inertia of an arm given its length and mass.doublegetAngle()Returns the current arm angle.doubleReturns the arm current draw.doubleReturns the current arm velocity.booleanReturns whether the arm has hit the lower limit.booleanReturns whether the arm has hit the upper limit.voidsetInputVoltage(double volts) Sets the input voltage for the arm.final voidsetState(double angleRadians, double velocityRadPerSec) Sets the arm's state.Updates the state of the arm.booleanwouldHitLowerLimit(double currentAngleRads) Returns whether the arm would hit the lower limit.booleanwouldHitUpperLimit(double currentAngleRads) Returns whether the arm would hit the upper limit.
-
Constructor Details
-
SingleJointedArmSim
public SingleJointedArmSim(LinearSystem<N2, N1, N2> plant, DCMotor gearbox, double gearing, double armLength, double minAngleRads, double maxAngleRads, boolean simulateGravity, double startingAngleRads, double... measurementStdDevs) Creates a simulated arm mechanism.- Parameters:
plant- The linear system that represents the arm. This system can be created withModels.singleJointedArmFromPhysicalConstants(DCMotor, double, double).gearbox- The type of and number of motors in the arm gearbox.gearing- The gearing of the arm (numbers greater than 1 represent reductions).armLength- The length of the arm in meters.minAngleRads- The minimum angle that the arm is capable of, with 0 radians being horizontal.maxAngleRads- The maximum angle that the arm is capable of, with 0 radians being horizontal.simulateGravity- Whether gravity should be simulated or not.startingAngleRads- The initial position of the Arm simulation in radians, with 0 radians being horizontal.measurementStdDevs- The standard deviations of the measurements. Can be omitted if no noise is desired. If present must have 1 element for position.
-
SingleJointedArmSim
public SingleJointedArmSim(DCMotor gearbox, double gearing, double j, double armLength, double minAngleRads, double maxAngleRads, boolean simulateGravity, double startingAngleRads, double... 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).j- The moment of inertia of the arm in kg-m²; can be calculated from CAD software.armLength- The length of the arm in meters.minAngleRads- The minimum angle that the arm is capable of, with 0 radians being horizontal.maxAngleRads- The maximum angle that the arm is capable of, with 0 radians being horizontal.simulateGravity- Whether gravity should be simulated or not.startingAngleRads- The initial position of the Arm simulation in radians, with 0 radians being horizontal.measurementStdDevs- The standard deviations of the measurements. Can be omitted if no noise is desired. If present must have 1 element for position.
-
-
Method Details
-
setState
public final void setState(double angleRadians, double velocityRadPerSec) Sets the arm's state. The new angle will be limited between the minimum and maximum allowed limits.- Parameters:
angleRadians- The new angle in radians.velocityRadPerSec- The new angular velocity in radians per second.
-
wouldHitLowerLimit
public boolean wouldHitLowerLimit(double currentAngleRads) 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
public boolean wouldHitUpperLimit(double currentAngleRads) 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
public boolean hasHitLowerLimit()Returns whether the arm has hit the lower limit.- Returns:
- Whether the arm has hit the lower limit.
-
hasHitUpperLimit
public boolean hasHitUpperLimit()Returns whether the arm has hit the upper limit.- Returns:
- Whether the arm has hit the upper limit.
-
getAngle
public double getAngle()Returns the current arm angle.- Returns:
- The current arm angle in radians.
-
getVelocity
public double getVelocity()Returns the current arm velocity.- Returns:
- The current arm velocity in radians per second.
-
getCurrentDraw
public double getCurrentDraw()Returns the arm current draw.- Returns:
- The arm current draw in amps.
-
setInputVoltage
public void setInputVoltage(double volts) Sets the input voltage for the arm.- Parameters:
volts- The input voltage.
-
estimateMOI
public static double estimateMOI(double length, double mass) Calculates a rough estimate of the moment of inertia of an arm given its length and mass.- Parameters:
length- The length of the arm in m.mass- The mass of the arm in kg.- Returns:
- The calculated moment of inertia in kg-m².
-
updateX
Updates the state of the arm.- Overrides:
updateXin classLinearSystemSim<N2,N1, N2> - Parameters:
currentXhat- The current state estimate.u- The system inputs (voltage).dt- The time difference between controller updates in seconds.- Returns:
- The new state.
-