Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,6 @@ compile_commands.json

# Eclipse generated file for annotation processors
.factorypath

# Build Constants
src/main/java/frc/robot/BuildConstants.java
3 changes: 1 addition & 2 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
],
"robotJoysticks": [
{
"guid": "78696e70757401000000000000000000",
"useGamepad": true
"guid": "Keyboard0"
}
]
}
17 changes: 0 additions & 17 deletions src/main/java/frc/robot/BuildConstants.java

This file was deleted.

419 changes: 25 additions & 394 deletions src/main/java/frc/robot/Constants.java

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.Constants.Ports;
import frc.robot.commands.drive.DriveCommands;
import frc.robot.oi.DriverControls;
import frc.robot.oi.DriverControlsPS5;
import frc.robot.subsystems.drive.Drive;
import frc.robot.subsystems.drive.GyroIOPigeon2;
import frc.robot.subsystems.drive.ModuleIOSim;
import frc.robot.subsystems.drive.ModuleIOTalonFX;
import frc.robot.subsystems.spindexer.Spindexer;
import frc.robot.subsystems.spindexer.Spindexer.SpindexerState;
import frc.robot.subsystems.spindexer.SpindexerIOKraken;
import frc.robot.subsystems.spindexer.SpindexerIOSim;
import org.littletonrobotics.junction.networktables.LoggedDashboardChooser;

public class RobotContainer {

private Drive m_drive;
private Spindexer m_spindexer;

// Controller
private DriverControls m_driverControls;
private DriverControls m_controller;

// Dashboard inputs
private LoggedDashboardChooser<Command> m_autoChooser;
Expand All @@ -39,6 +45,7 @@ public void configureSubsystems() {
new ModuleIOTalonFX(1),
new ModuleIOTalonFX(2),
new ModuleIOTalonFX(3));
m_spindexer = new Spindexer(new SpindexerIOKraken(Ports.kSpindexer, Ports.kMainCanivoreName));
} else {
m_drive =
new Drive(
Expand All @@ -47,6 +54,7 @@ public void configureSubsystems() {
new ModuleIOSim(),
new ModuleIOSim(),
new ModuleIOSim());
m_spindexer = new Spindexer(new SpindexerIOSim());
}
}

Expand All @@ -55,24 +63,37 @@ public void configureCommands() {
}

public void configureControllers() {
m_driverControls = new DriverControlsPS5(0);
m_controller = new DriverControlsPS5(0);
}

public void configureBindings() {
m_drive.setDefaultCommand(
DriveCommands.joystickDrive(
m_drive,
m_driverControls::getForward,
m_driverControls::getStrafe,
m_driverControls::getTurn,
m_controller::getForward,
m_controller::getStrafe,
m_controller::getTurn,
false));
m_driverControls
m_controller
.resetFieldCentric()
.onTrue(
Commands.runOnce(
() -> {
m_drive.setPose(new Pose2d());
}));

// will be removed once it goes on the actual robot (always spins)
m_controller
.spin()
.onTrue(
Commands.runOnce(
() -> {
if (m_spindexer.getCurrentState() == SpindexerState.kSpinning) {
m_spindexer.updateState(SpindexerState.kIdle);
} else {
m_spindexer.updateState(SpindexerState.kSpinning);
}
}));
}

public Command getAutonomousCommand() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/RobotState.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum RobotAction {
}

private Drive m_drive;

