Merge pull request #11 from FairportRobotics/ToDo2electricboogalo

Added commands, lotta commands, im sleepy
This commit is contained in:
Raymond Healy 2026-03-10 20:21:58 -04:00 committed by GitHub
commit cfabf8cf69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 159 additions and 85 deletions

View File

@ -3,24 +3,24 @@
These are the jobs to be completed first, to ensure we have minimal functionality for RIT These are the jobs to be completed first, to ensure we have minimal functionality for RIT
- Add subsystems to robot - Add subsystems to robot
- Define unique IDs and channels for all devices in Constants.java IP Dom - Define unique IDs and channels for all devices in Constants.java (IP Dom)
- Add subsystems to the RobotContainer X - Add subsystems to the RobotContainer X
- Updates to subsystems X - Updates to subsystems X
- Update launcher wheel to a Neo/SparkMax X - Update launcher wheel to a Neo/SparkMax X
- Define basic commands for manual fire mode - Define basic commands for manual fire mode
- Y/Top button: Deploy the intake (and run the rollers) - Y/Top button: Deploy the intake (and run the rollers) (TO MAP)
- Could be a single command - Could be a single command
- Could be 2 commands in sequence - Could be 2 commands in sequence
- B/Right button: Reverse the intake - B/Right button: Reverse the intake (TO MAP)
- Unclear if this should touch the deploy motor. ATM suggest leaving the deploy motor alone - Unclear if this should touch the deploy motor. ATM suggest leaving the deploy motor alone
- A/Bottom button: Retract the intake (and stop the rollers) - A/Bottom button: Retract the intake (and stop the rollers) (TO MAP)
- D-pad: Set deflector to pre-programmed angle - D-pad: Set deflector to pre-programmed angle
- Suggestion: Implement this once, and make the angle an member variable of the command - Suggestion: Implement this once, and make the angle an member variable of the command (TO MAP)
- Both Triggers: Spin up flywheel (if not already spun up) and then start the kicker. - Both Triggers: Spin up flywheel (if not already spun up) and then start the kicker.
- Re: Sensing flywheel speed - Re: Sensing flywheel speed

View File

@ -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.HopperSubsystem;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
/** An example command that uses an example subsystem. */
public class ManualHopperCommand extends Command {
private final HopperSubsystem m_subsystem;
private final XboxController m_xboxController;
public ManualHopperCommand(HopperSubsystem subsystem, XboxController xboxController) {
m_subsystem = subsystem;
m_xboxController = xboxController;
addRequirements(subsystem);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_subsystem.spin(.5);
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
if(m_xboxController.getLeftTriggerAxis()>.5 && m_xboxController.getRightTriggerAxis()>.5)
{
m_subsystem.feed();
}
else
{
m_subsystem.stop();
}
}
// 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;
}
}

View File

@ -0,0 +1,40 @@
// 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.TurretSubsystem;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
/** An example command that uses an example subsystem. */
public class ManualShootCommand extends Command {
private final TurretSubsystem m_subsystem;
private final XboxController m_controller;
public ManualShootCommand(TurretSubsystem subsystem, XboxController controller) {
m_subsystem = subsystem;
m_controller = controller;
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(subsystem);
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
if(m_controller.getLeftTriggerAxis()>.5 || m_controller.getRightTriggerAxis()>.5)
{
m_subsystem.setLauncher(1);
}
else
{
m_subsystem.setLauncher(0);
}
}
@Override
public boolean isFinished() {
return false;
}
}

View File

@ -0,0 +1,32 @@
// 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.TurretSubsystem;
import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.wpilibj2.command.Command;
/** An example command that uses an example subsystem. **/
public class SetDeflectorCommand extends Command {
private final TurretSubsystem m_subsystem;
private Angle deployAngle;
public SetDeflectorCommand(TurretSubsystem subsystem, Angle deployAngle) {
m_subsystem = subsystem;
this.deployAngle = deployAngle;
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_subsystem.setTargetElevation(deployAngle);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return true;
}
}

View File

