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

First pass at integrating AdvantageKit into MaroonFramework #34

Merged
merged 12 commits into from
Jan 15, 2024
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ allprojects {

// REV
maven { url = uri('https://maven.revrobotics.com/') }

// AdvantageKit
maven {
url = uri("https://maven.pkg.github.com/Mechanical-Advantage/AdvantageKit")
credentials {
username = "Mechanical-Advantage-Bot"
password = "\u0067\u0068\u0070\u005f\u006e\u0056\u0051\u006a\u0055\u004f\u004c\u0061\u0079\u0066\u006e\u0078\u006e\u0037\u0051\u0049\u0054\u0042\u0032\u004c\u004a\u006d\u0055\u0070\u0073\u0031\u006d\u0037\u004c\u005a\u0030\u0076\u0062\u0070\u0063\u0051"
dejabot marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

//AdvantageKit code
configurations.all {
exclude group: "edu.wpi.first.wpilibj"
}
}

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/team766/hal/wpilib/RobotMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
//import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Supplier;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;
import com.team766.config.ConfigFileReader;
import com.team766.framework.Scheduler;
import com.team766.hal.GenericRobotMain;
import com.team766.hal.RobotProvider;
import com.team766.logging.LoggerExceptionUtils;

import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Filesystem;
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;

public class RobotMain extends TimedRobot {
public class RobotMain extends LoggedRobot {
// this file, if present, will be a symlink to one of several config files in the deploy directory.
// this allows for the same code to be deployed to multiple physical robots, each with their own
// config file with CAN bus port mappings, etc, with the actual file used for a specific robot
Expand Down Expand Up @@ -81,6 +89,20 @@ public void robotInit() {
RobotProvider.instance = new WPIRobotProvider();
robot = new GenericRobotMain();

DriverStation.startDataLog(DataLogManager.getLog());

if (isReal()) {
DataLogManager.log("Initializing logging.");
Logger.getInstance().addDataReceiver(new WPILOGWriter("/U/logs")); // Log to sdcard
Logger.getInstance().addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
new PowerDistribution(1, ModuleType.kRev); // Enables power distribution logging

} else {
// TODO: add support for simulation logging/replay
}

Logger.getInstance().start();

robot.robotInit();
} catch (Exception e) {
e.printStackTrace();
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/team766/logging/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

import com.team766.config.ConfigFileReader;
import com.team766.library.CircularBuffer;
import edu.wpi.first.wpilibj.DataLogManager;

public final class Logger {

private static final boolean ALSO_LOG_TO_DATALOG = true;

private static class LogUncaughtException implements Thread.UncaughtExceptionHandler {
public void uncaughtException(final Thread t, final Throwable e) {
e.printStackTrace();
Expand Down Expand Up @@ -96,15 +100,19 @@ public Collection<LogEntry> recentEntries() {
public void logData(final Severity severity, final String format, final Object... args) {
var entry = LogEntry.newBuilder().setTime(getTime()).setSeverity(severity)
.setCategory(m_category);
entry.setMessageStr(String.format(format, args));
String message = String.format(format, args);
entry.setMessageStr(message);
m_recentEntries.add(entry.build());
entry.setMessageStr(format);
dejabot marked this conversation as resolved.
Show resolved Hide resolved

for (Object arg : args) {
SerializationUtils.valueToProto(arg, entry.addArgBuilder());
}
if (m_logWriter != null) {
m_logWriter.logStoredFormat(entry);
}
if (ALSO_LOG_TO_DATALOG) {
DataLogManager.log(message);
dejabot marked this conversation as resolved.
Show resolved Hide resolved
}
}

public void logRaw(final Severity severity, final String message) {
Expand All @@ -114,6 +122,9 @@ public void logRaw(final Severity severity, final String message) {
if (m_logWriter != null) {
m_logWriter.log(entry);
}
if (ALSO_LOG_TO_DATALOG) {
DataLogManager.log(message);
}
}

void logOnlyInMemory(final Severity severity, final String message) {
Expand Down
41 changes: 41 additions & 0 deletions vendordeps/AdvantageKit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"fileName": "AdvantageKit.json",
"name": "AdvantageKit",
"version": "2.2.4",
"uuid": "d820cc26-74e3-11ec-90d6-0242ac120003",
"mavenUrls": [],
"jsonUrl": "https://github.com/Mechanical-Advantage/AdvantageKit/releases/latest/download/AdvantageKit.json",
"javaDependencies": [
{
"groupId": "org.littletonrobotics.akit.junction",
"artifactId": "wpilib-shim",
"version": "2.2.4"
},
{
"groupId": "org.littletonrobotics.akit.junction",
"artifactId": "junction-core",
"version": "2.2.4"
},
{
"groupId": "org.littletonrobotics.akit.conduit",
"artifactId": "conduit-api",
"version": "2.2.4"
}
],
"jniDependencies": [
{
"groupId": "org.littletonrobotics.akit.conduit",
"artifactId": "conduit-wpilibio",
"version": "2.2.4",
"skipInvalidPlatforms": false,
"isJar": false,
"validPlatforms": [
"linuxathena",
"windowsx86-64",
"linuxx86-64",
"osxuniversal"
]
}
],
"cppDependencies": []
}