Skip to content
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

Merged
merged 4 commits into from
Feb 24, 2024
Merged

Make a teleop actionRunner #22

merged 4 commits into from
Feb 24, 2024

Conversation

team6101
Copy link
Collaborator

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.

Co-authored-by: Julian Sprague <julspr@users.noreply.github.com>
Comment on lines -23 to -27
if (shoot != null) {
if (shoot.isDone() == true) {
shoot = null;
}
}
Copy link
Collaborator Author

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;

Copy link
Collaborator Author

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());
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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;
}

Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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();
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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.

Comment on lines +15 to +23
public void onEveryFrame() {
for (int i = 0; i < actions.size(); i++) {
AutonAction action = actions.get(i);
if (action.isDone()) {
actions.remove(i);
i--;
}
}
}
Copy link
Member

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

Copy link
Member

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!

Nanosplitter
Nanosplitter previously approved these changes Feb 24, 2024
Copy link
Contributor

@BookSerpent BookSerpent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legit

@BookSerpent BookSerpent merged commit 2addd70 into main Feb 24, 2024
2 checks passed
@atsuke-axolotl atsuke-axolotl deleted the add-auton-actions-to-teleop branch February 24, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants