import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.math.system.plant.DCMotor;
+import edu.wpi.first.math.system.plant.LinearSystemId;
import edu.wpi.first.math.util.Units;
+import edu.wpi.first.units.VelocityUnit;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.simulation.ElevatorSim;
+import edu.wpi.first.wpilibj.simulation.FlywheelSim;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
/** Left motor (slave) */
private TalonFX leftMotor = new TalonFX(IntakeConstants.leftID, Constants.CANIVORE_SUB);
+ /** Motor characteristics for the roller motor, a Kraken X44 (aka gearbox) */
+ private final DCMotor dcMotorRoller = DCMotor.getKrakenX44(1);
/** Motor characteristics for the extending pair of Kraken X44 motors (aka gearbox) */
- private final DCMotor dcMotor = DCMotor.getKrakenX44(2);
+ private final DCMotor dcMotorExtend = DCMotor.getKrakenX44(2);
private double maxVelocity;
private double maxAcceleration;
+
+ private FlywheelSim rollerSim;
private ElevatorSim intakeSim;
+
private double distance;
private final MotionMagicVoltage voltageRequest = new MotionMagicVoltage(0);
public Intake() {
// get the maximum free speed
- double mechFreeSpeed = Units.radiansToRotations(dcMotor.freeSpeedRadPerSec)/ IntakeConstants.gearRatio;
+ double mechFreeSpeed = Units.radiansToRotations(dcMotorExtend.freeSpeedRadPerSec)/ IntakeConstants.gearRatio;
// this is confusing
maxVelocity = 0.5 * mechFreeSpeed;
if (RobotBase.isSimulation()) {
// build the simulation resources
+ // Extender
// the supply voltage should change with load....
rightMotor.getSimState().setSupplyVoltage(12.0);
double maxHeightMeters = Units.inchesToMeters(IntakeConstants.maxExtension);
double startingHeightMeters = Units.inchesToMeters(0.0);
intakeSim = new ElevatorSim(
- dcMotor,
+ dcMotorExtend,
IntakeConstants.gearRatio,
carriageMassKg,
drumRadiusMeters,
maxHeightMeters,
false,
startingHeightMeters);
+
+ // Roller
+ double moi = 0.25;
+ double gearing = 2.0;
+ rollerSim = new FlywheelSim(
+ LinearSystemId.createFlywheelSystem(dcMotorRoller, moi, gearing),
+ dcMotorRoller);
}
}
double inchExtension = getPosition();
SmartDashboard.putNumber("Intake Position:", inchExtension);
robotExtension.setLength(inchExtension);
+
+ // this returns rotations per second.
+ double velocity = rollerMotor.getVelocity().getValueAsDouble();
+ SmartDashboard.putNumber("Roller Velocity", velocity);
}
public void simulationPeriodic(){
// update the display
robotExtension.setLength(inchesExtend);
+
+ // simulate roller
+ voltage = rollerMotor.getMotorVoltage().getValueAsDouble();
+ rollerSim.setInputVoltage(voltage);
+ rollerSim.update(0.020);
+ // FIXME: get the simulated velocity
+ double velocity = 51.9; // rollerSim.getAngularVelocity();
+ rollerMotor.getSimState().setRotorVelocity(velocity);
}
/**
public double getPosition(){
double motorRotations = rightMotor.getPosition().getValueAsDouble();
return rotationsToInches(motorRotations);
-
}
/**
return distance == IntakeConstants.maxExtension; // TODO add tolerance for distance
}
-
public void spin(double speed) {
rollerMotor.set(speed);
}
public void extend() {
setPosition(IntakeConstants.maxExtension);
-
}
public void retract(){
rightMotor.close();
rollerMotor.close();
}
-
}