-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from team422/Shooter
Shooter
- Loading branch information
Showing
39 changed files
with
1,562 additions
and
669 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -41,6 +41,9 @@ | |
|
||
# Log file | ||
*.log | ||
*.wpilog | ||
advantagekit/logs | ||
logs | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
This file contains 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 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
Binary file not shown.
This file contains 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 @@ | ||
[] |
This file contains 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.lib.advantagekit; | ||
|
||
public interface LoggedIO<T> { | ||
public void updateInputs(T inputs); | ||
} |
This file contains 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,58 @@ | ||
package frc.lib.advantagekit; | ||
|
||
import frc.robot.BuildConstants; | ||
// import frc.robot.BuildConstants; | ||
import frc.robot.Robot; | ||
import java.io.File; | ||
import java.nio.file.Path; | ||
import org.littletonrobotics.junction.Logger; | ||
import org.littletonrobotics.junction.networktables.NT4Publisher; | ||
import org.littletonrobotics.junction.wpilog.WPILOGWriter; | ||
|
||
public class LoggerUtil { | ||
public static final String kLogDirectory = "advantagekit/logs"; | ||
|
||
public static void initializeLogger() { | ||
|
||
// Record metadata | ||
Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME); | ||
Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE); | ||
Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA); | ||
Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE); | ||
Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH); | ||
Logger.recordMetadata("GitDirty", getGitDirtyString()); | ||
|
||
// Set up data receivers & replay source | ||
if (Robot.isSimulation()) { | ||
Logger.addDataReceiver(new WPILOGWriter(getLogPath())); | ||
Logger.addDataReceiver(new NT4Publisher()); | ||
} else { | ||
Logger.addDataReceiver(new WPILOGWriter("/media/sda1/")); | ||
Logger.addDataReceiver(new NT4Publisher()); | ||
} | ||
|
||
// Start AdvantageKit logger | ||
Logger.start(); | ||
} | ||
|
||
private static String getGitDirtyString() { | ||
switch (BuildConstants.DIRTY) { | ||
case 0: | ||
return "All changes committed"; | ||
case 1: | ||
return "Uncomitted changes"; | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
|
||
private static String getLogPath() { | ||
File file = Path.of(kLogDirectory).toFile(); | ||
|
||
if (!file.exists()) { | ||
file.mkdirs(); | ||
} | ||
|
||
return file.getAbsolutePath(); | ||
} | ||
} |
This file contains 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,122 @@ | ||
package frc.lib.utils; | ||
|
||
import frc.robot.Constants; | ||
// FROM 6328 Mechanical Advantage | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import org.littletonrobotics.junction.networktables.LoggedDashboardNumber; | ||
|
||
/** | ||
* Class for a tunable number. Gets value from dashboard in tuning mode, returns default if not or | ||
* value not in dashboard. | ||
*/ | ||
public class LoggedTunableNumber { | ||
private static final String tableKey = "TunableNumbers"; | ||
|
||
private final String key; | ||
private boolean hasDefault = false; | ||
private double defaultValue; | ||
private LoggedDashboardNumber dashboardNumber; | ||
private Map<Integer, Double> lastHasChangedValues = new HashMap<>(); | ||
|
||
/** | ||
* Create a new LoggedTunableNumber | ||
* | ||
* @param dashboardKey Key on dashboard | ||
*/ | ||
public LoggedTunableNumber(String dashboardKey, String tableKey) { | ||
this.key = tableKey + "/" + dashboardKey; | ||
// this.key = tableKey + "/" + dashboardKey; | ||
} | ||
|
||
/** | ||
* Create a new LoggedTunableNumber with the default value | ||
* | ||
* @param dashboardKey Key on dashboard | ||
* @param defaultValue Default value | ||
*/ | ||
public LoggedTunableNumber(String dashboardKey, double defaultValue) { | ||
this(dashboardKey, tableKey); | ||
initDefault(defaultValue); | ||
} | ||
|
||
public LoggedTunableNumber(String dashboardKey, double defaultValue, String tableKey) { | ||
this(dashboardKey, tableKey); | ||
initDefault(defaultValue); | ||
} | ||
|
||
/** | ||
* Set the default value of the number. The default value can only be set once. | ||
* | ||
* @param defaultValue The default value | ||
*/ | ||
public void initDefault(double defaultValue) { | ||
if (!hasDefault) { | ||
hasDefault = true; | ||
this.defaultValue = defaultValue; | ||
if (Constants.tuningMode) { | ||
dashboardNumber = new LoggedDashboardNumber(key, defaultValue); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the current value, from dashboard if available and in tuning mode. | ||
* | ||
* @return The current value | ||
*/ | ||
public double get() { | ||
if (!hasDefault) { | ||
return 0.0; | ||
} else { | ||
return Constants.tuningMode ? dashboardNumber.get() : defaultValue; | ||
} | ||
} | ||
|
||
public void set(double val) { | ||
dashboardNumber.set(val); | ||
} | ||
|
||
/** | ||
* Checks whether the number has changed since our last check | ||
* | ||
* @param id Unique identifier for the caller to avoid conflicts when shared between multiple | ||
* objects. Recommended approach is to pass the result of "hashCode()" | ||
* @return True if the number has changed since the last time this method was called, false | ||
* otherwise. | ||
*/ | ||
public boolean hasChanged(int id) { | ||
if (!Constants.tuningMode) return false; | ||
double currentValue = get(); | ||
Double lastValue = lastHasChangedValues.get(id); | ||
if (lastValue == null || currentValue != lastValue) { | ||
lastHasChangedValues.put(id, currentValue); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Runs action if any of the tunableNumbers have changed | ||
* | ||
* @param id Unique identifier for the caller to avoid conflicts when shared between multiple * | ||
* objects. Recommended approach is to pass the result of "hashCode()" | ||
* @param action Callback to run when any of the tunable numbers have changed. Access tunable | ||
* numbers in order inputted in method | ||
* @param tunableNumbers All tunable numbers to check | ||
*/ | ||
public static void ifChanged( | ||
int id, Consumer<double[]> action, LoggedTunableNumber... tunableNumbers) { | ||
if (Arrays.stream(tunableNumbers).anyMatch(tunableNumber -> tunableNumber.hasChanged(id))) { | ||
action.accept(Arrays.stream(tunableNumbers).mapToDouble(LoggedTunableNumber::get).toArray()); | ||
} | ||
} | ||
|
||
/** Runs action if any of the tunableNumbers have changed */ | ||
public static void ifChanged(int id, Runnable action, LoggedTunableNumber... tunableNumbers) { | ||
ifChanged(id, values -> action.run(), tunableNumbers); | ||
} | ||
} |
This file contains 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,90 @@ | ||
package frc.lib.utils; | ||
|
||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import frc.robot.Constants; | ||
|
||
/** | ||
* Class for a tunable number. Gets value from dashboard in tuning mode, returns default if not or | ||
* value not in dashboard. | ||
*/ | ||
public class TunableNumber { | ||
private static final String tableKey = "TunableNumbers"; | ||
|
||
private String key; | ||
private double defaultValue; | ||
private double lastHasChangedValue = defaultValue; | ||
|
||
/** | ||
* Create a new TunableNumber | ||
* | ||
* @param dashboardKey Key on dashboard | ||
*/ | ||
public TunableNumber(String tableString, String dashboardKey) { | ||
this.key = tableString + "/" + dashboardKey; | ||
} | ||
|
||
/** | ||
* Create a new TunableNumber with the default value | ||
* | ||
* @param dashboardKey Key on dashboard | ||
* @param defaultValue Default value | ||
*/ | ||
public TunableNumber(String dashboardKey, double defaultValue) { | ||
this(tableKey, dashboardKey); | ||
setDefault(defaultValue); | ||
} | ||
|
||
public TunableNumber(String dashboardKey, double defaultValue, String tableKey) { | ||
this(tableKey, dashboardKey); | ||
setDefault(defaultValue); | ||
} | ||
|
||
/** | ||
* Get the default value for the number that has been set | ||
* | ||
* @return The default value | ||
*/ | ||
public double getDefault() { | ||
return defaultValue; | ||
} | ||
|
||
/** | ||
* Set the default value of the number | ||
* | ||
* @param defaultValue The default value | ||
*/ | ||
public void setDefault(double defaultValue) { | ||
this.defaultValue = defaultValue; | ||
if (Constants.tuningMode) { | ||
// This makes sure the data is on NetworkTables but will not change it | ||
SmartDashboard.putNumber(key, SmartDashboard.getNumber(key, defaultValue)); | ||
} else { | ||
SmartDashboard.clearPersistent(key); | ||
} | ||
} | ||
|
||
/** | ||
* Get the current value, from dashboard if available and in tuning mode | ||
* | ||
* @return The current value | ||
*/ | ||
public double get() { | ||
return Constants.tuningMode ? SmartDashboard.getNumber(key, defaultValue) : defaultValue; | ||
} | ||
|
||
/** | ||
* Checks whether the number has changed since our last check | ||
* | ||
* @return True if the number has changed since the last time this method was called, false | ||
* otherwise | ||
*/ | ||
public boolean hasChanged() { | ||
double currentValue = get(); | ||
if (currentValue != lastHasChangedValue) { | ||
lastHasChangedValue = currentValue; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.