-
Notifications
You must be signed in to change notification settings - Fork 0
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
Make a teleop actionRunner #22
Conversation
Co-authored-by: Julian Sprague <julspr@users.noreply.github.com>
if (shoot != null) { | ||
if (shoot.isDone() == true) { | ||
shoot = null; | ||
} | ||
} |
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.
this originally ran the code to shoot the note, as we are changing how we tell the code to shoot the note, this isn't needed anymore, so we deleted it
@@ -52,11 +47,8 @@ private static void doShooterIntake() { | |||
} | |||
} | |||
|
|||
static AutonShoot shoot = null; | |||
|
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.
originally, we set this variable to null when we weren't shooting, as we don't shoot at the start, we declared the variable to be null at the start
private static void shootIntoSpeaker() { | ||
shoot = new AutonShoot(); | ||
shoot.initiate(); | ||
Robot.getTeleopActionRunner().addActionToRun(new AutonShoot()); |
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.
before, we set the shoot variable to an AutonShoot() and initiated it, now we add the AutonShoot to the TeleopActionRunner, which runs all actions it is given at the same time until they are done.
import frc.robot.auton.AutonRoutes; | ||
import frc.robot.auton.ParallelActionRunner; | ||
import frc.robot.auton.SequentialActionRunner; |
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.
we renamed AutonActionRunner to ParellelActionRunner to describe what it does and not how we use it, and added SequentialActionRunner, and we use both in Robot.java, so they both need to be imported
@@ -44,7 +45,13 @@ public class Robot extends TimedRobot { | |||
XboxController driverController = new XboxController(Constants.DRIVER_CONTROLLER_ID); | |||
XboxController coDriverController = new XboxController(1); | |||
static AHRS navX = new AHRS(SPI.Port.kMXP); | |||
AutonActionRunner auton; | |||
SequentialActionRunner auton; |
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.
we renamed AutonActionRunner to ParallelActionRunner
public static ParallelActionRunner getTeleopActionRunner() { | ||
return teleopActionRunner; | ||
} | ||
|
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.
teleopActionRunner is the ActionRunner we use in teleop, we make a getter for it so we can give it actions to run in inputtedCoDriverControlls.
@@ -150,7 +157,7 @@ public void autonomousInit() { | |||
default -> new ArrayDeque<AutonAction>(); | |||
}; | |||
System.out.println("selected auton: " + route); | |||
auton = new AutonActionRunner(route); | |||
auton = new SequentialActionRunner(route); |
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.
we renamed AutonActionRunner to ParallelActionRunner
@@ -192,6 +199,7 @@ public void teleopInit() {} | |||
/** This function is called periodically during operator control. */ | |||
@Override | |||
public void teleopPeriodic() { | |||
teleopActionRunner.onEveryFrame(); |
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.
this tells teleopActionRunner to run all of it's Actions every frame of teleop
@@ -7,5 +7,4 @@ public AutonAction() {} | |||
public abstract boolean isDone(); | |||
|
|||
public abstract void initiate(); | |||
//public/private abstract TYPE NAME(ARGUMENTS); |
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.
it is a comment that isn't helping us, so we deleted it.
public void onEveryFrame() { | ||
for (int i = 0; i < actions.size(); i++) { | ||
AutonAction action = actions.get(i); | ||
if (action.isDone()) { | ||
actions.remove(i); | ||
i--; | ||
} | ||
} | ||
} |
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.
Instead of doing a loop with indexes here, you could do something like
for (AutonAction action : actions) {
if (action.isDone()) {
actions.remove(action);
}
}
This way you don't have to deal with indexes at all
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.
So turns out I'm wrong and Java is weird. You can do it in a way with iterators like this
https://stackoverflow.com/questions/1196586/calling-remove-in-foreach-loop-in-java
But if you guys aren't comfortable with that then you can just keep it like you have it!
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.
seems legit
we renamed AutonActionRunner to SequentialActionRunner to make the name describe what the function does and not what the function is used for, and we added ParallelActionRunner, ParallelActionRunner runs all of the actions it has been given at the same time.