generated from TitaniumTigers4829/4829-BaseRobotCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* juno's intake * IntakeAdvantageKit * Intake Advantagekit Done * Edited intake a bit * Intake edits * Formatting fixes * Worked on coral pivot * fjioe * continued algae pivot * htuiew * gfi * jkjlkjlk --------- Co-authored-by: Ishan1522 <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5d23f26
commit d66622d
Showing
16 changed files
with
545 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
plugins { | ||
id "java" | ||
id "edu.wpi.first.GradleRIO" version "2025.2.1" | ||
|
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
35 changes: 35 additions & 0 deletions
35
src/main/java/frc/robot/commands/algaePivot/ManualAlgaePivot.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,35 @@ | ||
package frc.robot.commands.algaePivot; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.algaePivot.AlgaeConstants; | ||
import frc.robot.subsystems.algaePivot.AlgaePivotSubsystem; | ||
import java.util.function.DoubleSupplier; | ||
|
||
public class ManualAlgaePivot extends Command { | ||
private final AlgaePivotSubsystem algaePivotSubsystem; | ||
private final DoubleSupplier speed; | ||
|
||
public ManualAlgaePivot(AlgaePivotSubsystem algaePivotSubsystem, DoubleSupplier speed) { | ||
this.algaePivotSubsystem = algaePivotSubsystem; | ||
this.speed = speed; | ||
addRequirements(algaePivotSubsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() {} | ||
|
||
@Override | ||
public void execute() { | ||
algaePivotSubsystem.setAlgaeSpeed(speed.getAsDouble()); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
algaePivotSubsystem.setAlgaeSpeed(AlgaeConstants.ALGAE_NEUTRAL_SPEED); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
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,29 @@ | ||
package frc.robot.commands.intake; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.intake.IntakeConstants; | ||
import frc.robot.subsystems.intake.IntakeSubsystem; | ||
|
||
public class Eject extends Command { | ||
private final IntakeSubsystem intakeSubsystem; | ||
|
||
public Eject(IntakeSubsystem intakeSubsystem) { | ||
this.intakeSubsystem = intakeSubsystem; | ||
addRequirements(this.intakeSubsystem); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
intakeSubsystem.setIntakeSpeed(IntakeConstants.EJECT_SPEED); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
intakeSubsystem.setIntakeSpeed(0); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
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,29 @@ | ||
package frc.robot.commands.intake; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.intake.IntakeConstants; | ||
import frc.robot.subsystems.intake.IntakeSubsystem; | ||
|
||
public class Intake extends Command { | ||
private final IntakeSubsystem intakeSubsystem; | ||
|
||
public Intake(IntakeSubsystem intakeSubsystem) { | ||
this.intakeSubsystem = intakeSubsystem; | ||
addRequirements(this.intakeSubsystem); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
intakeSubsystem.setIntakeSpeed(IntakeConstants.INTAKE_SPEED); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
intakeSubsystem.setIntakeSpeed(0); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/frc/robot/subsystems/AlgaePivot/AlgaeConstants.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,31 @@ | ||
package frc.robot.subsystems.algaePivot; | ||
|
||
import com.ctre.phoenix6.signals.SensorDirectionValue; | ||
|
||
public class AlgaeConstants { | ||
public static final int ALGAE_PIVOT_MOTOR_ID = 0; | ||
public static final int ALGAE_ENCODER_MOTOR_ID = 0; | ||
|
||
public static final SensorDirectionValue ALGAE_ENCODER_REVERSED = | ||
SensorDirectionValue.Clockwise_Positive; | ||
public static final double MAX_VELOCITY_ROTATIONS_PER_SECOND = 0.0; | ||
public static final double MAX_ACCELERATION_ROTATIONS_PER_SECOND = 0.0; | ||
|
||
public static final double MAX_ANGLE = 0.0; | ||
public static final double MIN_ANGLE = 0.0; | ||
|
||
public static final double ANGLE_ZERO = 0.0; | ||
public static final double PIVOT_P = 0.0; | ||
public static final double PIVOT_I = 0.0; | ||
public static final double PIVOT_D = 0.0; | ||
public static final double PIVOT_G = 0.0; | ||
|
||
public static final double ALGAE_GEAR_RATIO = 0.0; | ||
public static final double ALGAE_PIVOT_MASS = 0.0; | ||
public static final double ALGAE_PIVOT_LENGTH = 0.0; | ||
|
||
public static final double ALGAE_PIVOT_ANGLE = 0.0; | ||
public static final double ALGAE_PIVOT_SPEED = 0.0; | ||
public static final double ALGAE_VOLTAGE = 0.0; | ||
public static final double ALGAE_NEUTRAL_SPEED = 0.0; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/frc/robot/subsystems/AlgaePivot/AlgaePivotInterface.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,36 @@ | ||
package frc.robot.subsystems.algaePivot; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface AlgaePivotInterface { | ||
@AutoLog | ||
public static class AlgaePivotInputs { | ||
public boolean isConnected = true; | ||
public double algaeAngle = 0.0; | ||
public double algaeVoltage = 0.0; | ||
public double algaeVelocity = 0.0; | ||
public double algaeTemp = 0.0; | ||
public double algaeSupplyCurrentAmps = 0.0; | ||
public double algaeTorqueCurrentAmps = 0.0; | ||
} | ||
|
||
default void updateInputs(AlgaePivotInputs inputs) {} | ||
|
||
default void setAlgaeSpeed(double speed) {} | ||
|
||
default void setAlgaeAngle(double angle) {} | ||
|
||
default void setAlgaeVoltage(double voltage) {} | ||
|
||
default boolean isPivotWithinAcceptapleError() { | ||
return true; | ||
} | ||
|
||
default double getAlgaeAngle() { | ||
return 0.0; | ||
} | ||
|
||
default double getAlgaePivotTarget() { | ||
return 0.0; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/frc/robot/subsystems/AlgaePivot/AlgaePivotSubsystem.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,30 @@ | ||
package frc.robot.subsystems.algaePivot; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class AlgaePivotSubsystem extends SubsystemBase { | ||
private final AlgaePivotInterface algaePivotInterface; | ||
private final AlgaePivotInputsAutoLogged inputs = new AlgaePivotInputsAutoLogged(); | ||
|
||
public AlgaePivotSubsystem(AlgaePivotInterface algaePivotInterface) { | ||
this.algaePivotInterface = algaePivotInterface; | ||
} | ||
|
||
public void setAlgaeSpeed(double speed) { | ||
algaePivotInterface.setAlgaeSpeed(speed); | ||
} | ||
|
||
public void setAlgaeAngle(double angle) { | ||
algaePivotInterface.setAlgaeAngle(angle); | ||
} | ||
|
||
public void setAlgaeVoltage(double voltage) { | ||
algaePivotInterface.setAlgaeVoltage(voltage); | ||
} | ||
|
||
public void periodic() { | ||
algaePivotInterface.updateInputs(inputs); | ||
Logger.processInputs("AlgaePivotSubsystem/", inputs); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/frc/robot/subsystems/AlgaePivot/PhysicalAlgaePivot.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,115 @@ | ||
package frc.robot.subsystems.algaePivot; | ||
|
||
import com.ctre.phoenix6.BaseStatusSignal; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.CANcoderConfiguration; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.controls.MotionMagicVoltage; | ||
import com.ctre.phoenix6.controls.VoltageOut; | ||
import com.ctre.phoenix6.hardware.CANcoder; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.FeedbackSensorSourceValue; | ||
import com.ctre.phoenix6.signals.GravityTypeValue; | ||
import com.ctre.phoenix6.signals.InvertedValue; | ||
import com.ctre.phoenix6.signals.NeutralModeValue; | ||
import edu.wpi.first.units.measure.Angle; | ||
import edu.wpi.first.units.measure.AngularVelocity; | ||
import edu.wpi.first.units.measure.Current; | ||
import edu.wpi.first.units.measure.Voltage; | ||
import frc.robot.Constants.HardwareConstants; | ||
|
||
public class PhysicalAlgaePivot implements AlgaePivotInterface { | ||
private final TalonFX algaeMotor; | ||
private final CANcoder algaeEncoder; | ||
private final TalonFXConfiguration algaeMotorConfig; | ||
private final CANcoderConfiguration algaeEncoderConfig; | ||
private final StatusSignal<Voltage> algaeVoltage; | ||
private final StatusSignal<AngularVelocity> algaeVelocity; | ||
private StatusSignal<Angle> algaeAngle; | ||
private final StatusSignal<Current> algaeSupplyCurrent; | ||
private final StatusSignal<Current> algaeStatorCurrent; | ||
private final MotionMagicVoltage mmPositionRequest; | ||
private double algaeTargetAngle; | ||
private final VoltageOut voltageOut; | ||
|
||
public PhysicalAlgaePivot() { | ||
algaeMotor = new TalonFX(AlgaeConstants.ALGAE_PIVOT_MOTOR_ID); | ||
algaeEncoder = new CANcoder(AlgaeConstants.ALGAE_ENCODER_MOTOR_ID); | ||
algaeMotorConfig = new TalonFXConfiguration(); | ||
algaeEncoderConfig = new CANcoderConfiguration(); | ||
mmPositionRequest = new MotionMagicVoltage(0); | ||
|
||
algaeVoltage = algaeMotor.getMotorVoltage(); | ||
algaeVelocity = algaeMotor.getVelocity(); | ||
algaeAngle = algaeEncoder.getAbsolutePosition(); | ||
algaeSupplyCurrent = algaeMotor.getSupplyCurrent(); | ||
algaeStatorCurrent = algaeMotor.getStatorCurrent(); | ||
voltageOut = new VoltageOut(0); | ||
|
||
algaeEncoderConfig.MagnetSensor.MagnetOffset = -AlgaeConstants.ANGLE_ZERO; | ||
algaeEncoderConfig.MagnetSensor.SensorDirection = AlgaeConstants.ALGAE_ENCODER_REVERSED; | ||
algaeEncoder.getConfigurator().apply(algaeEncoderConfig, HardwareConstants.TIMEOUT_S); | ||
|
||
algaeMotorConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
algaeMotorConfig.MotorOutput.NeutralMode = NeutralModeValue.Brake; | ||
algaeMotorConfig.MotorOutput.DutyCycleNeutralDeadband = HardwareConstants.MIN_FALCON_DEADBAND; | ||
|
||
algaeMotorConfig.Slot0.kP = AlgaeConstants.PIVOT_P; | ||
algaeMotorConfig.Slot0.kI = AlgaeConstants.PIVOT_I; | ||
algaeMotorConfig.Slot0.kD = AlgaeConstants.PIVOT_D; | ||
algaeMotorConfig.Slot0.kG = AlgaeConstants.PIVOT_G; | ||
algaeMotorConfig.Slot0.GravityType = GravityTypeValue.Arm_Cosine; | ||
|
||
algaeMotorConfig.MotionMagic.MotionMagicAcceleration = | ||
AlgaeConstants.MAX_VELOCITY_ROTATIONS_PER_SECOND; | ||
algaeMotorConfig.MotionMagic.MotionMagicCruiseVelocity = | ||
AlgaeConstants.MAX_ACCELERATION_ROTATIONS_PER_SECOND; | ||
|
||
algaeMotorConfig.ClosedLoopGeneral.ContinuousWrap = true; | ||
|
||
algaeMotorConfig.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RemoteCANcoder; | ||
algaeMotorConfig.Feedback.FeedbackRemoteSensorID = algaeEncoder.getDeviceID(); | ||
|
||
algaeMotorConfig.SoftwareLimitSwitch.ForwardSoftLimitThreshold = AlgaeConstants.MAX_ANGLE; | ||
algaeMotorConfig.SoftwareLimitSwitch.ReverseSoftLimitThreshold = AlgaeConstants.MIN_ANGLE; | ||
algaeMotorConfig.SoftwareLimitSwitch.ForwardSoftLimitEnable = true; | ||
algaeMotorConfig.SoftwareLimitSwitch.ReverseSoftLimitEnable = true; | ||
|
||
BaseStatusSignal.setUpdateFrequencyForAll( | ||
100.0, algaeAngle, algaeVelocity, algaeVoltage, algaeSupplyCurrent, algaeStatorCurrent); | ||
} | ||
|
||
@Override | ||
public void updateInputs(AlgaePivotInputs inputs) { | ||
inputs.algaeAngle = algaeAngle.getValueAsDouble(); | ||
inputs.algaeVelocity = algaeVelocity.getValueAsDouble(); | ||
inputs.algaeVoltage = algaeVoltage.getValueAsDouble(); | ||
} | ||
|
||
@Override | ||
public void setAlgaeSpeed(double speed) { | ||
algaeMotor.set(speed); | ||
} | ||
|
||
@Override | ||
public void setAlgaeAngle(double angle) { | ||
algaeTargetAngle = angle; | ||
algaeMotor.setControl(mmPositionRequest.withPosition(angle)); | ||
} | ||
|
||
@Override | ||
public void setAlgaeVoltage(double voltage) { | ||
algaeMotor.setControl(voltageOut.withOutput(voltage)); | ||
} | ||
|
||
@Override | ||
public double getAlgaeAngle() { | ||
algaeAngle.refresh(); | ||
return algaeAngle.getValueAsDouble(); | ||
} | ||
|
||
@Override | ||
public double getAlgaePivotTarget() { | ||
return algaeTargetAngle; | ||
} | ||
} |
Oops, something went wrong.