Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collecting #13

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.InstantCommand;
import frc.robot.subsystems.CollectingSubsystem;

// 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. */
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);
}
}
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 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();
double speed;
/** Creates a new 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() {
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) {
collectingSubsystem.setSpeed(0);
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return (collectingSubsystem.getSwitch());
}
}
47 changes: 47 additions & 0 deletions src/main/java/frc/robot/subsystems/CollectingSubsystem.java
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 lazerSensor;

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.lazerSensor = new DigitalInput(SwitchID);
}

public void setSpeed(double speed){
m_collecting.set(ControlMode.PercentOutput, speed);
}

public boolean getSwitch(){
return lazerSensor.get();
}

@Override
public void periodic() {
// This method will be called once per scheduler run
}
}