private SubsystemProfiles<RobotAction> m_profiles;
private static RobotState m_instance;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/oi/DriverControls.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface DriverControls {
public double getTurn();

public Trigger resetFieldCentric();

public Trigger spin();
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/oi/DriverControlsPS5.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public double getTurn() {
public Trigger resetFieldCentric() {
return m_controller.touchpad();
}

@Override
public Trigger spin() {
return m_controller.cross();
}
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/oi/DriverControlsXbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public double getTurn() {
public Trigger resetFieldCentric() {
return m_controller.start();
}

@Override
public Trigger spin() {
return m_controller.a();
}
}
58 changes: 58 additions & 0 deletions src/main/java/frc/robot/subsystems/spindexer/Spindexer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package frc.robot.subsystems.spindexer;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.SpindexerConstants;
import frc.robot.util.SubsystemProfiles;
import java.util.HashMap;
import java.util.Map;
import org.littletonrobotics.junction.Logger;

public class Spindexer extends SubsystemBase {
private SpindexerIO m_io;
public final SpindexerInputsAutoLogged m_inputs = new SpindexerInputsAutoLogged();

private SubsystemProfiles<SpindexerState> m_profiles;

public static enum SpindexerState {
kIdle,
kSpinning,
}

public Spindexer(SpindexerIO spindexerIO) {
m_io = spindexerIO;
Map<SpindexerState, Runnable> periodicHash = new HashMap<>();
periodicHash.put(SpindexerState.kIdle, this::idlePeriodic);
periodicHash.put(SpindexerState.kSpinning, this::spinningPeriodic);

m_profiles = new SubsystemProfiles<>(periodicHash, SpindexerState.kIdle);
}

@Override
public void periodic() {
m_io.updateInputs(m_inputs);
m_profiles.getPeriodicFunctionTimed().run();

Logger.processInputs("Spindexer", m_inputs);
Logger.recordOutput("Spindexer/state", m_profiles.getCurrentProfile());
}

public void idlePeriodic() {
m_io.setVoltage(SpindexerConstants.kIdleVoltage.get());
}

public void spinningPeriodic() {
m_io.setVoltage(SpindexerConstants.kSpinningVoltage.get());
}

public void updateState(SpindexerState state) {
m_profiles.setCurrentProfile(state);
}

public SpindexerState getCurrentState() {
return m_profiles.getCurrentProfile();
}

public double getCurrentVelocity() {
return m_inputs.velocityRPS;
}
}
22 changes: 22 additions & 0 deletions src/main/java/frc/robot/subsystems/spindexer/SpindexerIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package frc.robot.subsystems.spindexer;

import org.littletonrobotics.junction.AutoLog;

public interface SpindexerIO {
@AutoLog
public static class SpindexerInputs {
public double velocityRPS;
public double accelerationRPSSq;
public double current;
public double statorCurrent;
public double voltage;
public double temperature;
public boolean motorIsConnected;
}

public void updateInputs(SpindexerInputs inputs);

public void setVoltage(double voltage);

public void setCurrentLimits(double supplyLimit);
}
128 changes: 128 additions & 0 deletions src/main/java/frc/robot/subsystems/spindexer/SpindexerIOKraken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package frc.robot.subsystems.spindexer;

import static edu.wpi.first.units.Units.Amps;
import static edu.wpi.first.units.Units.Celsius;
import static edu.wpi.first.units.Units.RotationsPerSecond;
import static edu.wpi.first.units.Units.Volts;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
import com.ctre.phoenix6.configs.FeedbackConfigs;
import com.ctre.phoenix6.configs.MotorOutputConfigs;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.VoltageOut;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.ConnectedMotorValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.units.measure.AngularVelocity;
import edu.wpi.first.units.measure.Current;
import edu.wpi.first.units.measure.Temperature;
import edu.wpi.first.units.measure.Voltage;
import frc.robot.Constants;
import frc.robot.Constants.CurrentLimitConstants;
import frc.robot.Constants.SpindexerConstants;
import frc.robot.util.CtreBaseRefreshManager;
import java.util.List;

public class SpindexerIOKraken implements SpindexerIO {

private TalonFX m_motor;

private StatusSignal<ConnectedMotorValue> m_connectedMotor;
private StatusSignal<Voltage> m_motorVoltage;
private StatusSignal<AngularVelocity> m_motorVelocity;
private StatusSignal<Current> m_motorCurrent;
private StatusSignal<Current> m_motorStatorCurrent;
private StatusSignal<Temperature> m_motorTemperature;

private final TalonFXConfiguration m_config;

private VoltageOut m_voltageOut = new VoltageOut(0.0).withEnableFOC(true);

public SpindexerIOKraken(int Port, String Bus) {
m_motor = new TalonFX(Port, Bus);

var currentLimits =
new CurrentLimitsConfigs()
.withSupplyCurrentLimitEnable(true)
.withSupplyCurrentLimit(CurrentLimitConstants.kSpindexerDefaultSupplyLimit)
.withStatorCurrentLimitEnable(true)
.withStatorCurrentLimit(CurrentLimitConstants.kSpindexerDefaultStatorLimit);

var feedbackConfig =
new FeedbackConfigs().withSensorToMechanismRatio(SpindexerConstants.kGearRatio);

var motorOutput = new MotorOutputConfigs().withNeutralMode(NeutralModeValue.Brake);

m_config =
new TalonFXConfiguration()
.withCurrentLimits(currentLimits)
.withFeedback(feedbackConfig)
.withMotorOutput(motorOutput);

m_motor.getConfigurator().apply(m_config);

m_connectedMotor = m_motor.getConnectedMotor();
m_motorVelocity = m_motor.getVelocity();
m_motorCurrent = m_motor.getSupplyCurrent();
m_motorStatorCurrent = m_motor.getStatorCurrent();
m_motorVoltage = m_motor.getMotorVoltage();
m_motorTemperature = m_motor.getDeviceTemp();

BaseStatusSignal.setUpdateFrequencyForAll(
75.0,
m_connectedMotor,
m_motorVelocity,
m_motorCurrent,
m_motorStatorCurrent,
m_motorVoltage,
m_motorTemperature);

if (Constants.kUseBaseRefreshManager) {
CtreBaseRefreshManager.addSignals(
List.of(
m_connectedMotor,
m_motorVelocity,
m_motorCurrent,
m_motorStatorCurrent,
m_motorVoltage,
m_motorTemperature));
}
}

@Override
public void updateInputs(SpindexerInputs inputs) {
if (!Constants.kUseBaseRefreshManager) {
BaseStatusSignal.refreshAll(
null,
m_connectedMotor,
m_motorVelocity,
m_motorCurrent,
m_motorStatorCurrent,
m_motorVoltage,
m_motorTemperature)
.isOK();
}

inputs.motorIsConnected = m_connectedMotor.getValue() != ConnectedMotorValue.Unknown;

inputs.velocityRPS = m_motorVelocity.getValue().in(RotationsPerSecond);
inputs.current = m_motorCurrent.getValue().in(Amps);
inputs.statorCurrent = m_motorStatorCurrent.getValue().in(Amps);
inputs.voltage = m_motorVoltage.getValue().in(Volts);
inputs.temperature = m_motorTemperature.getValue().in(Celsius);
}

@Override
public void setVoltage(double voltage) {
m_motor.setControl(m_voltageOut.withOutput(voltage));
}

@Override
public void setCurrentLimits(double supplyLimit) {
m_motor
.getConfigurator()
.apply(m_config.CurrentLimits.withSupplyCurrentLimit(supplyLimit), 0.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package frc.robot.subsystems.spindexer;

public class SpindexerIOReplay implements SpindexerIO {
@Override
public void updateInputs(SpindexerInputs inputs) {}

@Override
public void setVoltage(double voltage) {}

@Override
public void setCurrentLimits(double supplyLimit) {}
}
Loading