-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding CollectingSubsystem and adding setSpeedCommand and setSpeedUntilFeedCommand and adding CollectingConstants
- Loading branch information
Yair Lavie
committed
Jan 19, 2024
1 parent
2893c1f
commit 1a9db59
Showing
4 changed files
with
137 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
src/main/java/frc/robot/commands/CollectingCommands/setSpeedCommand.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,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; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/frc/robot/commands/CollectingCommands/setSpeedUntilFeedCommand.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,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; | ||
} | ||
|
||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/frc/robot/subsystems/CollectingSubsystem.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,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 | ||
} | ||
} |