Skip to content

Commit

Permalink
IntakeIOSparkMax
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterBiscuit committed Jan 20, 2024
1 parent bb4cc32 commit e91716d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/frc/robot/subsystems/intake/IntakeIOSparkMax.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package frc.robot.subsystems.intake;

import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import edu.wpi.first.math.util.Units;

public class IntakeIOSparkMax implements IntakeIO {
private static final double GEAR_RATIO = 10.0;

// define the 2 SparkMax Controllers. A leader, and a follower
private final CANSparkMax leader = new CANSparkMax(0, MotorType.kBrushless);

// Gets the NEO encoder
private final RelativeEncoder encoder = leader.getEncoder();

public IntakeIOSparkMax() {
// leader motor is not inverted, and set follower motor to follow the leader
leader.setInverted(false);
}

@Override
public void updateInputs(IntakeIOInputs inputs) {
// Set velocityRadPerSec to the encoder velocity(rotationsPerMinute) divided by the gear ratio
// and converted into Radians Per Second
inputs.velocityRadPerSec =
Units.rotationsPerMinuteToRadiansPerSecond(encoder.getVelocity() / GEAR_RATIO);
// Get applied voltage from the leader motor
inputs.appliedVolts = leader.getAppliedOutput() * leader.getBusVoltage();
}

@Override
public void setVoltage(double volts) {
// Set the voltage output for the leader motor
leader.setVoltage(volts);
}
}

0 comments on commit e91716d

Please sign in to comment.