generated from TitaniumTigers4829/4829-BaseRobotCode
-
Notifications
You must be signed in to change notification settings - Fork 0
auto factories #55
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
Merged
Merged
auto factories #55
Changes from 13 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
5539322
woah these are actually kinda cool
7c3fb18
added FunctionalCommand, StartEndCommand, and RunOnceCommand examples
43cc9b3
added example triggers and a bit more stuff about command factories
91debed
moved auto stuff to robot.java, made it better(used choreo's autoChoo…
f0f9afd
vscode.dev changes so they r very jank
aridavidson001 293ee0e
made some changes
6d74f63
amazing cool new autos.java file yay
c513ba6
merge conflicts
6ed584f
cool
de943d6
starter paths for now
487b5ea
More paths but J heading is very wrong needs fixing
828ffe3
removed example auto
aridavidson001 0c93dee
Formatting fixes
github-actions[bot] fa2c140
use pose estimation for trajectories (#71)
Ishan1522 e8a10b2
w fixes
aridavidson001 e495961
added a constructor for Autos(), fixed some smaller things
aridavidson001 9cabc9a
oui oui fixed the constructor
2f7cf56
Created an AutoConstants class and moved TrajectoryConstants into it.…
aridavidson001 14358d9
removed example directory
aridavidson001 250138a
Formatting fixes
github-actions[bot] 13c5624
actual computer changes yay
b2dcbdb
Merge branch 'flexiautos' of https://github.com/TitaniumTigers4829/ro…
6ad781a
renamed AutoPaths folder to Trajectories
c37e0d1
fixed string path in constants for trajectories
16de4ef
fix
Ishan1522 1e56d2e
one meter path exists
fa7dd55
Merge branch 'auto-factories' of https://github.com/TitaniumTigers482…
18d7a1d
deleted unused imports
3aa5a1d
added one meter test auto
340a39b
R
9f8a437
Merge branch 'main' of https://github.com/TitaniumTigers4829/robot-co…
5e2bc4f
more merge fixes
882ee8b
choreos autoChooser is broken I think
14651a8
something isn't working :(
ba7b4be
choreo changes
c49126b
huh
Ishan1522 f73f2d1
adfajsflk
Ishan1522 b30883e
added choreoAutoChooser back but it's still broken
0329107
small fix
dba189f
resets pose at start of auto(uncommented)
5ab07e9
labeled the 2 autochoosers
7958178
wtf why does the autochooser show up right now
d937245
debugging changes
1494a6a
delete extraneous paths.chor
Ishan1522 f830e42
bibbity bobity boop
Ishan1522 92c19c9
wahoo
a006b07
Merge branch 'auto-factories' of https://github.com/TitaniumTigers482…
6e3995a
huh
Ishan1522 dde057b
Merge branch 'auto-factories' of https://github.com/TitaniumTigers482…
Ishan1522 b5f6ee4
choreo path changes
c443bbc
Merge branch 'auto-factories' of https://github.com/TitaniumTigers482…
cbc80a1
started flexiauto stuff
6b25e15
small fix
5c5ad63
if actually works first try im super cool(vscode.dev)
aridavidson001 b3ac9ee
added robotContainer back and cleaned
aridavidson001 7b41e79
ayyy that stuff was important
aridavidson001 635353b
small constants name fixes
aridavidson001 2e9acb4
deleted old commented out code
aridavidson001 407f0d0
Merge branch 'main' into auto-factories
aridavidson001 e8b2f64
bye bye robotContainer! :)
aridavidson001 eb4e016
Merge branch 'main' into auto-factories
aridavidson001 f71864b
check changes
aridavidson001 3c1cac2
more chnages
aridavidson001 3b61b3c
more changes
aridavidson001 6d0bcdf
docstring
aridavidson001 81d97a6
re-added DriveCommand
aridavidson001 3aa4dc9
hhjhj
Ishan1522 3428bf0
it works yay
Ishan1522 3ca92e7
sim changes :)
Ishan1522 42ecdb3
some changes
ef59806
more changes
ed63a6a
more changes
c76424c
wahoo
985cddd
wahoo part 2 electric boogaloo
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
Empty file.
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,47 @@ | ||
package frc.robot; | ||
|
||
import choreo.auto.AutoFactory; | ||
import choreo.auto.AutoRoutine; | ||
import choreo.auto.AutoTrajectory; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import frc.robot.subsystems.example.ExampleSubsystem; | ||
import frc.robot.subsystems.swerve.SwerveDrive; | ||
|
||
public class Autos { | ||
public AutoFactory autoFactory; | ||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public AutoRoutine exampleAutoRoutine( | ||
ExampleSubsystem exampleSubsystem, SwerveDrive swerveDrive) { | ||
|
||
AutoRoutine routine = autoFactory.newRoutine("exampleAutoRoutine"); | ||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
AutoTrajectory startToETraj = routine.trajectory("startToE"); | ||
AutoTrajectory eToPickupTraj = routine.trajectory("eToPickup"); | ||
AutoTrajectory cToPickupTraj = routine.trajectory("cToPickup"); | ||
Check warning on line 20 in src/main/java/frc/robot/Autos.java
|
||
AutoTrajectory pickupToCTraj = routine.trajectory("pickupToC"); | ||
Check warning on line 21 in src/main/java/frc/robot/Autos.java
|
||
|
||
// reset odometry and start first trajectory | ||
routine.active().onTrue(Commands.sequence(startToETraj.resetEstimatedPose(), startToETraj.cmd())); | ||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
startToETraj | ||
.active() | ||
.onTrue( | ||
exampleSubsystem | ||
.exampleFunctionalCommand()); // TODO: replace with elevator to L4 command | ||
startToETraj | ||
.atTime("score") | ||
.onTrue( | ||
exampleSubsystem.exampleFunctionalCommand()); // TODO: replace with command for rollers | ||
startToETraj | ||
.done() | ||
.onTrue( | ||
eToPickupTraj | ||
.cmd() | ||
.alongWith( | ||
exampleSubsystem | ||
.exampleFunctionalCommand())); // TODO: replace with elevator to intake | ||
// command | ||
|
||
return routine; | ||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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
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
42 changes: 42 additions & 0 deletions
42
src/main/java/frc/robot/commands/drive/FollowChoreoTrajectory.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,42 @@ | ||
package frc.robot.commands.drive; | ||
|
||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import choreo.trajectory.SwerveSample; | ||
import frc.robot.subsystems.swerve.SwerveDrive; | ||
import frc.robot.subsystems.vision.VisionSubsystem; | ||
|
||
public class FollowChoreoTrajectory extends DriveCommandBase { | ||
private final SwerveDrive swerveDrive; | ||
private SwerveSample sample; | ||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Constructor without TrajectorySample for AutoFactory | ||
public FollowChoreoTrajectory( | ||
SwerveDrive swerveDrive, VisionSubsystem vision, SwerveSample sample) { | ||
super(swerveDrive, vision); | ||
this.swerveDrive = swerveDrive; | ||
this.sample = sample; | ||
// Use addRequirements() here to declare subsystem dependencies. | ||
addRequirements(swerveDrive, vision); | ||
} | ||
|
||
// 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() { | ||
if (sample != null) { | ||
swerveDrive.followTrajectory(sample); | ||
} | ||
} | ||
|
||
// 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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/frc/robot/subsystems/example/ExampleConstants.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,5 @@ | ||
package frc.robot.subsystems.example; | ||
aridavidson001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public class ExampleConstants { | ||
public static final double SHOOTER_PIVOT_ANGLE = 0 - 9; | ||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/frc/robot/subsystems/example/ExampleSubsystem.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,102 @@ | ||
// 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.example; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.FunctionalCommand; | ||
import edu.wpi.first.wpilibj2.command.StartEndCommand; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import edu.wpi.first.wpilibj2.command.button.Trigger; | ||
import java.util.function.DoubleSupplier; | ||
|
||
public class ExampleSubsystem extends SubsystemBase { | ||
private DoubleSupplier DOUBLELOL; | ||
|
||
/** Creates a new ExampleSubsystem. */ | ||
public ExampleSubsystem() {} | ||
|
||
// this is the skeleton for the subsystem | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
|
||
private void exampleSubsystemFunction() {} | ||
|
||
private void setExamplePivotAngle(double angle) { | ||
// normal subsystem stuff | ||
} | ||
|
||
private double getExamplePivotAngle() { | ||
return 0.0; | ||
} | ||
|
||
private boolean isAngleSet() { | ||
return false; | ||
} | ||
|
||
private boolean isGamepieceinRobot() { | ||
return false; | ||
} | ||
|
||
// Public Command Factory | ||
// create these for everything you would need to access from a command | ||
// so you don't input values or acces the internals of a subsystem in the commands themselves | ||
public Command exampleFunctionalCommand() { | ||
// the command is written here instead of in it's own seperate file. | ||
// this saves space and makes the code more readable | ||
|
||
return new FunctionalCommand( | ||
// does on init | ||
() -> this.setExamplePivotAngle(0), | ||
// does on execute | ||
() -> this.setExamplePivotAngle(1), | ||
// does when command ends | ||
interrupted -> this.setExamplePivotAngle(0), | ||
// ends the command when this is true | ||
() -> getExamplePivotAngle() >= 0, | ||
// requirements for the command | ||
this); | ||
} | ||
|
||
// Shared internal implementation | ||
private Command exampleStartEndCommand() { | ||
// the command is written here instead of in it's own seperate file. | ||
// this saves space and makes the code more readable | ||
|
||
return new StartEndCommand( | ||
// Sets the pivot to 1 while the command is active | ||
() -> this.setExamplePivotAngle(1), | ||
// Sets the pivot to 0 when the command ends | ||
() -> this.setExamplePivotAngle(0), | ||
// requirements for the command | ||
this); | ||
} | ||
|
||
// Shared internal implementation | ||
private Command exampleRunOnceCommand(double angle) { | ||
return this.runOnce(() -> setExamplePivotAngle(angle)); | ||
} | ||
|
||
// Public Command Factory | ||
public Command setPivotToScore() { | ||
return exampleRunOnceCommand(ExampleConstants.SHOOTER_PIVOT_ANGLE); | ||
} | ||
|
||
// Public Command Factory | ||
public Command setPivotToAngle(DoubleSupplier angle) { | ||
// if you need to pass a value in do it this way | ||
return exampleRunOnceCommand(angle.getAsDouble()); | ||
} | ||
|
||
// this is a trigger | ||
// if you need to give information from the subsystem do it like this | ||
// must be a boolean | ||
public final Trigger isAngleInRightSpot = new Trigger(() -> isAngleSet()); | ||
|
||
// another trigger example | ||
public final Trigger hasGamepiece = new Trigger(() -> isGamepieceinRobot()); | ||
} |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.