Skip to content

Commit

Permalink
added some more things for autonomous information
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTaylor29 committed Jan 18, 2025
1 parent d924f64 commit 7c8733e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/main/java/frc/lib/AutoOption.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package frc.lib;

import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.Command;
import choreo.auto.AutoRoutine;
import java.util.Optional;

public class AutoOption {
private Alliance m_color;
private int m_option;
private Optional<AutoRoutine> m_auto;
private String name;

/**
* Constructs a selectable autonomous mode option
Expand All @@ -16,10 +18,11 @@ public class AutoOption {
* @param option Selector switch index for which the option is valid
* @param auto Command which runs the autonomous mode
*/
public AutoOption(Alliance color, int option, AutoRoutine auto) {
public AutoOption(Alliance color, int option, AutoRoutine auto, String name) {
this.m_color = color;
this.m_option = option;
this.m_auto = Optional.of(auto);
this.name = name;
}

/**
Expand Down Expand Up @@ -51,7 +54,11 @@ public int getOption() {
/**
* @return The command which runs the selected autonomous mode
*/
public Optional<AutoRoutine> getChoreoAuto() {
return this.m_auto;
public Optional<Command> getAutoCommand() {
return Optional.of(this.m_auto.get().cmd());
}

public String getName() {
return this.name;
}
}
16 changes: 9 additions & 7 deletions src/main/java/frc/lib/AutoSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import choreo.auto.AutoRoutine;
import java.util.List;
Expand All @@ -13,10 +14,11 @@

public class AutoSelector {

private Optional<AutoRoutine> m_currentAuto;
private Optional<Command> m_currentAuto;
private DigitalInput[] m_switchPositions;
private Supplier<Alliance> m_allianceColorSupplier;
private List<AutoOption> m_autoOptions;
private AutoOption m_autoOption;
private EventLoop m_loop = new EventLoop();
private BooleanEvent m_changedAutoSelection;

Expand Down Expand Up @@ -56,16 +58,16 @@ private Alliance getAllianceColor() {
return m_allianceColorSupplier.get();
}

private Optional<AutoRoutine> findMatchingOption() {
private Optional<Command> findMatchingOption() {
return m_autoOptions.stream()
.filter(o -> o.getColor() == getAllianceColor())
.filter(o -> o.getOption() == getSwitchPosition())
.findFirst()
.flatMap(AutoOption::getChoreoAuto);
.flatMap(AutoOption::getAutoCommand);
}

private boolean updateAuto() {
Optional<AutoRoutine> m_newAuto = findMatchingOption();
Optional<Command> m_newAuto = findMatchingOption();
if (m_newAuto.equals(m_currentAuto)) return false;
else {
m_currentAuto = m_newAuto;
Expand All @@ -82,12 +84,12 @@ public Trigger getChangedAutoSelection() {

/** Schedules the command corresponding to the selected autonomous mode */
public void scheduleAuto() {
if (m_currentAuto.isPresent()) m_currentAuto.get().cmd().schedule();
m_currentAuto.ifPresent(o -> o.schedule());
}

/** Deschedules the command corresponding to the selected autonomous mode */
public void cancelAuto() {
if (m_currentAuto.isPresent()) m_currentAuto.get().cmd().cancel();
m_currentAuto.ifPresent(o -> o.cancel());
}

public void disabledPeriodic() {
Expand All @@ -96,7 +98,7 @@ public void disabledPeriodic() {
SmartDashboard.putNumber("Auto Selector Switch Position", getSwitchPosition());

if (m_currentAuto.isPresent()) {
SmartDashboard.putString("Auto", m_currentAuto.get().toString());
SmartDashboard.putString("Auto", m_currentAuto.get().getName());
} else {
SmartDashboard.putString("Auto", "Null");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void configureEventBindings() {

private void configureAutoOptions() {
m_autoOptions.add(new AutoOption(Alliance.Red, 4));
m_autoOptions.add(new AutoOption(Alliance.Blue, 1, m_auto.exampleRoutine()));
m_autoOptions.add(new AutoOption(Alliance.Blue, 1, m_auto.exampleRoutine(), "exampleAuto"));
}

/**
Expand Down

0 comments on commit 7c8733e

Please sign in to comment.