-
Notifications
You must be signed in to change notification settings - Fork 1
Handle balls #23
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
base: main
Are you sure you want to change the base?
Handle balls #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ public static class ShooterMotor { | |
| public static class Funnel { | ||
| public static final double POWER = 0.7; | ||
| public static final double REVERSE_POWER = -0.7; | ||
| public static final int MACRO_SWITCH_PORT = 0; | ||
|
|
||
| public static class FunnelMotor { | ||
| public static final int MOTOR_PORT = 5; | ||
|
|
@@ -89,6 +90,9 @@ public static class PressureSensor { | |
| } | ||
| } | ||
|
|
||
| public static class DigitalInputMap { | ||
| public static final int MACRO_SWITCH = 0; | ||
| } | ||
|
|
||
| public static class Swerve { | ||
| public static final double WHEEL_CIRC = 0.0517 * 2 * Math.PI; //very accurate right now | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the comment |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package edu.greenblitz.pegasus.commands.handleBalls; | ||
|
|
||
| import edu.greenblitz.pegasus.commands.funnel.ReverseRunFunnel; | ||
| import edu.greenblitz.pegasus.commands.funnel.RunFunnel; | ||
| import edu.greenblitz.pegasus.commands.intake.IntakeCommand; | ||
| import edu.greenblitz.pegasus.commands.intake.roller.ReverseRunRoller; | ||
| import edu.greenblitz.pegasus.commands.shooter.ShooterEvacuate; | ||
| import edu.greenblitz.pegasus.subsystems.Indexing; | ||
| import edu.greenblitz.pegasus.utils.DigitalInputMap; | ||
| import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
| import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; | ||
| import edu.wpi.first.wpilibj2.command.WaitCommand; | ||
|
|
||
| public class HandleBalls extends IntakeCommand { | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove one of the enters |
||
| /** | ||
| * this command checks if an enemy ball is trying to enter the Funnel, | ||
| * and if so it is rejecting it from entering the funnel system using a | ||
| * color sensor to check the color | ||
| * | ||
| * @see com.revrobotics.ColorSensorV3 colorSensor. | ||
| * @see Indexing Subsystem | ||
| */ | ||
|
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use an informative name instead of a comment |
||
|
|
||
| private final Indexing index; | ||
| private boolean isBallInFunnel; | ||
|
|
||
| public HandleBalls() { | ||
| this.index = Indexing.getInstance(); | ||
| isBallInFunnel = false; | ||
| require(Indexing.getInstance()); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| SmartDashboard.putBoolean("isBallInFunnel", isBallInFunnel); | ||
| SmartDashboard.putBoolean("isEnemyBallUnSensor", index.isEnemyBallInSensor()); | ||
| SmartDashboard.putBoolean("isMacroSwitch", DigitalInputMap.getInstance().getValue(0)); | ||
|
|
||
| if (index.isTeamsBallInSensor()) { | ||
| //if our team's ball is in front of the sensor activate the boolean | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the comment, the name is informative enough |
||
| isBallInFunnel = true; | ||
| } | ||
| if (DigitalInputMap.getInstance().getValue(0)) { | ||
| //if the ball got to the macroSwitch then disable the boolean | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no need for a comment |
||
| isBallInFunnel = false; | ||
| } | ||
|
|
||
| if (index.isEnemyBallInSensor()) { | ||
| if (DigitalInputMap.getInstance().getValue(0) || isBallInFunnel) { | ||
| isBallInFunnel = false; | ||
| SmartDashboard.putBoolean("isEvacuatingFromShooter", false); | ||
| //back direction | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comment is uninformative and unnecessary |
||
| new ParallelDeadlineGroup( | ||
| new WaitCommand(0.5), | ||
| new ReverseRunRoller(), | ||
| new ReverseRunFunnel().raceWith(new WaitCommand(0.2)) | ||
| ).andThen(new RunFunnel().until(() -> DigitalInputMap.getInstance().getValue(0))).schedule(false); | ||
| } else { | ||
| //shooter evacuation | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comment is unnecessary |
||
| SmartDashboard.putBoolean("isEvacuatingFromShooter", true); | ||
| new ShooterEvacuate().raceWith(new WaitCommand(5)).schedule(false); | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package edu.greenblitz.pegasus.commands.multiSystem; | ||
|
|
||
| import edu.greenblitz.pegasus.commands.intake.roller.ReverseRunRoller; | ||
| import edu.wpi.first.wpilibj2.command.ParallelRaceGroup; | ||
| import edu.wpi.first.wpilibj2.command.WaitCommand; | ||
|
|
||
| public class EjectEnemyBallFromGripper extends ParallelRaceGroup { //todo can be deadline | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. execute the "todo" instead of leaving it there |
||
| public EjectEnemyBallFromGripper() { | ||
| addCommands( | ||
| new WaitCommand(1.5), | ||
| new ReverseRunRoller() | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package edu.greenblitz.pegasus.commands.multiSystem; | ||
|
|
||
| import edu.greenblitz.pegasus.RobotMap; | ||
| import edu.greenblitz.pegasus.commands.funnel.ReverseRunFunnel; | ||
| import edu.greenblitz.pegasus.commands.intake.roller.ReverseRunRoller; | ||
| import edu.greenblitz.pegasus.utils.DigitalInputMap; | ||
| import edu.wpi.first.wpilibj2.command.ParallelRaceGroup; | ||
| import edu.wpi.first.wpilibj2.command.WaitUntilCommand; | ||
|
|
||
| public class EjectFromShooter extends ParallelRaceGroup {//todo delete | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. execute the "todo" |
||
| public EjectFromShooter() { | ||
| addCommands( | ||
| new WaitUntilCommand(() -> DigitalInputMap.getInstance().getValue(RobotMap.Pegasus.Funnel.MACRO_SWITCH_PORT)), | ||
| new ReverseRunFunnel(), | ||
| new ReverseRunRoller() | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package edu.greenblitz.pegasus.commands.multiSystem; | ||
|
|
||
| import edu.greenblitz.GBLib.src.main.java.edu.greenblitz.gblib.subsystems.shooter.Shooter; | ||
| import edu.greenblitz.pegasus.RobotMap; | ||
| import edu.greenblitz.pegasus.commands.funnel.RunFunnel; | ||
| import edu.greenblitz.pegasus.commands.intake.roller.RunRoller; | ||
| import edu.greenblitz.pegasus.utils.DigitalInputMap; | ||
| import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
| import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; | ||
| import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
| import edu.wpi.first.wpilibj2.command.WaitUntilCommand; | ||
|
|
||
| public class InsertIntoShooter extends SequentialCommandGroup { | ||
|
|
||
| private double startTime; | ||
| private boolean reported = false; | ||
|
|
||
| // AKA InsertoShooter @tal935 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the comment, the name is informative enough |
||
| public InsertIntoShooter() { | ||
| addCommands( | ||
| new MoveBallUntilClick(), | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove unnecessary enter |
||
| //waits until the shooter is ready | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the comment, the name is informative enough |
||
| new WaitUntilCommand(() -> Shooter.getInstance().isPreparedToShoot()), | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the unnecessary enter |
||
| new ParallelDeadlineGroup(//activates both roller and funnel until ball is no longer at macro switch (was probably propelled) | ||
|
Comment on lines
+18
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| new WaitUntilCommand(() -> !DigitalInputMap.getInstance().getValue(RobotMap.Pegasus.Funnel.MACRO_SWITCH_PORT)), | ||
| new RunFunnel(), | ||
| new RunRoller() | ||
| )); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the unnecessary enter |
||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for the "InsertIntoShooter" function Ctrl + Alt +L! |
||
| @Override | ||
| public void initialize() { | ||
| super.initialize(); | ||
| startTime = System.currentTimeMillis() / 1000.0; | ||
| } | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove unnecessary enter |
||
| @Override | ||
| public void end(boolean interrupted) { | ||
| super.end(interrupted); | ||
| reported = false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package edu.greenblitz.pegasus.commands.multiSystem; | ||
|
|
||
| import edu.greenblitz.GBLib.src.main.java.edu.greenblitz.gblib.base.GBCommand; | ||
| import edu.greenblitz.GBLib.src.main.java.edu.greenblitz.gblib.commands.DoUntilCommand; | ||
| import edu.greenblitz.pegasus.RobotMap; | ||
| import edu.greenblitz.pegasus.commands.funnel.RunFunnel; | ||
| import edu.greenblitz.pegasus.commands.intake.roller.RunRoller; | ||
| import edu.greenblitz.pegasus.utils.DigitalInputMap; | ||
| import edu.greenblitz.pegasus.utils.WaitCommand; | ||
| import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; | ||
| import edu.wpi.first.wpilibj2.command.WaitUntilCommand; | ||
|
|
||
| public class MoveBallUntilClick extends ParallelDeadlineGroup { | ||
|
|
||
| public MoveBallUntilClick() { | ||
| super(new WaitUntilCommand(() -> DigitalInputMap.getInstance().getValue(0)), new RunRoller(),new RunFunnel()); | ||
| } | ||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ctrl + Alt + L |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ public void moveMotor(double power) { | |
| public void moveMotor(boolean reversed) { | ||
| moveMotor(reversed ? RobotMap.Pegasus.Funnel.REVERSE_POWER : RobotMap.Pegasus.Funnel.POWER); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete space |
||
|
|
||
| public void moveMotor() { | ||
| moveMotor(false); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package edu.greenblitz.pegasus.subsystems; | ||
|
|
||
| import com.revrobotics.ColorSensorV3; | ||
| import edu.greenblitz.GBLib.src.main.java.edu.greenblitz.gblib.subsystems.GBSubsystem; | ||
| import edu.wpi.first.wpilibj.DriverStation; | ||
| import edu.wpi.first.wpilibj.I2C; | ||
| import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
|
||
| import java.awt.*; | ||
|
|
||
|
|
||
|
Comment on lines
+1
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should drop any unnecessary spaces |
||
| public class Indexing extends GBSubsystem { | ||
| /** | ||
| * This class is in-charge of checking if an enemy ball is trying to get to the funnel (and eventually to the shooter) | ||
| * by using color sensor | ||
| * | ||
| * @see ColorSensorV3 colorSensorV3 | ||
| */ | ||
|
Comment on lines
+13
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should optimize the readabilty of the code instead of writing a comment |
||
|
|
||
| private static Indexing instance; | ||
| private ColorSensorV3 cs; | ||
| public DriverStation.Alliance alliance; | ||
|
|
||
| private Indexing() { | ||
| cs = new ColorSensorV3(I2C.Port.kOnboard); | ||
| alliance = DriverStation.getAlliance(); | ||
| } | ||
|
|
||
|
Comment on lines
+19
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should change the "cs" object into colorSensor |
||
| public static Indexing getInstance() { | ||
| if (instance == null) { | ||
| instance = new Indexing(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @return the color that is in front of the sensor (as a DriverStation.Alliance enum) | ||
| */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for a comment ( return is present) |
||
| public DriverStation.Alliance getBallColor() { | ||
| float[] color = Color.RGBtoHSB(cs.getRed(), cs.getGreen(), cs.getBlue(), new float[3]); | ||
| if (color[0] >= 0.05 && color[0] <= 0.2) { | ||
| return DriverStation.Alliance.Red; | ||
| } else if (color[0] >= 0.4 && color[0] < 0.6) { | ||
|
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use variables/constants instead of random numbers thrown in the code without an exact meaning |
||
| return DriverStation.Alliance.Blue; | ||
| } else { | ||
| return DriverStation.Alliance.Invalid; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return true if enemy ball in front of the sensor | ||
| */ | ||
|
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should drop the comment |
||
| public boolean isEnemyBallInSensor() { | ||
| DriverStation.Alliance a = instance.getBallColor(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a name that indicates the meaning of "a" |
||
| SmartDashboard.putString("color", a.toString()); | ||
| return a != alliance | ||
| && a != DriverStation.Alliance.Invalid; | ||
| } | ||
|
|
||
| /** | ||
| * @return true is our team's ball is in front of the sensor. | ||
| */ | ||
| public boolean isTeamsBallInSensor() { | ||
| DriverStation.Alliance a = instance.getBallColor(); | ||
| SmartDashboard.putString("color", a.toString()); | ||
| return a == alliance | ||
| && a != DriverStation.Alliance.Invalid; | ||
| } | ||
|
Comment on lines
+51
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could merge both functions into one and change the receiving logic |
||
|
|
||
|
|
||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either delete the code or use it