Package frc.robot.devices.motor
Class AbstractSimMotor
java.lang.Object
frc.robot.devices.motor.AbstractMotor
frc.robot.devices.motor.AbstractSimMotor
- Direct Known Subclasses:
AbstractVelocitySimMotor,HarvesterSimMotor,TurretSimMotor
Abstract simulation-only motor wrapper that mirrors
AbstractMotor behavior while using REV simulation helpers.
This class pairs a SparkMaxSim with a DCMotorSim so the simulated Spark MAX follows the same control modes, soft limits, and
conversion factors as the real robot. Motion is modeled in radians and seconds to match the rest of the robot math.
-
Nested Class Summary
Nested classes/interfaces inherited from interface frc.robot.devices.motor.MotorIO
MotorIO.MotorIOInputs -
Field Summary
Fields inherited from class frc.robot.devices.motor.AbstractMotor
log, motor, name, NOMINAL_VOLTAGE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSimMotor(String name, MotorConfig config, Supplier<Double> maximumVelocityDegreesPerSecondSupplier, Supplier<Double> maximumAccelerationDegreesPerSecondSqSupplier) Creates a simulated motor using the default NEO motor model.protectedAbstractSimMotor(String name, MotorConfig config, Supplier<Double> maximumVelocityDegreesPerSecondSupplier, Supplier<Double> maximumAccelerationDegreesPerSecondSqSupplier, edu.wpi.first.math.system.plant.DCMotor motorModel) Creates a simulated motor using an explicit motor model for improved realism. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.revrobotics.spark.config.SparkMaxConfigconfigureMotor(com.revrobotics.spark.config.SparkMaxConfig sparkConfig) Applies the base configuration for the simulated Spark MAX.voidsetEncoderPosition(double positionRadians) Overwrites the real encoder, the SparkMaxSim, and the physics model position.voidupdateInputs(MotorIO.MotorIOInputs inputs) Updates the physics model and then exports sensor values from the simulated Spark MAX.Methods inherited from class frc.robot.devices.motor.AbstractMotor
computeMechanismRadiansPerMotorRotation, getPositionRadians, getVelocityRadiansPerSecond, getVoltage, init, isInitialized, setVoltage, stop
-
Constructor Details
-
Method Details
-
updateInputs
Updates the physics model and then exports sensor values from the simulated Spark MAX.- Specified by:
updateInputsin interfaceMotorIO- Overrides:
updateInputsin classAbstractMotor- Parameters:
inputs- mutable inputs container to fill for logging
-
setEncoderPosition
public void setEncoderPosition(double positionRadians) Overwrites the real encoder, the SparkMaxSim, and the physics model position.All three position stores must stay in sync. Without updating the DCMotorSim, the physics model starts from a stale position and soft-limit clamping prevents it from ever reaching the encoder's reported value; the motor appears frozen in telemetry.
- Specified by:
setEncoderPositionin interfaceMotor- Overrides:
setEncoderPositionin classAbstractMotor- Parameters:
positionRadians- new encoder position in mechanism radians
-
configureMotor
protected com.revrobotics.spark.config.SparkMaxConfig configureMotor(com.revrobotics.spark.config.SparkMaxConfig sparkConfig) Applies the base configuration for the simulated Spark MAX.This mirrors the inversion, current limits, and voltage compensation used on the real controller so the simulation follows the same control assumptions.
- Specified by:
configureMotorin classAbstractMotor- Parameters:
sparkConfig- base SparkMax config to mutate- Returns:
- updated SparkMax config ready for
SparkMax.configure(com.revrobotics.spark.config.SparkBaseConfig, com.revrobotics.spark.SparkBase.ResetMode, com.revrobotics.spark.SparkBase.PersistMode)
-