@ -6,12 +6,10 @@ package frc.robot.subsystems;
import org.fairportrobotics.frc.posty.TestableSubsystem; import org.fairportrobotics.frc.posty.TestableSubsystem;
import org.fairportrobotics.frc.posty.test.PostTest; import org.fairportrobotics.frc.posty.test.PostTest;
import com.ctre.phoenix6.hardware.TalonFX; import com.ctre.phoenix6.hardware.TalonFX;
import static org.fairportrobotics.frc.posty.assertions.Assertions.*; import static org.fairportrobotics.frc.posty.assertions.Assertions.*;
import frc.robot.Constants; import frc.robot.Constants;
import edu.wpi.first.wpilibj2.command.Command; import frc.robot.commands.ManualHopperCommand;
public class HopperSubsystem extends TestableSubsystem { public class HopperSubsystem extends TestableSubsystem {
@ -23,55 +21,13 @@ public class HopperSubsystem extends TestableSubsystem {
kickerMotor = new TalonFX(Constants.HopperConstants.KICKER_MOTOR_ID); kickerMotor = new TalonFX(Constants.HopperConstants.KICKER_MOTOR_ID);
} }
public void feed() { public void feed() {kickerMotor.set(0.5);}
kickerMotor.set(0.5);
}
public void reverse() { public void reverse() {kickerMotor.set(-0.5);}
kickerMotor.set(-0.5);
}
public void stop() { public void stop() {kickerMotor.set(0);}
kickerMotor.set(0);
}
public void spin(double speed) { public void spin(double speed) {spindexerMotor.set(speed);}
spindexerMotor.set(speed);
}
/**
* 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
}
@PostTest(name = "A friendly name", enabled = true) @PostTest(name = "A friendly name", enabled = true)
public void myFailingPostTest(){ public void myFailingPostTest(){
@ -82,4 +38,4 @@ public class HopperSubsystem extends TestableSubsystem {
public void myPassingPostTest(){ public void myPassingPostTest(){
assertThat("Hello World").endWith("World"); assertThat("Hello World").endWith("World");
} }
} }

View File

@ -7,15 +7,21 @@ package frc.robot.subsystems;
import org.fairportrobotics.frc.posty.TestableSubsystem; import org.fairportrobotics.frc.posty.TestableSubsystem;
import org.fairportrobotics.frc.posty.test.PostTest; import org.fairportrobotics.frc.posty.test.PostTest;
import com.ctre.phoenix.motorcontrol.LimitSwitchNormal;
import com.ctre.phoenix.motorcontrol.LimitSwitchSource;
import com.ctre.phoenix.motorcontrol.can.TalonSRX; import com.ctre.phoenix.motorcontrol.can.TalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import com.ctre.phoenix6.hardware.TalonFX; import com.ctre.phoenix6.hardware.TalonFX;
import frc.robot.Constants; import frc.robot.Constants;
import static org.fairportrobotics.frc.posty.assertions.Assertions.*; import static org.fairportrobotics.frc.posty.assertions.Assertions.*;
import java.time.chrono.ThaiBuddhistChronology;
import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.wpilibj.DigitalOutput; import edu.wpi.first.wpilibj.DigitalOutput;
import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
public class IntakeSubsystem extends TestableSubsystem { public class IntakeSubsystem extends TestableSubsystem {
/** Creates a new ExampleSubsystem. */ /** Creates a new ExampleSubsystem. */
@ -27,6 +33,8 @@ public class IntakeSubsystem extends TestableSubsystem {
{ {
intakeMotor = new TalonFX(Constants.IntakeConstants.INTAKE_MOTOR_ID); intakeMotor = new TalonFX(Constants.IntakeConstants.INTAKE_MOTOR_ID);
deployMotor = new WPI_TalonSRX(Constants.IntakeConstants.DEPLOY_MOTOR_ID); deployMotor = new WPI_TalonSRX(Constants.IntakeConstants.DEPLOY_MOTOR_ID);
deployMotor.configForwardLimitSwitchSource(LimitSwitchSource.FeedbackConnector, LimitSwitchNormal.NormallyOpen);
deployMotor.configReverseLimitSwitchSource(LimitSwitchSource.FeedbackConnector, LimitSwitchNormal.NormallyOpen);
} }
public void neutral() public void neutral()
@ -49,38 +57,29 @@ public class IntakeSubsystem extends TestableSubsystem {
intakeMotor.set(speed); intakeMotor.set(speed);
} }
/** public boolean isDeployed()
* Example command factory method. {
* return deployMotor.isFwdLimitSwitchClosed()==1;
* @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 */
});
} }
/** public boolean isRetracted()
* An example method querying a boolean state of the subsystem (for example, a digital sensor). {
* return deployMotor.isRevLimitSwitchClosed()==1;
* @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 Command deployCommand()
public void periodic() { {
// This method will be called once per scheduler run return new FunctionalCommand(this::extend, this::extend, interrupted -> neutral(), this::isDeployed, this).andThen(Commands.startEnd(() -> setSpeed(50), () -> setSpeed(0), this));
} }
@Override public Command reverseCommand()
public void simulationPeriodic() { {
// This method will be called once per scheduler run during simulation return new FunctionalCommand(this::extend, this::extend, interrupted -> neutral(), this::isDeployed, this).andThen(Commands.startEnd(() -> setSpeed(-50), () -> setSpeed(0), this));
}
public Command retractCommand()
{
return this.runOnce(() -> setSpeed(0)).andThen(new FunctionalCommand(this::retract, this::retract, interrupted -> neutral(), this::isRetracted, this));
} }
@PostTest(name = "A friendly name", enabled = true) @PostTest(name = "A friendly name", enabled = true)

View File

@ -54,10 +54,7 @@ public class TurretSubsystem extends TestableSubsystem {
targElev = edu.wpi.first.units.Units.Degrees.of(45); targElev = edu.wpi.first.units.Units.Degrees.of(45);
} }
public void setLauncher(double speed) public void setLauncher(double speed) {launcherMotor.set(speed);}
{
launcherMotor.set(speed);
}
public void setTargetElevation(Angle elev) public void setTargetElevation(Angle elev)
{ {