From 5539beefefdf6ffbc84e1f5fa62d9325a78c3d31 Mon Sep 17 00:00:00 2001 From: Violet Su Date: Mon, 28 Oct 2024 19:32:44 -0700 Subject: [PATCH 01/13] Co-authored-by: Venkata Siva Ramisetty --- src/main/java/frc/robot/subsystems/Piper.java | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/main/java/frc/robot/subsystems/Piper.java diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java new file mode 100644 index 0000000..0b148f8 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -0,0 +1,131 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc.robot.subsystems; + +import com.ctre.phoenix6.configs.CurrentLimitsConfigs; +import com.ctre.phoenix6.configs.Slot0Configs; +import com.ctre.phoenix6.hardware.TalonFX; +import com.ctre.phoenix6.controls.VelocityVoltage; +import edu.wpi.first.wpilibj.DigitalInput; +import edu.wpi.first.wpilibj.motorcontrol.Talon; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class Piper extends SubsystemBase { + private TalonFX shooter1, shooter2; + private TalonFX preshooterMotor; + private TalonFX intakeMotor; + private DigitalInput noteSwitch; + + public Piper() { + // Shooter + shooter1 = new TalonFX(35); + shooter2 = new TalonFX(34); + shooter1.setInverted(true); + shooter2.setInverted(false); + + Slot0Configs s0c = new Slot0Configs().withKP(0).withKI(0).withKD(0).withKG(0).withKV(0).withKA(0); + CurrentLimitsConfigs clc = + new CurrentLimitsConfigs() + .withStatorCurrentLimitEnable(true) + .withStatorCurrentLimit(20); + + shooter1.getConfigurator().apply(s0c); + shooter2.getConfigurator().apply(s0c); + shooter1.getConfigurator().apply(clc); + shooter2.getConfigurator().apply(clc); + + // PreShooter + preshooterMotor = new TalonFX(32); + + preshooterMotor.getConfigurator().apply(clc); + + + intakeMotor = new TalonFX(33); + + intakeMotor.getConfigurator().apply(clc); + + //note detector + + noteSwitch = new DigitalInput(1); + + } + public boolean isNotesThere() { + return noteSwitch.get(); + } + + //Shooter Functions + public void spinShooter(int speed) { + + VelocityVoltage VV = new VelocityVoltage(speed * 1); +; + shooter1.setControl(VV); + shooter2.setControl(VV); + } + + public void stopShooter() { + VelocityVoltage VV = new VelocityVoltage(0); + shooter1.setControl(VV); + shooter2.setControl(VV); + } + + // PreShooter Functions + public void spinPreShooter(int speed) { + + VelocityVoltage VV = new VelocityVoltage(speed * 1); +; + preshooterMotor.setControl(VV); + } + + public void stopPreShooter() { + preshooterMotor.stopMotor(); + } + + //Intake Functions + public void spinIntake(int speed) { + VelocityVoltage VV = new VelocityVoltage(speed); +; + intakeMotor.setControl(VV); + } + + public void stopIntake() { + intakeMotor.stopMotor(); + } +, + + /** + * Example command factory method. + * + * @return a command + */ + public Command exampleMethodCommand() { + // Inline construction of command goes here. + // Subsystem::RunOnce implicitly requires `this` subsystem. + return runOnce( + () -> { + /* one-time action goes here */ + }); + } + + /** + * An example method querying a boolean state of the subsystem (for example, a digital sensor). + * + * @return value of some boolean subsystem state, such as a digital sensor. + */ + public boolean exampleCondition() { + // Query some boolean state, such as a digital sensor. + return false; + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + } + + @Override + public void simulationPeriodic() { + // This method will be called once per scheduler run during simulation + } +} From 3569247de8ba1d5edaabddfc05b39f91ded364c1 Mon Sep 17 00:00:00 2001 From: Violet Su Date: Mon, 28 Oct 2024 21:05:33 -0700 Subject: [PATCH 02/13] piper mech Co-authored-by: Venkata Siva Ramisetty --- src/main/java/frc/robot/RobotContainer.java | 22 ++++---- src/main/java/frc/robot/commands/Autos.java | 4 -- src/main/java/frc/robot/commands/Intake.java | 50 +++++++++++++++++++ ...{ExampleCommand.java => PiperCommand.java} | 8 +-- .../robot/subsystems/ExampleSubsystem.java | 47 ----------------- src/main/java/frc/robot/subsystems/Piper.java | 18 +++++-- vendordeps/DogLog.json | 20 ++++++++ 7 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 src/main/java/frc/robot/commands/Intake.java rename src/main/java/frc/robot/commands/{ExampleCommand.java => PiperCommand.java} (84%) delete mode 100644 src/main/java/frc/robot/subsystems/ExampleSubsystem.java create mode 100644 vendordeps/DogLog.json diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index a33249e..ea88639 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -6,8 +6,8 @@ import frc.robot.Constants.OperatorConstants; import frc.robot.commands.Autos; -import frc.robot.commands.ExampleCommand; -import frc.robot.subsystems.ExampleSubsystem; +import frc.robot.commands.Intake; +import frc.robot.subsystems.Piper; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.Trigger; @@ -20,15 +20,18 @@ */ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem(); // Replace with CommandPS4Controller or CommandJoystick if needed private final CommandXboxController m_driverController = new CommandXboxController(OperatorConstants.kDriverControllerPort); + private final Piper piper = Piper.getInstance(); + + /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { // Configure the trigger bindings + m_driverController.rightTrigger().whileTrue(new Intake(piper)); configureBindings(); } @@ -43,12 +46,12 @@ public RobotContainer() { */ private void configureBindings() { // Schedule `ExampleCommand` when `exampleCondition` changes to `true` - new Trigger(m_exampleSubsystem::exampleCondition) - .onTrue(new ExampleCommand(m_exampleSubsystem)); + // new Trigger(m_exampleSubsystem::exampleCondition) + // .onTrue(new ExampleCommand(m_exampleSubsystem)); - // Schedule `exampleMethodCommand` when the Xbox controller's B button is pressed, - // cancelling on release. - m_driverController.b().whileTrue(m_exampleSubsystem.exampleMethodCommand()); + // // Schedule `exampleMethodCommand` when the Xbox controller's B button is pressed, + // // cancelling on release. + // m_driverController.b().whileTrue(m_exampleSubsystem.exampleMethodCommand()); } /** @@ -57,7 +60,8 @@ private void configureBindings() { * @return the command to run in autonomous */ public Command getAutonomousCommand() { + return null; // An example command will be run in autonomous - return Autos.exampleAuto(m_exampleSubsystem); + // return Autos.exampleAuto(m_exampleSubsystem); } } diff --git a/src/main/java/frc/robot/commands/Autos.java b/src/main/java/frc/robot/commands/Autos.java index 107aad7..b32acdb 100644 --- a/src/main/java/frc/robot/commands/Autos.java +++ b/src/main/java/frc/robot/commands/Autos.java @@ -4,15 +4,11 @@ package frc.robot.commands; -import frc.robot.subsystems.ExampleSubsystem; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; public final class Autos { /** Example static factory for an autonomous command. */ - public static Command exampleAuto(ExampleSubsystem subsystem) { - return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem)); - } private Autos() { throw new UnsupportedOperationException("This is a utility class!"); diff --git a/src/main/java/frc/robot/commands/Intake.java b/src/main/java/frc/robot/commands/Intake.java new file mode 100644 index 0000000..8c25742 --- /dev/null +++ b/src/main/java/frc/robot/commands/Intake.java @@ -0,0 +1,50 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc.robot.commands; +import frc.robot.subsystems.Piper; +import edu.wpi.first.wpilibj2.command.Command; + +/** An example command that uses an example subsystem. */ +public class Intake extends Command { + @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) + private final Piper m_piper; + + /** + * Creates a new ExampleCommand. + * + * @param subsystem The subsystem used by this command. + */ + public Intake(Piper piper) { + m_piper = piper; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(piper); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + double speed = 6.0; + m_piper.spinIntake(speed); + m_piper.spinPreShooter(speed); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + m_piper.stopIntake(); + m_piper.stopPreShooter(); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return m_piper.isNotesThere(); + } +} diff --git a/src/main/java/frc/robot/commands/ExampleCommand.java b/src/main/java/frc/robot/commands/PiperCommand.java similarity index 84% rename from src/main/java/frc/robot/commands/ExampleCommand.java rename to src/main/java/frc/robot/commands/PiperCommand.java index 7481d3c..9a62e34 100644 --- a/src/main/java/frc/robot/commands/ExampleCommand.java +++ b/src/main/java/frc/robot/commands/PiperCommand.java @@ -4,20 +4,20 @@ package frc.robot.commands; -import frc.robot.subsystems.ExampleSubsystem; +import frc.robot.subsystems.Piper; import edu.wpi.first.wpilibj2.command.Command; /** An example command that uses an example subsystem. */ -public class ExampleCommand extends Command { +public class PiperCommand extends Command { @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) - private final ExampleSubsystem m_subsystem; + private final Piper m_subsystem; /** * Creates a new ExampleCommand. * * @param subsystem The subsystem used by this command. */ - public ExampleCommand(ExampleSubsystem subsystem) { + public PiperCommand(Piper subsystem) { m_subsystem = subsystem; // Use addRequirements() here to declare subsystem dependencies. addRequirements(subsystem); diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java deleted file mode 100644 index 6b375da..0000000 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package frc.robot.subsystems; - -import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -public class ExampleSubsystem extends SubsystemBase { - /** Creates a new ExampleSubsystem. */ - public ExampleSubsystem() {} - - /** - * Example command factory method. - * - * @return a command - */ - public Command exampleMethodCommand() { - // Inline construction of command goes here. - // Subsystem::RunOnce implicitly requires `this` subsystem. - return runOnce( - () -> { - /* one-time action goes here */ - }); - } - - /** - * An example method querying a boolean state of the subsystem (for example, a digital sensor). - * - * @return value of some boolean subsystem state, such as a digital sensor. - */ - public boolean exampleCondition() { - // Query some boolean state, such as a digital sensor. - return false; - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - } - - @Override - public void simulationPeriodic() { - // This method will be called once per scheduler run during simulation - } -} diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index 0b148f8..d64fa95 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -18,6 +18,7 @@ public class Piper extends SubsystemBase { private TalonFX preshooterMotor; private TalonFX intakeMotor; private DigitalInput noteSwitch; + private static Piper piperInstance; public Piper() { // Shooter @@ -57,7 +58,7 @@ public boolean isNotesThere() { } //Shooter Functions - public void spinShooter(int speed) { + public void spinShooter(double speed) { VelocityVoltage VV = new VelocityVoltage(speed * 1); ; @@ -72,7 +73,7 @@ public void stopShooter() { } // PreShooter Functions - public void spinPreShooter(int speed) { + public void spinPreShooter(double speed) { VelocityVoltage VV = new VelocityVoltage(speed * 1); ; @@ -84,7 +85,7 @@ public void stopPreShooter() { } //Intake Functions - public void spinIntake(int speed) { + public void spinIntake(double speed) { VelocityVoltage VV = new VelocityVoltage(speed); ; intakeMotor.setControl(VV); @@ -93,7 +94,8 @@ public void spinIntake(int speed) { public void stopIntake() { intakeMotor.stopMotor(); } -, + + /** * Example command factory method. @@ -122,10 +124,18 @@ public boolean exampleCondition() { @Override public void periodic() { // This method will be called once per scheduler run + DogLog.log(); } @Override public void simulationPeriodic() { // This method will be called once per scheduler run during simulation } + public static Piper getInstance() { + if(piperInstance == null){ + piperInstance = new Piper(); + } + + return piperInstance; + } } diff --git a/vendordeps/DogLog.json b/vendordeps/DogLog.json new file mode 100644 index 0000000..4e867e1 --- /dev/null +++ b/vendordeps/DogLog.json @@ -0,0 +1,20 @@ +{ + "javaDependencies": [ + { + "groupId": "com.github.jonahsnider", + "artifactId": "doglog", + "version": "2024.1.1" + } + ], + "fileName": "DogLog.json", + "frcYear": "2024", + "jsonUrl": "https://doglog.dev/vendordep.json", + "name": "DogLog", + "jniDependencies": [], + "mavenUrls": [ + "https://jitpack.io" + ], + "cppDependencies": [], + "version": "2024.6.0", + "uuid": "65592ce1-2251-4a31-8e4b-2df20dacebe4" +} \ No newline at end of file From ea824b71b7cb9bc1550fffb74a7e203efc576f3d Mon Sep 17 00:00:00 2001 From: Violet Su Date: Mon, 28 Oct 2024 21:13:37 -0700 Subject: [PATCH 03/13] piper mech --- src/main/java/frc/robot/subsystems/Piper.java | 3 +++ vendordeps/DogLog.json | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index d64fa95..95a00e9 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -7,6 +7,9 @@ import com.ctre.phoenix6.configs.CurrentLimitsConfigs; import com.ctre.phoenix6.configs.Slot0Configs; import com.ctre.phoenix6.hardware.TalonFX; + +import dev.doglog.DogLog; + import com.ctre.phoenix6.controls.VelocityVoltage; import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.motorcontrol.Talon; diff --git a/vendordeps/DogLog.json b/vendordeps/DogLog.json index 4e867e1..4b21de7 100644 --- a/vendordeps/DogLog.json +++ b/vendordeps/DogLog.json @@ -3,7 +3,7 @@ { "groupId": "com.github.jonahsnider", "artifactId": "doglog", - "version": "2024.1.1" + "version": "2024.6.0" } ], "fileName": "DogLog.json", @@ -15,6 +15,6 @@ "https://jitpack.io" ], "cppDependencies": [], - "version": "2024.6.0", + "version": "2024.5.8", "uuid": "65592ce1-2251-4a31-8e4b-2df20dacebe4" } \ No newline at end of file From 94edf36aa13f25ec0569024a706a4d87f9d0a19c Mon Sep 17 00:00:00 2001 From: MaryamShaikh320 Date: Mon, 4 Nov 2024 18:53:40 -0800 Subject: [PATCH 04/13] piper w/ doglogged --- .../robot/subsystems/RunMotorSubsystem.java | 48 +++++++++++ .../java/frc/robot/util/LoggedTalonFX.java | 80 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 src/main/java/frc/robot/subsystems/RunMotorSubsystem.java create mode 100644 src/main/java/frc/robot/util/LoggedTalonFX.java diff --git a/src/main/java/frc/robot/subsystems/RunMotorSubsystem.java b/src/main/java/frc/robot/subsystems/RunMotorSubsystem.java new file mode 100644 index 0000000..0717f99 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/RunMotorSubsystem.java @@ -0,0 +1,48 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc.robot.subsystems; + +import com.ctre.phoenix6.hardware.TalonFX; + +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + + +public class RunMotorSubsystem extends SubsystemBase { + + //The motor is declared here! + private TalonFX motor; + private static RunMotorSubsystem instance; + + + private RunMotorSubsystem() { + //TODO: Initalize the motor on port 0 + motor = new TalonFX(0); + } + // This is a singleton pattern. Ensures only one instance of `RunMotorSubsystem` exists! + // See if you can understand how it works! + public static RunMotorSubsystem getInstance(){ + if(instance == null){ + instance = new RunMotorSubsystem(); + } + return instance; + } + + public void runMotor(double speed) { + //TODO: set motor speed and log speed + motor.set(speed); + SmartDashboard.putNumber("motor speed", speed); + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + } + + @Override + public void simulationPeriodic() { + // This method will be called once per scheduler run during simulation + } +} diff --git a/src/main/java/frc/robot/util/LoggedTalonFX.java b/src/main/java/frc/robot/util/LoggedTalonFX.java new file mode 100644 index 0000000..cea8383 --- /dev/null +++ b/src/main/java/frc/robot/util/LoggedTalonFX.java @@ -0,0 +1,80 @@ +package frc.robot.util; + +import java.util.ArrayList; + +import com.ctre.phoenix6.StatusSignal; +import com.ctre.phoenix6.hardware.TalonFX; + +import dev.doglog.DogLog; + +public class LoggedTalonFX extends TalonFX{ + + private static ArrayList motors = new ArrayList<>(); + private String name; + private String temperature,closedLoopError,closedLoopReference,position,velocity,acceleration,supplycurrent,statorcurrent,torquecurrent,motorvoltage,supplyvoltage; + + public LoggedTalonFX(String deviceName,int deviceId, String canbus) { + super(deviceId, canbus); + init(); + name = deviceName; + } + + public LoggedTalonFX(String deviceName,int deviceId) { + super(deviceId); + init(); + name = deviceName; + } + + public LoggedTalonFX(int deviceId, String canbus) { + super(deviceId, canbus); + init(); + name = "motor "+deviceId; + } + + public LoggedTalonFX(int deviceId) { + super(deviceId); + init(); + name = "motor "+deviceId; + } + + public void init(){ + motors.add(this); + this.temperature=name + "/temperature(degC)"; + this.closedLoopError = name + "/closedLoopError"; + this.closedLoopReference = name + "/closedLoopReference"; + this.position=name + "/position(rotations)"; + this.velocity=name + "/velocity(rps)"; + this.acceleration=name + "/acceleration(rps2)"; + this.supplycurrent=name + "/current/supply(A)"; + this.statorcurrent=name + "/current/stator(A)"; + this.torquecurrent=name + "/current/torque(A)"; + this.motorvoltage=name + "/voltage/motor(V)"; + this.supplyvoltage=name + "/voltage/supply(V)"; + } + + public static void peroidic(){ + for(LoggedTalonFX l: motors){ + l.periodic(); + } + } + + public void periodic(){ + DogLog.log(temperature,this.getDeviceTemp().getValue()); + DogLog.log(closedLoopError,this.getClosedLoopError().getValue()); + DogLog.log(closedLoopReference,this.getClosedLoopReference().getValue()); + + DogLog.log(position,this.getPosition().getValue()); + DogLog.log(velocity,this.getVelocity().getValue()); + DogLog.log(acceleration,this.getAcceleration().getValue()); + + //Current + DogLog.log(supplycurrent,this.getSupplyCurrent().getValue()); + DogLog.log(statorcurrent,this.getStatorCurrent().getValue()); + DogLog.log(torquecurrent,this.getTorqueCurrent().getValue()); + + //Voltage + DogLog.log(motorvoltage,this.getMotorVoltage().getValue()); + DogLog.log(supplyvoltage,this.getSupplyVoltage().getValue()); + } + +} \ No newline at end of file From 93f1adbe55bc5ca3612974824bccf54fd44caac9 Mon Sep 17 00:00:00 2001 From: MaryamShaikh320 Date: Mon, 4 Nov 2024 19:02:11 -0800 Subject: [PATCH 05/13] updated doglog version --- src/main/java/frc/robot/Robot.java | 3 +++ vendordeps/DogLog.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 687a0a0..b762b82 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -4,6 +4,7 @@ package frc.robot; +import dev.doglog.DogLog; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; @@ -28,6 +29,8 @@ public void robotInit() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. m_robotContainer = new RobotContainer(); + // DogLog.setOptions(new DogLogOptions().withNtPublish(true).withCaptureDs(true).withLogExtras(true)); + } /** diff --git a/vendordeps/DogLog.json b/vendordeps/DogLog.json index 4b21de7..750a428 100644 --- a/vendordeps/DogLog.json +++ b/vendordeps/DogLog.json @@ -3,7 +3,7 @@ { "groupId": "com.github.jonahsnider", "artifactId": "doglog", - "version": "2024.6.0" + "version": "2024.5.8" } ], "fileName": "DogLog.json", From 759c383aac6f8dc25a0f5b95ef3324140b3cf0f6 Mon Sep 17 00:00:00 2001 From: Violet Su Date: Mon, 4 Nov 2024 19:43:27 -0800 Subject: [PATCH 06/13] doglog w piper --- src/main/java/frc/robot/commands/Intake.java | 1 + src/main/java/frc/robot/subsystems/Piper.java | 8 ++++++-- src/main/java/frc/robot/util/LoggedTalonFX.java | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/commands/Intake.java b/src/main/java/frc/robot/commands/Intake.java index 8c25742..34fe973 100644 --- a/src/main/java/frc/robot/commands/Intake.java +++ b/src/main/java/frc/robot/commands/Intake.java @@ -4,6 +4,7 @@ package frc.robot.commands; import frc.robot.subsystems.Piper; +import dev.doglog.DogLog; import edu.wpi.first.wpilibj2.command.Command; /** An example command that uses an example subsystem. */ diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index 95a00e9..df745f6 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -92,6 +92,7 @@ public void spinIntake(double speed) { VelocityVoltage VV = new VelocityVoltage(speed); ; intakeMotor.setControl(VV); + } public void stopIntake() { @@ -126,10 +127,13 @@ public boolean exampleCondition() { @Override public void periodic() { - // This method will be called once per scheduler run - DogLog.log(); + DogLog.log(intakeMotor,this.getSpeed()).getValue(); } + + private int getSpeed(int Speed) { + return Speed; + } @Override public void simulationPeriodic() { // This method will be called once per scheduler run during simulation diff --git a/src/main/java/frc/robot/util/LoggedTalonFX.java b/src/main/java/frc/robot/util/LoggedTalonFX.java index cea8383..bcfdc8c 100644 --- a/src/main/java/frc/robot/util/LoggedTalonFX.java +++ b/src/main/java/frc/robot/util/LoggedTalonFX.java @@ -6,6 +6,7 @@ import com.ctre.phoenix6.hardware.TalonFX; import dev.doglog.DogLog; +import dev.doglog.DogLogOptions; public class LoggedTalonFX extends TalonFX{ From d75f257510672eb7270b4ce3cbe33629a920c44d Mon Sep 17 00:00:00 2001 From: Violet Su Date: Mon, 4 Nov 2024 21:27:40 -0800 Subject: [PATCH 07/13] pipermech 11/4 --- src/main/java/frc/robot/RobotContainer.java | 3 +++ src/main/java/frc/robot/commands/Intake.java | 3 ++- .../frc/robot/commands/increaseConstVal.java | 11 +++++++++++ src/main/java/frc/robot/subsystems/Piper.java | 16 +++++++++------- src/main/java/frc/robot/util/LoggedTalonFX.java | 4 ++-- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/main/java/frc/robot/commands/increaseConstVal.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index ea88639..64c34f2 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -7,6 +7,7 @@ import frc.robot.Constants.OperatorConstants; import frc.robot.commands.Autos; import frc.robot.commands.Intake; +import frc.robot.commands.increaseConstVal; import frc.robot.subsystems.Piper; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; @@ -33,6 +34,8 @@ public RobotContainer() { // Configure the trigger bindings m_driverController.rightTrigger().whileTrue(new Intake(piper)); configureBindings(); + double ffval = 0; + m_driverController.rightBumper().onTrue(piper.FFConst); } /** diff --git a/src/main/java/frc/robot/commands/Intake.java b/src/main/java/frc/robot/commands/Intake.java index 34fe973..2f841f9 100644 --- a/src/main/java/frc/robot/commands/Intake.java +++ b/src/main/java/frc/robot/commands/Intake.java @@ -31,7 +31,8 @@ public void initialize() { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - double speed = 6.0; + double speed = 1; + m_piper.spinShooter(speed); m_piper.spinIntake(speed); m_piper.spinPreShooter(speed); } diff --git a/src/main/java/frc/robot/commands/increaseConstVal.java b/src/main/java/frc/robot/commands/increaseConstVal.java new file mode 100644 index 0000000..4c2157a --- /dev/null +++ b/src/main/java/frc/robot/commands/increaseConstVal.java @@ -0,0 +1,11 @@ +package frc.robot.commands; + + +public class increaseConstVal { + double ffval = 0; + + public static double increaseVal (double ffval){ + ffval += 0.5; + return ffval; + } +} diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index df745f6..3cc50ff 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -22,6 +22,7 @@ public class Piper extends SubsystemBase { private TalonFX intakeMotor; private DigitalInput noteSwitch; private static Piper piperInstance; + double FFConst; public Piper() { // Shooter @@ -40,6 +41,7 @@ public Piper() { shooter2.getConfigurator().apply(s0c); shooter1.getConfigurator().apply(clc); shooter2.getConfigurator().apply(clc); + // PreShooter preshooterMotor = new TalonFX(32); @@ -64,7 +66,7 @@ public boolean isNotesThere() { public void spinShooter(double speed) { VelocityVoltage VV = new VelocityVoltage(speed * 1); -; + shooter1.setControl(VV); shooter2.setControl(VV); } @@ -89,7 +91,7 @@ public void stopPreShooter() { //Intake Functions public void spinIntake(double speed) { - VelocityVoltage VV = new VelocityVoltage(speed); + VelocityVoltage VV = new VelocityVoltage(speed).withFeedForward(FFConst); ; intakeMotor.setControl(VV); @@ -127,13 +129,13 @@ public boolean exampleCondition() { @Override public void periodic() { - DogLog.log(intakeMotor,this.getSpeed()).getValue(); + DogLog.log("IntakeMotor Speed", intakeMotor.get()); + FFConst += 0.5; } - - private int getSpeed(int Speed) { - return Speed; - } + //private int getSpeed(int Speed) { + // return Speed; + //} @Override public void simulationPeriodic() { // This method will be called once per scheduler run during simulation diff --git a/src/main/java/frc/robot/util/LoggedTalonFX.java b/src/main/java/frc/robot/util/LoggedTalonFX.java index bcfdc8c..92fa083 100644 --- a/src/main/java/frc/robot/util/LoggedTalonFX.java +++ b/src/main/java/frc/robot/util/LoggedTalonFX.java @@ -1,3 +1,4 @@ + package frc.robot.util; import java.util.ArrayList; @@ -6,7 +7,6 @@ import com.ctre.phoenix6.hardware.TalonFX; import dev.doglog.DogLog; -import dev.doglog.DogLogOptions; public class LoggedTalonFX extends TalonFX{ @@ -78,4 +78,4 @@ public void periodic(){ DogLog.log(supplyvoltage,this.getSupplyVoltage().getValue()); } -} \ No newline at end of file +} From 0276a6a772390fa33bb7fe4b3e5b221542d0dfa8 Mon Sep 17 00:00:00 2001 From: MaryamShaikh320 Date: Mon, 11 Nov 2024 20:53:29 -0800 Subject: [PATCH 08/13] Got FF constant to change when button is clicked. Intake doesn't work. (Reverting to old code) --- src/main/java/frc/robot/Robot.java | 14 ++++++++++++- src/main/java/frc/robot/RobotContainer.java | 3 --- src/main/java/frc/robot/commands/Intake.java | 2 +- .../frc/robot/commands/increaseConstVal.java | 11 ---------- src/main/java/frc/robot/subsystems/Piper.java | 20 ++++++++++++++++++- 5 files changed, 33 insertions(+), 17 deletions(-) delete mode 100644 src/main/java/frc/robot/commands/increaseConstVal.java diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index b762b82..cda4276 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -8,6 +8,11 @@ import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; +import edu.wpi.first.wpilibj2.command.InstantCommand; +import frc.robot.Constants.OperatorConstants; +import frc.robot.subsystems.Piper; +import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +import edu.wpi.first.wpilibj2.command.button.Trigger; /** * The VM is configured to automatically run this class, and to call the functions corresponding to @@ -19,6 +24,10 @@ public class Robot extends TimedRobot { private Command m_autonomousCommand; private RobotContainer m_robotContainer; + private Piper m_piper = Piper.getInstance(); + + private final CommandXboxController m_driverController = + new CommandXboxController(OperatorConstants.kDriverControllerPort); /** * This function is run when the robot is first started up and should be used for any @@ -84,7 +93,10 @@ public void teleopInit() { /** This function is called periodically during operator control. */ @Override - public void teleopPeriodic() {} + public void teleopPeriodic() { + m_driverController.rightBumper().onTrue(new InstantCommand(() -> m_piper.increaseFF())); + m_driverController.leftBumper().onTrue(new InstantCommand(() -> m_piper.decreaseFF())); + } @Override public void testInit() { diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 64c34f2..ea88639 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -7,7 +7,6 @@ import frc.robot.Constants.OperatorConstants; import frc.robot.commands.Autos; import frc.robot.commands.Intake; -import frc.robot.commands.increaseConstVal; import frc.robot.subsystems.Piper; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; @@ -34,8 +33,6 @@ public RobotContainer() { // Configure the trigger bindings m_driverController.rightTrigger().whileTrue(new Intake(piper)); configureBindings(); - double ffval = 0; - m_driverController.rightBumper().onTrue(piper.FFConst); } /** diff --git a/src/main/java/frc/robot/commands/Intake.java b/src/main/java/frc/robot/commands/Intake.java index 2f841f9..b9386ca 100644 --- a/src/main/java/frc/robot/commands/Intake.java +++ b/src/main/java/frc/robot/commands/Intake.java @@ -32,7 +32,7 @@ public void initialize() { @Override public void execute() { double speed = 1; - m_piper.spinShooter(speed); + //m_piper.spinShooter(speed); m_piper.spinIntake(speed); m_piper.spinPreShooter(speed); } diff --git a/src/main/java/frc/robot/commands/increaseConstVal.java b/src/main/java/frc/robot/commands/increaseConstVal.java deleted file mode 100644 index 4c2157a..0000000 --- a/src/main/java/frc/robot/commands/increaseConstVal.java +++ /dev/null @@ -1,11 +0,0 @@ -package frc.robot.commands; - - -public class increaseConstVal { - double ffval = 0; - - public static double increaseVal (double ffval){ - ffval += 0.5; - return ffval; - } -} diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index 3cc50ff..2b75779 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -13,6 +13,7 @@ import com.ctre.phoenix6.controls.VelocityVoltage; import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.motorcontrol.Talon; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; @@ -61,11 +62,18 @@ public Piper() { public boolean isNotesThere() { return noteSwitch.get(); } + + public static Piper piperInstance() { + if (piperInstance == null) { + piperInstance = new Piper(); + } + return piperInstance; + } //Shooter Functions public void spinShooter(double speed) { - VelocityVoltage VV = new VelocityVoltage(speed * 1); + VelocityVoltage VV = new VelocityVoltage(speed); shooter1.setControl(VV); shooter2.setControl(VV); @@ -130,9 +138,19 @@ public boolean exampleCondition() { @Override public void periodic() { DogLog.log("IntakeMotor Speed", intakeMotor.get()); + SmartDashboard.putNumber("IntakeMotor Speed", intakeMotor.get()); + DogLog.log("FF Constant Value", FFConst); + SmartDashboard.putNumber("FF Constant Value", FFConst); + } + + public void increaseFF() { FFConst += 0.5; } + public void decreaseFF() { + FFConst -= 0.25; + } + //private int getSpeed(int Speed) { // return Speed; //} From bfaed6fb607ce826e24e95643690f909d3f5f9f2 Mon Sep 17 00:00:00 2001 From: Venkata Siva Ramisetty <92191466+Ace-Kat@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:00:39 -0800 Subject: [PATCH 09/13] added dog log for note sensor --- src/main/java/frc/robot/subsystems/Piper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index 2b75779..357650c 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -139,6 +139,8 @@ public boolean exampleCondition() { public void periodic() { DogLog.log("IntakeMotor Speed", intakeMotor.get()); SmartDashboard.putNumber("IntakeMotor Speed", intakeMotor.get()); + DogLog.log("IsNotePresent", isNotesThere()); + SmartDashboard.putNumber("IntakeMotor Speed", isNotesThere()); DogLog.log("FF Constant Value", FFConst); SmartDashboard.putNumber("FF Constant Value", FFConst); } From b72602b866c22b2769b2d9afaad6c04c3da7d2a8 Mon Sep 17 00:00:00 2001 From: Ace-Kat <92191466+Ace-Kat@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:05:27 -0800 Subject: [PATCH 10/13] Changed intake speed and added logging for the note sensor --- src/main/java/frc/robot/commands/Intake.java | 2 +- src/main/java/frc/robot/subsystems/Piper.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/commands/Intake.java b/src/main/java/frc/robot/commands/Intake.java index b9386ca..c612e6f 100644 --- a/src/main/java/frc/robot/commands/Intake.java +++ b/src/main/java/frc/robot/commands/Intake.java @@ -31,7 +31,7 @@ public void initialize() { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - double speed = 1; + double speed = 90; //m_piper.spinShooter(speed); m_piper.spinIntake(speed); m_piper.spinPreShooter(speed); diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index 357650c..c0bf8b3 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -32,7 +32,7 @@ public Piper() { shooter1.setInverted(true); shooter2.setInverted(false); - Slot0Configs s0c = new Slot0Configs().withKP(0).withKI(0).withKD(0).withKG(0).withKV(0).withKA(0); + Slot0Configs s0c = new Slot0Configs().withKP(0.1).withKI(0).withKD(0).withKG(0).withKV(0).withKA(0); CurrentLimitsConfigs clc = new CurrentLimitsConfigs() .withStatorCurrentLimitEnable(true) @@ -60,7 +60,7 @@ public Piper() { } public boolean isNotesThere() { - return noteSwitch.get(); + return !(noteSwitch.get()); } public static Piper piperInstance() { @@ -139,18 +139,18 @@ public boolean exampleCondition() { public void periodic() { DogLog.log("IntakeMotor Speed", intakeMotor.get()); SmartDashboard.putNumber("IntakeMotor Speed", intakeMotor.get()); - DogLog.log("IsNotePresent", isNotesThere()); - SmartDashboard.putNumber("IntakeMotor Speed", isNotesThere()); + DogLog.log("IsNotePresent", !(noteSwitch.get()) ? 1:0); + SmartDashboard.putNumber("isnotepresent", !(noteSwitch.get()) ? 1:0); DogLog.log("FF Constant Value", FFConst); SmartDashboard.putNumber("FF Constant Value", FFConst); } public void increaseFF() { - FFConst += 0.5; + FFConst += 0.00001; } public void decreaseFF() { - FFConst -= 0.25; + FFConst -= 0.00001; } //private int getSpeed(int Speed) { From c8aee86e704a21dfaebb9c83f83999b6ce3c2e98 Mon Sep 17 00:00:00 2001 From: Ace-Kat <92191466+Ace-Kat@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:24:40 -0800 Subject: [PATCH 11/13] Co-authored-by: Maryam Co-authored-by: vio1atte --- 2025-training | 1 + src/main/java/frc/robot/commands/Shooter.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 160000 2025-training create mode 100644 src/main/java/frc/robot/commands/Shooter.java diff --git a/2025-training b/2025-training new file mode 160000 index 0000000..bc380f5 --- /dev/null +++ b/2025-training @@ -0,0 +1 @@ +Subproject commit bc380f511945ab0b6dbb442b2c6e5e035519b7a1 diff --git a/src/main/java/frc/robot/commands/Shooter.java b/src/main/java/frc/robot/commands/Shooter.java new file mode 100644 index 0000000..1f92199 --- /dev/null +++ b/src/main/java/frc/robot/commands/Shooter.java @@ -0,0 +1,50 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc.robot.commands; +import frc.robot.subsystems.Piper; +import dev.doglog.DogLog; +import edu.wpi.first.wpilibj2.command.Command; + +/** An example command that uses an example subsystem. */ +public class Shooter extends Command { + @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) + private final Piper m_piper; + + /** + * Creates a new ExampleCommand. + * + * @param subsystem The subsystem used by this command. + */ + public Shooter(Piper piper) { + m_piper = piper; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(piper); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + double speed = 50; + m_piper.spinShooter(speed); + m_piper.spinPreShooter(speed/2); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + m_piper.stopShooter(); + m_piper.stopPreShooter(); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + } +} From 19054d26555477818a14e79e67fdd587743d77a4 Mon Sep 17 00:00:00 2001 From: Ace-Kat <92191466+Ace-Kat@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:27:26 -0800 Subject: [PATCH 12/13] Added logging for shooter speed Co-authored-by: Maryam Co-authored-by: vio1atte for --- src/main/java/frc/robot/subsystems/Piper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index c0bf8b3..1a9cc37 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -139,6 +139,8 @@ public boolean exampleCondition() { public void periodic() { DogLog.log("IntakeMotor Speed", intakeMotor.get()); SmartDashboard.putNumber("IntakeMotor Speed", intakeMotor.get()); + DogLog.log("ShooterMotor Speed", Shooter1.get()); + SmartDashboard.putNumber("ShooterMotor Speed", Shooter1.get()); DogLog.log("IsNotePresent", !(noteSwitch.get()) ? 1:0); SmartDashboard.putNumber("isnotepresent", !(noteSwitch.get()) ? 1:0); DogLog.log("FF Constant Value", FFConst); From 07964c9bdd5da55ccb0096c1b0ff5a40e24081ec Mon Sep 17 00:00:00 2001 From: Ace-Kat <92191466+Ace-Kat@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:58:02 -0800 Subject: [PATCH 13/13] added shooter code --- src/main/java/frc/robot/RobotContainer.java | 2 ++ src/main/java/frc/robot/commands/Shooter.java | 1 + src/main/java/frc/robot/subsystems/Piper.java | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index ea88639..975491d 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -7,6 +7,7 @@ import frc.robot.Constants.OperatorConstants; import frc.robot.commands.Autos; import frc.robot.commands.Intake; +import frc.robot.commands.Shooter; import frc.robot.subsystems.Piper; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; @@ -32,6 +33,7 @@ public class RobotContainer { public RobotContainer() { // Configure the trigger bindings m_driverController.rightTrigger().whileTrue(new Intake(piper)); + m_driverController.leftTrigger().whileTrue(new Shooter(piper)); configureBindings(); } diff --git a/src/main/java/frc/robot/commands/Shooter.java b/src/main/java/frc/robot/commands/Shooter.java index 1f92199..668a8d6 100644 --- a/src/main/java/frc/robot/commands/Shooter.java +++ b/src/main/java/frc/robot/commands/Shooter.java @@ -46,5 +46,6 @@ public void end(boolean interrupted) { // Returns true when the command should end. @Override public boolean isFinished() { + return !(m_piper.isNotesThere()); } } diff --git a/src/main/java/frc/robot/subsystems/Piper.java b/src/main/java/frc/robot/subsystems/Piper.java index 1a9cc37..00be46e 100644 --- a/src/main/java/frc/robot/subsystems/Piper.java +++ b/src/main/java/frc/robot/subsystems/Piper.java @@ -139,8 +139,8 @@ public boolean exampleCondition() { public void periodic() { DogLog.log("IntakeMotor Speed", intakeMotor.get()); SmartDashboard.putNumber("IntakeMotor Speed", intakeMotor.get()); - DogLog.log("ShooterMotor Speed", Shooter1.get()); - SmartDashboard.putNumber("ShooterMotor Speed", Shooter1.get()); + DogLog.log("ShooterMotor Speed", shooter1.get()); + SmartDashboard.putNumber("ShooterMotor Speed", shooter1.get()); DogLog.log("IsNotePresent", !(noteSwitch.get()) ? 1:0); SmartDashboard.putNumber("isnotepresent", !(noteSwitch.get()) ? 1:0); DogLog.log("FF Constant Value", FFConst);