-
Notifications
You must be signed in to change notification settings - Fork 0
BallChucker9000 + Limelight Command Based #62
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
Open
cadenmr
wants to merge
24
commits into
Command-Based
Choose a base branch
from
BallChuckerCommand
base: Command-Based
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bc4be6b
Initial Command-Based BallChucker9000
cadenmr 6cb9b4e
Basic auto target
cadenmr 81b1727
Limit switch, PID, rotatorDistance
cadenmr 67f7bf0
split flywheel l/r, fix rotator distancePerPulse, remove indexerPisto…
cadenmr 742e291
use indexerMotorControl in BC9KIndex command
cadenmr 4d23760
proper limelight logic
cadenmr 47612f2
change resting position to 0*
cadenmr 0b4b5a5
change var name, add search state
cadenmr af77160
rename BC9KAuto to BC9KAutoRotate
cadenmr 910c548
change encoder center offset
cadenmr 0a323c7
fix import in robotContainer
cadenmr 29d9f51
add BC9KAutoRotateCommand in RobotContainer
cadenmr 12d544e
set low power for testing
cadenmr 431fe82
change phoenix ver
cadenmr 6847ad8
rename commands
cadenmr 867b621
correct ports
cadenmr d133429
change failsafe position
cadenmr 821c61d
change max angle
cadenmr 60cd133
fix motor controllers
cadenmr ccf3f54
rename rotatorPosition to rotatorAngle
cadenmr 169a87b
convert Shoot to instantCommand
cadenmr bba6e81
merge RotateLeft and RotateRight, convert ManualRotate to InstantCommand
cadenmr c87de14
rename getRotatorDistance to getRotatorAngle
cadenmr a2d0b1c
conform to motor controller convention
cadenmr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
127 changes: 127 additions & 0 deletions
127
src/main/java/frc/robot/commands/BallChucker9000AutoRotate.java
This file contains hidden or 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,127 @@ | ||
package frc.robot.commands; | ||
|
||
import frc.robot.subsystems.BallChucker9000; | ||
import edu.wpi.first.networktables.NetworkTable; | ||
import edu.wpi.first.networktables.NetworkTableEntry; | ||
import edu.wpi.first.networktables.NetworkTableInstance; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
|
||
public class BallChucker9000AutoRotate extends CommandBase { | ||
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) | ||
private final BallChucker9000 BallChucker9000Subsystem; | ||
|
||
private final NetworkTable limelightData = NetworkTableInstance.getDefault().getTable("limelight"); | ||
|
||
private NetworkTableEntry tx = limelightData.getEntry("tx"); // X Offset from crosshair | ||
private NetworkTableEntry ta = limelightData.getEntry("ta"); // Target's size | ||
private NetworkTableEntry tv = limelightData.getEntry("tv"); // Target available | ||
|
||
private NetworkTableEntry ledMode = limelightData.getEntry("ledMode"); // Limelight's LED mode | ||
|
||
private double targetXOffset; | ||
private double targetSize; | ||
private boolean targetAvailable; | ||
|
||
private double rotatorAngle; | ||
private double rotatorDestination; | ||
|
||
/** | ||
* Creates command to make the BallChucker9000 automatically target | ||
* | ||
* @param subsystem The subsystem used by this command. | ||
*/ | ||
public BallChucker9000AutoRotate(BallChucker9000 subsystem) { | ||
BallChucker9000Subsystem = subsystem; | ||
addRequirements(BallChucker9000Subsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
|
||
ledMode.setNumber(3); // Turn the LEDs on | ||
|
||
} | ||
|
||
@Override | ||
public void execute() { | ||
|
||
// Read data | ||
targetXOffset = tx.getDouble(0.0); | ||
targetSize = ta.getDouble(0.0); | ||
targetAvailable = tv.getBoolean(false); | ||
|
||
// Show data (can be removed) | ||
SmartDashboard.putNumber("Limelight X Offset", targetXOffset); | ||
SmartDashboard.putNumber("Limelight Target Area", targetSize); | ||
SmartDashboard.putBoolean("Limelight Target Available", targetAvailable); | ||
|
||
if (targetAvailable) { // If a target is detected (Lock state) | ||
|
||
// get the encoder | ||
rotatorAngle = BallChucker9000Subsystem.getRotatorAngle(); | ||
|
||
// Set the destnation to the current position to bypass the | ||
// search check the first time it runs | ||
rotatorDestination = Math.round(rotatorAngle); | ||
|
||
// Move the rotator to the detected position including offset | ||
BallChucker9000Subsystem.rotatorPIDControl(targetXOffset + rotatorAngle); | ||
|
||
} else { // If no target is detected (Search state) | ||
|
||
// get the encoder and round it | ||
rotatorAngle = Math.round(BallChucker9000Subsystem.getRotatorAngle()); | ||
|
||
if (rotatorDestination == rotatorAngle) { // If we've reached our intended destination, check how we move | ||
|
||
if (rotatorAngle >= 120) { | ||
|
||
// Rotator is at max right rotation, go to max left rotation | ||
BallChucker9000Subsystem.rotatorPIDControl(0); | ||
rotatorDestination = 0; | ||
|
||
} else if (rotatorAngle >= 0) { | ||
|
||
// Rotator is above or equal to center, go to max right rotation | ||
BallChucker9000Subsystem.rotatorPIDControl(120); | ||
rotatorDestination = 120; | ||
|
||
} else if (rotatorAngle <= -120) { | ||
|
||
// Rotator is at max left rotation, go to max right rotation | ||
BallChucker9000Subsystem.rotatorPIDControl(120); | ||
rotatorDestination = 120; | ||
|
||
} else if (rotatorAngle < 0) { | ||
|
||
// Rotator is below center, go to max left rotation | ||
BallChucker9000Subsystem.rotatorPIDControl(0); | ||
rotatorDestination = 0; | ||
|
||
} else { | ||
|
||
// Uh oh! Hopefully we didn't break anything! | ||
// (go to center) | ||
BallChucker9000Subsystem.rotatorPIDControl(0); | ||
rotatorDestination = 0; | ||
cadenmr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
BallChucker9000Subsystem.rotatorPIDControl(0); // Reset to resting position | ||
ledMode.setNumber(1); // Turn the LEDs off | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/frc/robot/commands/BallChucker9000ManualRotate.java
This file contains hidden or 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,50 @@ | ||
package frc.robot.commands; | ||
|
||
import frc.robot.subsystems.BallChucker9000; | ||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
|
||
public class BallChucker9000ManualRotate extends InstantCommand { | ||
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) | ||
|
||
private final BallChucker9000 BallChucker9000Subsystem; | ||
private boolean rotateLeft; | ||
private double rotatorPosition; | ||
|
||
/** | ||
* Creates a new BallChucker9000ManualRotate. | ||
* | ||
* @param subsystem The subsystem used by this command. | ||
*/ | ||
public BallChucker9000ManualRotate(BallChucker9000 subsystem, boolean rotateLeft) { | ||
BallChucker9000Subsystem = subsystem; | ||
addRequirements(BallChucker9000Subsystem); | ||
|
||
this.rotateLeft = rotateLeft; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
|
||
// Prevent rotating if we're at rotational limits or the switch is pressed | ||
rotatorPosition = BallChucker9000Subsystem.getRotatorAngle(); | ||
if (rotatorPosition <= -120.0 || rotatorPosition >= 120.0 || !BallChucker9000Subsystem.getRotatorAtZeroSwitch()) { | ||
BallChucker9000Subsystem.rotatorMotorControl(0); | ||
} else { | ||
if (this.rotateLeft) { | ||
BallChucker9000Subsystem.rotatorMotorControl(-0.25); | ||
} else { | ||
BallChucker9000Subsystem.rotatorMotorControl(0.25); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
BallChucker9000Subsystem.rotatorMotorControl(0.0); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/frc/robot/commands/BallChucker9000Shoot.java
This file contains hidden or 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,37 @@ | ||
package frc.robot.commands; | ||
|
||
import frc.robot.subsystems.BallChucker9000; | ||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
|
||
|
||
public class BallChucker9000Shoot extends InstantCommand { | ||
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) | ||
|
||
private final BallChucker9000 BallChucker9000Subsystem; | ||
private boolean forward; | ||
|
||
/** | ||
* Creates a new BallChucker9000Index. | ||
* | ||
* @param subsystem The subsystem used by this command. | ||
*/ | ||
public BallChucker9000Shoot(BallChucker9000 subsystem, boolean forward) { | ||
BallChucker9000Subsystem = subsystem; | ||
|
||
this.forward = forward; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
if (this.forward) { | ||
BallChucker9000Subsystem.indexerMotorControl(0.75); | ||
} else { | ||
BallChucker9000Subsystem.indexerMotorControl(-0.75); | ||
} | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
BallChucker9000Subsystem.indexerMotorControl(0); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/frc/robot/commands/BallChucker9000SpinUp.java
This file contains hidden or 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,40 @@ | ||
package frc.robot.commands; | ||
|
||
import frc.robot.subsystems.BallChucker9000; | ||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
|
||
|
||
public class BallChucker9000SpinUp extends CommandBase { | ||
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) | ||
private final BallChucker9000 BallChucker9000Subsystem; | ||
|
||
/** | ||
* Creates a new BallChucker9000Shoot. | ||
* | ||
* @param subsystem The subsystem used by this command. | ||
*/ | ||
public BallChucker9000SpinUp(BallChucker9000 subsystem) { | ||
BallChucker9000Subsystem = subsystem; | ||
|
||
addRequirements(BallChucker9000Subsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
|
||
} | ||
|
||
@Override | ||
public void execute() { | ||
|
||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
By the way, here's the buttons.
manipulator -- left bumper: manual rotator left.
right bumper: manual rotator right.
Right joystick -- trigger: shoot
Button 3: indexer forward
Button 2: indexer backward