-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: AwesomeDustin4 <[email protected]> Co-authored-by: djjamin <[email protected]> Co-authored-by: Lia M <[email protected]> Co-authored-by: Sophie B <[email protected]>
- Loading branch information
1 parent
167d038
commit 6f7f2f3
Showing
6 changed files
with
236 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2024 - 2025 : FRC 2106 : The Junkyard Dogs | ||
// https://www.team2106.org | ||
|
||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file at | ||
// the root directory of this project. | ||
|
||
package frc.robot.elevator; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
import org.littletonrobotics.junction.LogTable; | ||
import org.littletonrobotics.junction.inputs.LoggableInputs; | ||
|
||
/// | ||
/// | ||
/// // | ||
public interface IO_ElevatorBase { | ||
|
||
@AutoLog | ||
public static class ElevatorInputs implements LoggableInputs { | ||
|
||
public double heightM = 0.0; | ||
public double velocityMPS = 0.0; | ||
public double motorOneCurrent = 0.0; | ||
public double motorTwoCurrent = 0.0; | ||
|
||
@Override | ||
public void toLog(LogTable table) { | ||
table.put("heightM", heightM); | ||
table.put("velocityMPS", velocityMPS); | ||
table.put("motorOneCurrent", motorOneCurrent); | ||
table.put("motorTwoCurrent", motorTwoCurrent); | ||
} | ||
|
||
@Override | ||
public void fromLog(LogTable table) { | ||
heightM = table.get("heightM", heightM); | ||
velocityMPS = table.get("velocityMPS", velocityMPS); | ||
motorOneCurrent = table.get("motorOneCurrent", motorOneCurrent); | ||
motorTwoCurrent = table.get("motorTwoCurrent", motorTwoCurrent); | ||
} | ||
} | ||
|
||
/** Updates the set of loggable inputs. */ | ||
public void updateInputs(ElevatorInputs inputs); | ||
|
||
public void setPositionM(double positionM); | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/frc/robot/elevator/IO_ElevatorRealKracken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2024 - 2025 : FRC 2106 : The Junkyard Dogs | ||
// https://www.team2106.org | ||
|
||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file at | ||
// the root directory of this project. | ||
|
||
package frc.robot.elevator; | ||
|
||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.controls.MotionMagicVoltage; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
|
||
public class IO_ElevatorRealKracken implements IO_ElevatorBase { | ||
|
||
private final TalonFX motorOne; | ||
private final TalonFX motorTwo; | ||
private final MotionMagicVoltage motorRequest; | ||
|
||
// private SparkMax motorOne; | ||
// private SparkMax motorTwo; | ||
|
||
public IO_ElevatorRealKracken() { | ||
motorOne = new TalonFX(0); | ||
motorTwo = new TalonFX(0); | ||
motorRequest = new MotionMagicVoltage(0); | ||
|
||
var motorConfigs = new TalonFXConfiguration(); | ||
|
||
// One rotation = X meters of linear travel | ||
// Calculate: (Sprocket Circumference in meters) / (Total Gear Reduction) | ||
// Example: (0.1524 meters per rotation) / (5:1 gear ratio) = 0.03048 meters per motor rotation | ||
double METERS_PER_MOTOR_ROTATION = 0.03048; | ||
|
||
var slot0Configs = motorConfigs.Slot0; | ||
slot0Configs.kS = 0.25; // Add 0.25 V output to overcome static friction | ||
slot0Configs.kV = 0.12; // A velocity target of 1 rps results in 0.12 V output | ||
slot0Configs.kA = 0.01; // An acceleration of 1 rps/s requires 0.01 V output | ||
slot0Configs.kP = 0.11; // An error of 1 rps results in 0.11 V output | ||
slot0Configs.kI = 0; // no output for integrated error | ||
slot0Configs.kD = 0; // no output for error derivative | ||
|
||
// Convert to meters | ||
motorConfigs.Feedback.SensorToMechanismRatio = METERS_PER_MOTOR_ROTATION; | ||
|
||
var motionMagicConfigs = motorConfigs.MotionMagic; | ||
motionMagicConfigs.MotionMagicCruiseVelocity = 2.0; // meters per second | ||
motionMagicConfigs.MotionMagicAcceleration = 4.0; // meters per second squared | ||
motionMagicConfigs.MotionMagicJerk = 40.0; // meters per second cubed | ||
|
||
motorOne.getConfigurator().apply(motorConfigs); | ||
motorTwo.getConfigurator().apply(motorConfigs); | ||
} | ||
|
||
@Override | ||
public void updateInputs(ElevatorInputs inputs) { | ||
inputs.heightM = motorOne.getPosition().getValueAsDouble(); | ||
inputs.velocityMPS = motorOne.getVelocity().getValueAsDouble(); | ||
inputs.motorOneCurrent = motorOne.getSupplyCurrent().getValueAsDouble(); | ||
inputs.motorTwoCurrent = motorTwo.getSupplyCurrent().getValueAsDouble(); | ||
} | ||
|
||
@Override | ||
public void setPositionM(double positionM) { | ||
motorOne.setControl(motorRequest.withPosition(positionM)); | ||
motorTwo.setControl(motorRequest.withPosition(positionM)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024 - 2025 : FRC 2106 : The Junkyard Dogs | ||
// https://www.team2106.org | ||
|
||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file at | ||
// the root directory of this project. | ||
|
||
package frc.robot.elevator; | ||
|
||
import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
import com.revrobotics.spark.SparkMax; | ||
|
||
public class IO_ElevatorRealNeo implements IO_ElevatorBase { | ||
|
||
private SparkMax motorOne; | ||
private SparkMax motorTwo; | ||
|
||
public IO_ElevatorRealNeo() { | ||
|
||
motorOne = new SparkMax(0, MotorType.kBrushless); | ||
motorTwo = new SparkMax(0, MotorType.kBrushless); | ||
} | ||
|
||
@Override | ||
public void updateInputs(ElevatorInputs inputs) { | ||
inputs.heightM = motorOne.getEncoder().getPosition(); | ||
inputs.velocityMPS = motorOne.getEncoder().getVelocity(); | ||
inputs.motorOneCurrent = motorOne.getOutputCurrent(); | ||
inputs.motorTwoCurrent = motorTwo.getOutputCurrent(); | ||
} | ||
|
||
@Override | ||
public void setPositionM(double speed) { | ||
// motorOne.set(speed); | ||
// motorTwo.set(speed); | ||
// Fix this later | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024 - 2025 : FRC 2106 : The Junkyard Dogs | ||
// https://www.team2106.org | ||
|
||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file at | ||
// the root directory of this project. | ||
|
||
package frc.robot.elevator; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class SUB_Elevator extends SubsystemBase { | ||
|
||
public enum State { | ||
STOWED(0.0), | ||
CORAL_STATION(1.0), | ||
ALGAE_GROUND(0.1), | ||
ALGAE_PROCESSOR(0.1), | ||
ALGAE_BARGE(2.9), | ||
L1_SCORING(0.5), | ||
L2_SCORING(0.8), | ||
L3_SCORING(1.2), | ||
L4_SCORING(1.85); | ||
|
||
private final double heightM; | ||
|
||
State(double heightM) { | ||
this.heightM = heightM; | ||
} | ||
|
||
public double getHeightM() { | ||
return heightM; | ||
} | ||
} | ||
|
||
private final IO_ElevatorBase io; | ||
|
||
private final IO_ElevatorBase.ElevatorInputs inputs = new IO_ElevatorBase.ElevatorInputs(); | ||
|
||
public SUB_Elevator(IO_ElevatorBase io) { | ||
this.io = io; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
|
||
// Update inputs | ||
io.updateInputs(inputs); | ||
|
||
// Process inputs | ||
Logger.processInputs("Elevator", inputs); | ||
} | ||
|
||
public Command setState(State state) { | ||
return new InstantCommand( | ||
() -> { | ||
io.setPositionM(state.getHeightM()); | ||
}); | ||
} | ||
} |