From 1a9db59e0fbab3b085bd96cf934eddf7c96e1a65 Mon Sep 17 00:00:00 2001 From: Yair Lavie Date: Sat, 20 Jan 2024 01:16:58 +0200 Subject: [PATCH 1/2] Collecting adding CollectingSubsystem and adding setSpeedCommand and setSpeedUntilFeedCommand and adding CollectingConstants --- src/main/java/frc/robot/Constants.java | 4 ++ .../CollectingCommands/setSpeedCommand.java | 42 +++++++++++++++++ .../setSpeedUntilFeedCommand.java | 44 +++++++++++++++++ .../robot/subsystems/CollectingSubsystem.java | 47 +++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java create mode 100644 src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java create mode 100644 src/main/java/frc/robot/subsystems/CollectingSubsystem.java diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 6320e0f..4753813 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -302,4 +302,8 @@ public static class ShooterConstants { .put(2.1, 10.2); } + public static class CollectingConstants{ + public static final int SwitchID=1; + public static final int CollectingMotorID=10; + } } diff --git a/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java new file mode 100644 index 0000000..0a9b3e9 --- /dev/null +++ b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java @@ -0,0 +1,42 @@ +// 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.CollectingCommands; + +import static frc.robot.Constants.CollectingConstants.CollectingMotorID; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.Constants.CollectingConstants; +import frc.robot.subsystems.CollectingSubsystem; + +public class setSpeedCommand extends Command { + private final CollectingSubsystem collectingSubsystem = CollectingSubsystem.getInstance(); + double speed; + /** Creates a new setSpeedCommand. */ + public setSpeedCommand(double speed) { + addRequirements(collectingSubsystem); + this.speed = speed; + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + collectingSubsystem.setSpeed(speed); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java new file mode 100644 index 0000000..c4f39d2 --- /dev/null +++ b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java @@ -0,0 +1,44 @@ +// 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.CollectingCommands; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.Constants.CollectingConstants; +import frc.robot.subsystems.CollectingSubsystem; + +public class setSpeedUntilFeedCommand extends Command { + private final CollectingSubsystem collectingSubsystem = CollectingSubsystem.getInstance(); + /** Creates a new setSpeedUntilFeedCommand. */ + public setSpeedUntilFeedCommand() { + addRequirements(collectingSubsystem); + // Use addRequirements() here to declare subsystem dependencies. + } + + // 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() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + collectingSubsystem.setSpeed(0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + if (collectingSubsystem.getSwitch()){ + return true; + } + else{ + return false; + } + + } +} diff --git a/src/main/java/frc/robot/subsystems/CollectingSubsystem.java b/src/main/java/frc/robot/subsystems/CollectingSubsystem.java new file mode 100644 index 0000000..9cf95ea --- /dev/null +++ b/src/main/java/frc/robot/subsystems/CollectingSubsystem.java @@ -0,0 +1,47 @@ +// 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.phoenix.motorcontrol.ControlMode; +import com.ctre.phoenix.motorcontrol.can.TalonSRX; +import com.ctre.phoenix6.hardware.TalonFX; + +import edu.wpi.first.wpilibj.DigitalInput; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +import static frc.robot.Constants.CollectingConstants.*; + +public class CollectingSubsystem extends SubsystemBase { + private TalonSRX m_collecting; + DigitalInput limitSwitch; + + private static CollectingSubsystem instance; + + public static CollectingSubsystem getInstance() { + if (instance == null) { + instance = new CollectingSubsystem(); + } + return instance; + } + + /** Creates a new CollectingSubsystem. */ + public CollectingSubsystem() { + this.m_collecting = new TalonSRX(CollectingMotorID); + this.limitSwitch = new DigitalInput(SwitchID); + } + + public void setSpeed(double speed){ + m_collecting.set(ControlMode.PercentOutput, speed); + } + + public boolean getSwitch(){ + return limitSwitch.get(); + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} From 13f2d96458d86d03a4a174602c99a653d930398d Mon Sep 17 00:00:00 2001 From: Yair Lavie Date: Sat, 20 Jan 2024 13:25:11 +0200 Subject: [PATCH 2/2] doing changes changing to instant command changing limitswithc to lazersensor giving setspeeduntilfeedCommand speed variable --- .../CollectingCommands/setSpeedCommand.java | 26 +++++-------------- .../setSpeedUntilFeedCommand.java | 16 +++++------- .../robot/subsystems/CollectingSubsystem.java | 8 +++--- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java index 0a9b3e9..096145a 100644 --- a/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java +++ b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.java @@ -4,16 +4,16 @@ package frc.robot.commands.CollectingCommands; -import static frc.robot.Constants.CollectingConstants.CollectingMotorID; - -import edu.wpi.first.wpilibj2.command.Command; -import frc.robot.Constants.CollectingConstants; +import edu.wpi.first.wpilibj2.command.InstantCommand; import frc.robot.subsystems.CollectingSubsystem; -public class setSpeedCommand extends Command { +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html +public class setSpeedCommand extends InstantCommand { private final CollectingSubsystem collectingSubsystem = CollectingSubsystem.getInstance(); double speed; - /** Creates a new setSpeedCommand. */ +/** Creates a new setSpeedCommand. */ public setSpeedCommand(double speed) { addRequirements(collectingSubsystem); this.speed = speed; @@ -25,18 +25,4 @@ public setSpeedCommand(double speed) { public void initialize() { collectingSubsystem.setSpeed(speed); } - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() {} - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) {} - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } } diff --git a/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java index c4f39d2..c4e2b31 100644 --- a/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java +++ b/src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.java @@ -10,15 +10,19 @@ public class setSpeedUntilFeedCommand extends Command { private final CollectingSubsystem collectingSubsystem = CollectingSubsystem.getInstance(); + double speed; /** Creates a new setSpeedUntilFeedCommand. */ - public setSpeedUntilFeedCommand() { + public setSpeedUntilFeedCommand(double speed) { addRequirements(collectingSubsystem); + this.speed=speed; // Use addRequirements() here to declare subsystem dependencies. } // Called when the command is initially scheduled. @Override - public void initialize() {} + public void initialize() { + collectingSubsystem.setSpeed(speed); + } // Called every time the scheduler runs while the command is scheduled. @Override @@ -33,12 +37,6 @@ public void end(boolean interrupted) { // Returns true when the command should end. @Override public boolean isFinished() { - if (collectingSubsystem.getSwitch()){ - return true; - } - else{ - return false; - } - + return (collectingSubsystem.getSwitch()); } } diff --git a/src/main/java/frc/robot/subsystems/CollectingSubsystem.java b/src/main/java/frc/robot/subsystems/CollectingSubsystem.java index 9cf95ea..47c5091 100644 --- a/src/main/java/frc/robot/subsystems/CollectingSubsystem.java +++ b/src/main/java/frc/robot/subsystems/CollectingSubsystem.java @@ -15,7 +15,7 @@ public class CollectingSubsystem extends SubsystemBase { private TalonSRX m_collecting; - DigitalInput limitSwitch; + DigitalInput lazerSensor; private static CollectingSubsystem instance; @@ -25,11 +25,11 @@ public static CollectingSubsystem getInstance() { } return instance; } - + /** Creates a new CollectingSubsystem. */ public CollectingSubsystem() { this.m_collecting = new TalonSRX(CollectingMotorID); - this.limitSwitch = new DigitalInput(SwitchID); + this.lazerSensor = new DigitalInput(SwitchID); } public void setSpeed(double speed){ @@ -37,7 +37,7 @@ public void setSpeed(double speed){ } public boolean getSwitch(){ - return limitSwitch.get(); + return lazerSensor.get(); } @Override