Change the off logging level to behave properly

Reduce the amount of strings created when logging
Add a temporary to do list to the read me file
This commit is contained in:
nathanrsxtn
2022-04-17 23:31:44 -06:00
parent e73d1c1d98
commit a95c97e4fe
5 changed files with 56 additions and 211 deletions
+29 -1
View File
@@ -1 +1,29 @@
# I don't know what to put here
# Experimental
## To Do
- [x] Rewrite target tracking.
- [x] Cleanup robot map.
- [x] Cleanup robot.
- [x] Change swerve module ordering to be consistent.
- [x] Remove old-style autonomous programs.
- [x] Change HAL logging to use custom formatting on its output stream.
- [x] Use original HAL logging when custom logging is off.
- [x] Change SparkMax sendable implementation to be an extension.
- [x] Add Shuffleboard layout plan.
- [ ] Organize constants.
- [ ] Efficiently load path files.
- [ ] Change the path chooser to select autonomous commands.
- [ ] Remove unused commands.
- [ ] Rewrite controller bindings.
- [ ] Write new-style autonomous programs for lower ball counts.
- [ ] Fix all XXX comments.
- [ ] Visit TODO comments.
- [ ] Forward the limelight port so it can be accessed over a USB tether.
## Planned
- [ ] Shuffleboard replacements options:
- [ ] Run a web server on the robot and bypass network tables.
- [ ] Run a web server on the drive laptop that accesses network tables.
- [ ] Write a network tables client in C++.
- [ ] Consider combining intake, serializer, and storage into a single subsystem.
- [ ] Consider combining turret, hood, and flywheels into a single subsystem.
- [ ] Move the network tables recorded path downloader into a Shuffleboard plugin.
- [ ] Finish the graph and web Shuffleboard widgets.
@@ -563,28 +563,30 @@ public class DriverStation {
boolean printTrace,
StackTraceElement[] stackTrace,
int stackTraceFirst) {
if (!frc4388.utility.AnsiLogging.LEVEL.equals(java.util.logging.Level.OFF)) {
java.util.logging.LogRecord logRecord = new java.util.logging.LogRecord(isError ? java.util.logging.Level.SEVERE : java.util.logging.Level.FINER, error.stripTrailing());
logRecord.setLoggerName("HAL");
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
java.util.Optional.ofNullable(stackTrace).filter(s -> s.length >= stackTraceFirst + 1).map(s -> java.util.Arrays.copyOfRange(s, Math.min(Math.max(0, stackTraceFirst), s.length - 1), s.length - 1)).ifPresent(presentStackTrace -> {
logRecord.setSourceMethodName(presentStackTrace[0].getMethodName());
String throwableMessage;
if (presentStackTrace[0].toString().equals("edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:63)")) {
throwableMessage = "Epochs" + System.lineSeparator() + logRecord.getMessage();
presentStackTrace = new java.lang.StackTraceElement[0];
logRecord.setLevel(java.util.logging.Level.FINEST);
logRecord.setMessage("Execution times:");
} else if (printTrace) {
long lineCount = logRecord.getMessage().lines().count();
throwableMessage = (lineCount > 1 ? logRecord.getMessage().lines().findFirst().map(s -> s + " + " + lineCount + " more lines...").orElse("") : logRecord.getMessage()).stripLeading();
} else return;
java.lang.Throwable throwable = new java.lang.Throwable(throwableMessage);
throwable.setStackTrace(presentStackTrace);
logRecord.setThrown(throwable);
});
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
frc4388.utility.AnsiLogging.halLoggerHandler.publish(logRecord);
if (frc4388.utility.AnsiLogging.halLoggerHandler != null) {
if (!frc4388.utility.AnsiLogging.LEVEL.equals(java.util.logging.Level.OFF)) {
java.util.logging.LogRecord logRecord = new java.util.logging.LogRecord(isError ? java.util.logging.Level.SEVERE : java.util.logging.Level.FINER, error.stripTrailing());
logRecord.setLoggerName("HAL");
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
java.util.Optional.ofNullable(stackTrace).filter(s -> s.length >= stackTraceFirst + 1).map(s -> java.util.Arrays.copyOfRange(s, Math.min(Math.max(0, stackTraceFirst), s.length - 1), s.length - 1)).ifPresent(presentStackTrace -> {
logRecord.setSourceMethodName(presentStackTrace[0].getMethodName());
String throwableMessage;
if (presentStackTrace[0].toString().equals("edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:63)")) {
throwableMessage = "Epochs" + System.lineSeparator() + logRecord.getMessage();
presentStackTrace = new java.lang.StackTraceElement[0];
logRecord.setLevel(java.util.logging.Level.FINEST);
logRecord.setMessage("Execution times:");
} else if (printTrace) {
long lineCount = logRecord.getMessage().lines().count();
throwableMessage = (lineCount > 1 ? logRecord.getMessage().lines().findFirst().map(s -> s + " + " + lineCount + " more lines...").orElse("") : logRecord.getMessage()).stripLeading();
} else return;
java.lang.Throwable throwable = new java.lang.Throwable(throwableMessage);
throwable.setStackTrace(presentStackTrace);
logRecord.setThrown(throwable);
});
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
frc4388.utility.AnsiLogging.halLoggerHandler.publish(logRecord);
}
} else {
String locString;
if (stackTrace.length >= stackTraceFirst + 1) {
@@ -14,7 +14,6 @@ import com.revrobotics.CANSparkMax.IdleMode;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.motorcontrol.Spark;
import frc4388.robot.Constants.ClimberConstants;
@@ -35,9 +35,8 @@ public class AnsiLogging {
public static final Level LEVEL = Level.ALL;
private static final AnsiPrintStream ANSI_CONSOLE_STREAM = AnsiConsole.err();
public static Handler halLoggerHandler = new ConsoleHandler();
public static Handler halLoggerHandler = null;
public static void systemInstall() {
if (LEVEL.equals(Level.OFF)) return;
try {
// Configure java.util.logging.Logger to output additional colored information.
LogManager.getLogManager().updateConfiguration(key -> (o, n) -> {
@@ -60,7 +59,6 @@ public class AnsiLogging {
DurianPlugins.register(Errors.Plugins.Log.class, e -> Logger.getLogger(e.getStackTrace()[0].getClassName().substring(e.getStackTrace()[0].getClassName().lastIndexOf('.') + 1)).log(Level.SEVERE, e, e::getLocalizedMessage));
// Store the handler for HAL to use when sending errors to DriverStation.
halLoggerHandler = new LoggingAnsiConsoleHandler(new HalOutputStream());
// Logger.getLogger(name)
} catch (IOException exception) {
exception.printStackTrace(AnsiConsole.sysErr());
}
@@ -132,7 +130,7 @@ public class AnsiLogging {
@Override
public void flush() throws IOException {
String s = toString();
if (!s.isBlank()) logger.logp(level, null, source, toString());
if (!s.isBlank()) logger.logp(level, null, source, s);
reset();
}
}, true);
@@ -146,8 +144,7 @@ public class AnsiLogging {
}
@Override
public void flush() {
String s = toString();
HAL.sendError(false, 0, false, s.substring(0, s.length() - 1), "", "", true);
HAL.sendError(false, 0, false, new String(buf, 0, count - 1), "", "", true);
reset();
}
}
@@ -1,181 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc4388.utility;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import com.kauailabs.navx.frc.AHRS;
import org.junit.*;
import frc4388.mocks.MockPigeonIMU;
import frc4388.robot.Constants.ArcadeDriveConstants;
/**
* Add your docs here.
*/
public class RobotGyroUtilityTest {
// TODO UNTESTED: most functions for NavX
private RobotGyro gyroPigeon;
private RobotGyro gyroNavX;
@Test
public void testConstructor() {
// Arrange
MockPigeonIMU pigeon = new MockPigeonIMU(ArcadeDriveConstants.DRIVE_PIGEON_ID);
AHRS navX = mock(AHRS.class);
gyroPigeon = new RobotGyro(pigeon);
gyroNavX = new RobotGyro(navX);
// Assert
assertEquals(true, gyroPigeon.m_isGyroAPigeon);
assertEquals(pigeon, gyroPigeon.getPigeon());
assertEquals(null, gyroPigeon.getNavX());
assertEquals(false, gyroNavX.m_isGyroAPigeon);
assertEquals(navX, gyroNavX.getNavX());
assertEquals(null, gyroNavX.getPigeon());
}
@Test
public void testHeadingPigeon() {
// Arrange
MockPigeonIMU pigeon = new MockPigeonIMU(ArcadeDriveConstants.DRIVE_PIGEON_ID);
gyroPigeon = new RobotGyro(pigeon);
// Act & Assert
assertEquals(-90, gyroPigeon.getHeading(270), 0.0001);
assertEquals(-45, gyroPigeon.getHeading(315), 0.0001);
assertEquals(-60, gyroPigeon.getHeading(-60), 0.0001);
assertEquals(30, gyroPigeon.getHeading(30), 0.0001);
assertEquals(0, gyroPigeon.getHeading(0), 0.0001);
assertEquals(180, gyroPigeon.getHeading(180), 0.0001);
assertEquals(-180, gyroPigeon.getHeading(-180), 0.0001);
assertEquals(97, gyroPigeon.getHeading(1537), 0.0001);
assertEquals(99, gyroPigeon.getHeading(-2781), 0.0001);
}
@Test
public void testYawPitchRollPigeon() {
// Arrange
MockPigeonIMU pigeon = new MockPigeonIMU(ArcadeDriveConstants.DRIVE_PIGEON_ID);
gyroPigeon = new RobotGyro(pigeon);
// Assert
assertEquals(0, gyroPigeon.getAngle(), 0.0001);
// Act
pigeon.setYaw(40);
// Assert
assertEquals(40, gyroPigeon.getAngle(), 0.0001);
// Act
gyroPigeon.reset();
// Assert
assertEquals(0, gyroPigeon.getAngle(), 0.0001);
// Act
pigeon.setYaw(-1457);
pigeon.setCurrentPitch(100);
pigeon.setCurrentRoll(100);
// Assert
assertEquals(-1457, gyroPigeon.getAngle(), 0.0001);
assertEquals(90, gyroPigeon.getPitch(), 0.0001);
assertEquals(90, gyroPigeon.getRoll(), 0.0001);
// Act
pigeon.setCurrentPitch(45);
pigeon.setCurrentRoll(45);
// Assert
assertEquals(45, gyroPigeon.getPitch(), 0.0001);
assertEquals(45, gyroPigeon.getRoll(), 0.0001);
// Act
pigeon.setCurrentPitch(0);
pigeon.setCurrentRoll(0);
// Assert
assertEquals(0, gyroPigeon.getPitch(), 0.0001);
assertEquals(0, gyroPigeon.getRoll(), 0.0001);
// Act
pigeon.setCurrentPitch(-60);
pigeon.setCurrentRoll(-60);
// Assert
assertEquals(-60, gyroPigeon.getPitch(), 0.0001);
assertEquals(-60, gyroPigeon.getRoll(), 0.0001);
// Act
pigeon.setCurrentPitch(-90);
pigeon.setCurrentRoll(-90);
// Assert
assertEquals(-90, gyroPigeon.getPitch(), 0.0001);
assertEquals(-90, gyroPigeon.getRoll(), 0.0001);
// Act
pigeon.setCurrentPitch(-100);
pigeon.setCurrentRoll(-100);
// Assert
assertEquals(-90, gyroPigeon.getPitch(), 0.0001);
assertEquals(-90, gyroPigeon.getRoll(), 0.0001);
}
@Test
public void testRatesPigeon() {
// Arrange
MockPigeonIMU pigeon = new MockPigeonIMU(ArcadeDriveConstants.DRIVE_PIGEON_ID);
gyroPigeon = new RobotGyro(pigeon);
RobotTime robotTime = RobotTime.getInstance();
gyroPigeon.updatePigeonDeltas();
// Act
robotTime.m_deltaTime = 5;
pigeon.setYaw(0);
gyroPigeon.updatePigeonDeltas();
// Assert
assertEquals(0, gyroPigeon.getRate(), 1);
// Act
robotTime.m_deltaTime = 5;
pigeon.setYaw(90);
gyroPigeon.updatePigeonDeltas();
// Assert
assertEquals(18000, gyroPigeon.getRate(), 0.001);
// Act
robotTime.m_deltaTime = 5;
pigeon.setYaw(90);
gyroPigeon.updatePigeonDeltas();
// Assert
assertEquals(0, gyroPigeon.getRate(), 0.001);
// Act
robotTime.m_deltaTime = 3;
pigeon.setYaw(-30);
gyroPigeon.updatePigeonDeltas();
// Assert
assertEquals(-40000, gyroPigeon.getRate(), 0.001);
// Act
robotTime.m_deltaTime = 6;
pigeon.setYaw(690);
gyroPigeon.updatePigeonDeltas();
// Assert
assertEquals(120000, gyroPigeon.getRate(), 0.001);
}
}