public static final int leftID = 2;
public static final int rollerID = 3;
+ //Motor speed
+ public static final double speed = 0.2;
+ public static final double gearRatio = 3;
+ public static final double radius = 0.5;
+
+ public static final double statorLimitAmps = 50.0;
+ public static final double supplyLimitAmps = 40.0;
+
// Intake positions
public static final double maxExtension = 12; // in inches: convert to rotations later
public static final double startingPoint = 0;
+ public static final double rackPitch = 10;
// for simulation
public static final double kMaxRotations = 37.5;
- public static final double kMaxVisualLength = 0.75;
}
import com.ctre.phoenix6.signals.MotorAlignmentValue;
import com.ctre.phoenix6.signals.MotorArrangementValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
+import com.fasterxml.jackson.databind.ser.std.InetAddressSerializer;
import com.revrobotics.spark.config.SparkMaxConfig;
+import edu.wpi.first.math.system.plant.DCMotor;
+import edu.wpi.first.wpilibj.simulation.DCMotorSim;
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
private TalonFX rollerMotor;
private TalonFX rightMotor; //leader
private TalonFX leftMotor; //invert this one
+ private double maxVelocity;
+ private double maxAcceleration;
+ private DCMotorSim intakeSim;
private MotionMagicVoltage voltageRequest = new MotionMagicVoltage(0);
rightMotor = new TalonFX(IntakeConstants.rightID);
leftMotor = new TalonFX(IntakeConstants.leftID);
rollerMotor = new TalonFX(IntakeConstants.rollerID);
+ DCMotor dcmotor = DCMotor.getKrakenX44(2);
// right motor configs
TalonFXConfiguration Config = new TalonFXConfiguration();
slot0Configs.kV = 0;
slot0Configs.kA = 0;
+
+ var currentLimits = Config.CurrentLimits;
+ currentLimits.StatorCurrentLimitEnable = true;
+ currentLimits.StatorCurrentLimit = IntakeConstants.statorLimitAmps;
+ currentLimits.SupplyCurrentLimitEnable = true;
+ currentLimits.SupplyCurrentLimit = IntakeConstants.supplyLimitAmps;
+
+ var motionMagicConfigs = Config.MotionMagic;
+
+ motionMagicConfigs.MotionMagicCruiseVelocity = IntakeConstants.gearRatio * maxVelocity/IntakeConstants.radius/Math.PI/2;
+ motionMagicConfigs.MotionMagicAcceleration = IntakeConstants.gearRatio * maxAcceleration/IntakeConstants.radius/Math.PI/2;
rightMotor.getConfigurator().apply(new MotorOutputConfigs().withNeutralMode(NeutralModeValue.Brake));
rightMotor.getConfigurator().apply(Config);
// report the position of the extension
double percentExtended = getPosition() / IntakeConstants.kMaxRotations;
-
+ double distance = percentExtended/IntakeConstants.gearRatio * 1/IntakeConstants.rackPitch; // in inches
percentExtended = Math.max(0.0, Math.min(1.0, percentExtended));
// robotExtension.setLength(percentExtended * maxExtension);
public void simulationPeriodic(){
// simulate the motor activity
+ double voltage = rightMotor.getMotorVoltage().getValueAsDouble();
+ intakeSim.setInputVoltage(voltage);
+ intakeSim.update(0.02);
+ // rackPitch in teeth/inch
+ double mechanicalRotation = intakeSim.getAngularPositionRotations();
+ double motorRotation = mechanicalRotation * IntakeConstants.gearRatio;
+ //convert motor rotation to distance
+
+
+
+
}
/**
}
/**
- * gets the position in rotations
+ * gets motor position in inches
*/
public double getPosition(){
double position = rightMotor.getPosition().getValueAsDouble();
}
public void spin(double speed) {
- rollerMotor.set(0.2);
+ rollerMotor.set(IntakeConstants.speed);
}
public void extend() {