Skip to content

Commit cbdbd94

Browse files
committed
2 parents 1f75b6f + 5bdf350 commit cbdbd94

File tree

5 files changed

+176
-2
lines changed

5 files changed

+176
-2
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package frc.team5115.subsystems.intakewheel;
2+
3+
import com.revrobotics.spark.SparkMax;
4+
import edu.wpi.first.wpilibj2.command.Command;
5+
import edu.wpi.first.wpilibj2.command.Commands;
6+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
7+
import java.util.ArrayList;
8+
import java.util.function.BooleanSupplier;
9+
import org.littletonrobotics.junction.Logger;
10+
11+
public class IntakeWheel extends SubsystemBase {
12+
private static final double INTAKE_SPEED = 0.15;
13+
private final IntakeWheelIO io;
14+
private final IntakeWheelIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged();
15+
16+
public IntakeWheel(IntakeIO io) {
17+
this.io = io;
18+
}
19+
20+
@Override
21+
public void periodic() {
22+
io.updateInputs(inputs);
23+
Logger.processInputs("Intake", inputs);
24+
}
25+
26+
public Command setSpeed(double speed) {
27+
return Commands.runOnce(() -> io.setPercent(speed));
28+
}
29+
30+
public Command intake() {
31+
return setSpeed(INTAKE_SPEED);
32+
}
33+
34+
public Command vomit() {
35+
return setSpeed(-0.22);
36+
}
37+
38+
public Command stop() {
39+
return setSpeed(0);
40+
}
41+
42+
public void getSparks(ArrayList<SparkMax> sparks) {
43+
io.getSparks(sparks);
44+
}
45+
46+
public Command intakeIf(BooleanSupplier supplier) {
47+
return Commands.run(
48+
() -> {
49+
if (supplier.getAsBoolean()) {
50+
// stall means we back it up a little and try again
51+
if (inputs.currentAmps > 25.0) {
52+
io.setPercent(-0.22);
53+
} else {
54+
io.setPercent(INTAKE_SPEED);
55+
}
56+
} else {
57+
io.setPercent(0);
58+
}
59+
},
60+
this);
61+
}
62+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package frc.team5115.subsystems.intakewheel;
2+
3+
import com.revrobotics.spark.SparkMax;
4+
import java.util.ArrayList;
5+
import org.littletonrobotics.junction.AutoLog;
6+
7+
public interface IntakeWheelIO {
8+
@AutoLog
9+
public static class IntakeWheelIOInputs {
10+
public double velocityRPM = 0.0;
11+
public double appliedVolts = 0.0;
12+
public double currentAmps = 0.0;
13+
}
14+
15+
/** Updates the set of loggable inputs. */
16+
public default void updateInputs(IntakeWheelIOInputs inputs) {}
17+
18+
/** Run the intake motor at the specified voltage. */
19+
public default void setVoltage(double volts) {}
20+
21+
/** Run the intake motor at the specified percentage. */
22+
public default void setPercent(double percent) {}
23+
24+
/** This should not really be here but it must be */
25+
public default void getSparks(ArrayList<SparkMax> sparks) {}
26+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package frc.team5115.subsystems.intakewheel;
2+
3+
import edu.wpi.first.math.MathUtil;
4+
import edu.wpi.first.math.system.plant.DCMotor;
5+
import edu.wpi.first.math.system.plant.LinearSystemId;
6+
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
7+
import frc.team5115.Constants;
8+
9+
public class IntakeWheelIOSim implements IntakeWheelIO {
10+
private final DCMotorSim sim;
11+
private double appliedVolts;
12+
13+
public IntakeWheelIOSim() {
14+
final DCMotor motor = DCMotor.getNEO(1);
15+
sim = new DCMotorSim(LinearSystemId.createDCMotorSystem(motor, 0.0002, 1.0), motor);
16+
}
17+
18+
@Override
19+
public void updateInputs(IntakeWheelIOInputs inputs) {
20+
sim.update(Constants.LOOP_PERIOD_SECS);
21+
inputs.velocityRPM = sim.getAngularVelocityRPM();
22+
inputs.appliedVolts = appliedVolts;
23+
inputs.currentAmps = Math.abs(sim.getCurrentDrawAmps());
24+
}
25+
26+
@Override
27+
public void setVoltage(double volts) {
28+
appliedVolts = MathUtil.clamp(volts, -12.0, +12.0);
29+
sim.setInputVoltage(appliedVolts);
30+
}
31+
32+
@Override
33+
public void setPercent(double percent) {
34+
appliedVolts = MathUtil.clamp(percent * 12, -12.0, +12.0);
35+
sim.setInputVoltage(appliedVolts);
36+
}
37+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package frc.team5115.subsystems.intakewheel;
2+
3+
import com.revrobotics.RelativeEncoder;
4+
import com.revrobotics.spark.SparkBase.PersistMode;
5+
import com.revrobotics.spark.SparkBase.ResetMode;
6+
import com.revrobotics.spark.SparkLowLevel.MotorType;
7+
import com.revrobotics.spark.SparkMax;
8+
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
9+
import com.revrobotics.spark.config.SparkMaxConfig;
10+
import frc.team5115.Constants;
11+
import java.util.ArrayList;
12+
13+
public class IntakeWheelIOSparkMax implements IntakeWheelIO {
14+
private final SparkMax motor;
15+
private final RelativeEncoder encoder;
16+
17+
public IntakeWheelIOSparkMax() {
18+
motor = new SparkMax(Constants.INTAKE_MOTOR_ID, MotorType.kBrushless);
19+
encoder = motor.getEncoder();
20+
21+
final SparkMaxConfig motorConfig = new SparkMaxConfig();
22+
motorConfig.smartCurrentLimit(30, 40).idleMode(IdleMode.kCoast);
23+
motor.configure(motorConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
24+
}
25+
26+
@Override
27+
public void updateInputs(IntakeWheelIOInputs inputs) {
28+
inputs.velocityRPM = encoder.getVelocity();
29+
inputs.appliedVolts = motor.getAppliedOutput() * motor.getBusVoltage();
30+
inputs.currentAmps = motor.getOutputCurrent();
31+
}
32+
33+
@Override
34+
public void setPercent(double percent) {
35+
motor.set(percent);
36+
}
37+
38+
@Override
39+
public void setVoltage(double volts) {
40+
motor.setVoltage(volts);
41+
}
42+
43+
@Override
44+
public void getSparks(ArrayList<SparkMax> sparks) {
45+
sparks.add(motor);
46+
}
47+
}

the evil table.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
Intake
1+
Intake Wheel
22
- Single wheel - Motor
3-
- Arm - Motor
43
- Spin wheel to intake, Move arm up to trade off, Spin wheel to trade.
54

5+
Intake Arm
6+
- Arm - Motor
7+
68
Defacator
79
- Arm - Pnumatic
810
- Wait till three Lunites (Sensor? Count Variable?), Move up arm

0 commit comments

Comments
 (0)