### Subsystem Logging Example with Tunable Parameters (Java) Source: https://context7.com/jonahsnider/doglog/llms.txt This example showcases advanced DogLog integration within an FRC subsystem, demonstrating how to log motor telemetry, sensor values, and fault conditions. It also illustrates the use of `DogLog.tunable` for real-time adjustment of PID controller parameters without code redeployment. Dependencies include WPILib and REV Robotics CANSparkMax. Input is sensor data and tunable parameters; output is logged telemetry and fault indicators. ```java // Complete subsystem example with logging import dev.doglog.DogLog; import edu.wpi.first.wpilibj2.command.SubsystemBase; import com.revrobotics.CANSparkMax; public class ElevatorSubsystem extends SubsystemBase { private final CANSparkMax motor = new CANSparkMax(10, MotorType.kBrushless); private final DoubleSubscriber kP = DogLog.tunable("Elevator/kP", 0.2); public ElevatorSubsystem() { DogLog.log("Elevator/Initialized", true); } @Override public void periodic() { // Log telemetry every 20ms DogLog.log("Elevator/Position", motor.getEncoder().getPosition()); DogLog.log("Elevator/Velocity", motor.getEncoder().getVelocity()); DogLog.log("Elevator/Current", motor.getOutputCurrent(), "Amps"); DogLog.log("Elevator/Voltage", motor.getAppliedOutput() * 12.0, "Volts"); // Check for faults if (motor.getOutputCurrent() > 30.0) { DogLog.logFault("Elevator/OverCurrent"); } // Use tunable values pidController.setP(kP.get()); } } ``` -------------------------------- ### Install DogLog Vendordep and Basic Robot Logging (Java) Source: https://context7.com/jonahsnider/doglog/llms.txt This snippet demonstrates how to add DogLog to an FRC robot project using the WPILib vendordep system and includes basic usage within the Robot.java file. It covers initial setup, optional configuration, and logging telemetry data during different robot modes. No external dependencies beyond WPILib are required. ```java // 1. Add vendordep via URL in WPILib VS Code // Click WPILib icon -> Manage Vendor Libraries -> Install new library (online) // Enter URL: https://doglog.dev/vendordep.json // 2. Import and use in Robot.java import dev.doglog.DogLog; public class Robot extends TimedRobot { @Override public void robotInit() { // Optional: Configure DogLog (defaults are competition-safe) DogLog.setOptions(new DogLogOptions().withNtPublish(true)); } @Override public void robotPeriodic() { // Start logging immediately - no additional setup required DogLog.log("Robot/Timestamp", Timer.getFPGATimestamp()); } @Override public void autonomousPeriodic() { DogLog.log("Auto/Enabled", true); } @Override public void teleopPeriodic() { DogLog.log("Teleop/Enabled", true); } } ``` -------------------------------- ### Vendordep URL for DogLog Installation Source: https://github.com/jonahsnider/doglog/blob/main/README.md This is the vendordep URL required to install the DogLog library through the WPILib VS Code extension. It allows teams to quickly integrate DogLog into their FRC projects without manual setup. ```text https://doglog.dev/vendordep.json ``` -------------------------------- ### Configure DogLog Behavior in Java Source: https://context7.com/jonahsnider/doglog/llms.txt Shows how to configure DogLog's behavior for different environments using `DogLog.setOptions()` and `DogLogOptions` in Java. This includes settings for NetworkTables publishing and tunables, logging diagnostics, capturing data (NetworkTables, driver station, console), and using a dedicated log thread. The examples cover default, development, competition, and conditional configurations, as well as setting the PowerDistribution object and enabling/disabling logging at runtime. ```java import dev.doglog.DogLog; import dev.doglog.DogLogOptions; import edu.wpi.first.wpilibj.PowerDistribution; public class Robot extends TimedRobot { @Override public void robotInit() { // Default options (safe for competition) // - NT publish: disabled when FMS attached // - NT tunables: disabled when FMS attached // - Log extras: enabled // - Capture console: enabled // - Log thread: enabled DogLog.setOptions(new DogLogOptions()); // Development configuration (always publish to NT, enable tunables) DogLog.setOptions( new DogLogOptions() .withNtPublish(true) // Always publish to NetworkTables .withNtTunables(true) // Always use tunable values from NT .withLogExtras(true) // Log PDH currents, CAN usage, etc. .withCaptureNt(true) // Save all NT fields to log .withCaptureDs(true) // Save driver station data .withCaptureConsole(true) // Save console output to log ); // Competition configuration (minimal NT usage) DogLog.setOptions( new DogLogOptions() .withNtPublish(false) // Never publish to NT .withNtTunables(false) // Never use NT tunables .withLogExtras(true) // Still log diagnostics .withCaptureConsole(false) // Reduce log file size ); // Conditional configuration with supplier functions DogLog.setOptions( new DogLogOptions() .withNtPublish(() -> !DriverStation.isFMSAttached()) .withNtTunables(() -> RobotBase.isSimulation() || !DriverStation.isFMSAttached()) ); // Configure log thread settings DogLog.setOptions( new DogLogOptions() .withUseLogThread(true) // Use separate thread (default) .withLogEntryQueueCapacity(2000) // Increase queue size ); // Set PowerDistribution for logging PDH/PDP data PowerDistribution pdh = new PowerDistribution(); DogLog.setPdh(pdh); // Enable/disable logging at runtime DogLog.setEnabled(true); // Check if logging is enabled if (DogLog.isEnabled()) { DogLog.log("Robot/Initialized", true); } // Get current options DogLogOptions currentOptions = DogLog.getOptions(); } } ``` -------------------------------- ### Create Tunable Parameters with DogLog in Java Source: https://context7.com/jonahsnider/doglog/llms.txt Demonstrates how to create tunable parameters of various types (double, boolean, integer, string) using `DogLog.tunable()` in Java. These parameters can be adjusted via NetworkTables during development. The code shows examples with default values, unit metadata, Unit objects, and callback functions that execute when a tunable value changes. Dependencies include `dev.doglog.DogLog` and relevant NetworkTables subscribers. ```java import dev.doglog.DogLog; import edu.wpi.first.networktables.DoubleSubscriber; import edu.wpi.first.networktables.BooleanSubscriber; import edu.wpi.first.units.Units; public class ShooterSubsystem extends SubsystemBase { // Create tunable double with default value private DoubleSubscriber kP = DogLog.tunable("Shooter/kP", 0.1); private DoubleSubscriber kD = DogLog.tunable("Shooter/kD", 0.05); // Tunable with unit metadata private DoubleSubscriber targetVelocity = DogLog.tunable("Shooter/TargetVelocity", 5000.0, "RPM"); // Tunable with Unit object private DoubleSubscriber maxVoltage = DogLog.tunable("Shooter/MaxVoltage", 11.5, Units.Volts); // Tunable boolean private BooleanSubscriber useVisionAiming = DogLog.tunable("Shooter/UseVisionAiming", false); // Tunable integer private IntegerSubscriber targetRPM = DogLog.tunable("Shooter/TargetRPM", 5000L); // Tunable string private StringSubscriber driveMode = DogLog.tunable("Drive/Mode", "field-relative"); @Override public void periodic() { // Get current values (returns default if NT not available or disabled) double currentKP = kP.get(); double currentVelocity = targetVelocity.get(); boolean visionEnabled = useVisionAiming.get(); // Use in control logic pidController.setP(currentKP); pidController.setD(kD.get()); } } public class DriveWithCallback extends SubsystemBase { // Tunable with callback function that runs when value changes private DoubleSubscriber maxSpeed = DogLog.tunable( "Drive/MaxSpeed", 4.5, Units.MetersPerSecond, (newValue) -> { System.out.println("Max speed changed to: " + newValue); reconfigureDrive(); } ); private BooleanSubscriber fieldRelative = DogLog.tunable( "Drive/FieldRelative", true, (enabled) -> { System.out.println("Field-relative mode: " + enabled); } ); } ``` -------------------------------- ### Measure Execution Time with DogLog in Java Source: https://context7.com/jonahsnider/doglog/llms.txt This Java snippet demonstrates how to use DogLog for performance profiling by measuring execution times of different operations. It shows how to start and end timing for specific operations and how to wrap entire commands to automatically time their lifecycle methods. ```java import dev.doglog.DogLog; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; public class AutonomousCommand extends Command { private VisionSubsystem vision; @Override public void initialize() { // Start timing an operation DogLog.time("Auto/VisionProcessing"); vision.processTargets(); // End timing and log duration in seconds DogLog.timeEnd("Auto/VisionProcessing"); // Logs to "Auto/VisionProcessing" with value like 0.0234 (seconds) } @Override public void execute() { DogLog.time("Auto/PathFollowing"); followPath(); DogLog.timeEnd("Auto/PathFollowing"); } } public class RobotContainer { private DriveSubsystem drive; public Command getAutonomousCommand() { Command pathCommand = drive.followTrajectoryCommand(); // Wrap command to automatically time all lifecycle methods Command timedCommand = DogLog.time("Auto/DriveCommand", pathCommand); // Logs execution time of initialize(), execute(), and end() methods // to keys like "Auto/DriveCommand/.initialize()", etc. return timedCommand; } public void timestampExample() { // Log current FPGA timestamp (useful for event tracking) if (gamepad.getAButton()) { DogLog.timestamp("Operator/AButtonPressed"); } } } ``` -------------------------------- ### Log Values with Units using DogLog Source: https://context7.com/jonahsnider/doglog/llms.txt Logs data with associated unit metadata, enhancing visualization and analysis in log viewers. Supports logging with unit strings, WPILib Unit objects, and Measure objects. Also demonstrates logging arrays with units. Requires `dev.doglog.DogLog` and WPILib units library. ```java import dev.doglog.DogLog; import edu.wpi.first.units.Units; import edu.wpi.first.units.Measure; import edu.wpi.first.units.Distance; public class DriveSubsystem extends SubsystemBase { private Encoder leftEncoder = new Encoder(0, 1); private Encoder rightEncoder = new Encoder(2, 3); @Override public void periodic() { // Log with unit string DogLog.log("Drive/LeftPosition", leftEncoder.getDistance(), "Meters"); DogLog.log("Drive/RightVelocity", rightEncoder.getRate(), "MetersPerSecond"); // Log with Unit object DogLog.log("Drive/LeftVoltage", 12.0, Units.Volts); DogLog.log("Drive/Temperature", 45.3, Units.Celsius); // Log Measure objects (preserves user-specified unit) Measure distance = Units.Meters.of(leftEncoder.getDistance()); DogLog.log("Drive/MeasuredDistance", distance); // Log arrays with units double[] motorCurrents = {2.5, 3.1, 2.8, 3.3}; DogLog.log("Drive/MotorCurrents", motorCurrents, Units.Amps); } } ``` -------------------------------- ### DogLog Dependency Information (Gradle) Source: https://context7.com/jonahsnider/doglog/llms.txt This snippet provides dependency information for integrating DogLog into an FRC project using Gradle. It outlines the group, artifact, version, and Maven repository required for the vendordep system. This information is typically managed automatically by the WPILib vendordep system after adding the URL. ```gradle // vendordep.json is automatically added to build.gradle // Dependency info: // - Group: com.github.jonahsnider // - Artifact: doglog // - Version: 2026.1.0 // - Maven: https://jitpack.io ``` -------------------------------- ### Log Robot Faults with DogLog in Java Source: https://context7.com/jonahsnider/doglog/llms.txt This snippet demonstrates how to log different types of faults using the DogLog library in Java. It shows how to log faults with default error alerts, specific alert types, without alerts, and using enums for fault names. It also includes methods for clearing and checking the status of logged faults. ```java import dev.doglog.DogLog; import edu.wpi.first.wpilibj.Alert.AlertType; public class ShooterSubsystem extends SubsystemBase { private CANSparkMax shooterMotor = new CANSparkMax(5, MotorType.kBrushless); private final double MAX_CURRENT = 40.0; enum ShooterFault { MOTOR_OVERCURRENT, ENCODER_DISCONNECTED, VELOCITY_TRACKING_ERROR } @Override public void periodic() { // Log fault with error alert (default) if (shooterMotor.getOutputCurrent() > MAX_CURRENT) { DogLog.logFault("Shooter/OverCurrent"); } // Log fault with specific alert type if (!shooterMotor.getEncoder().getPosition() != 0.0) { DogLog.logFault("Shooter/EncoderDisconnected", AlertType.kError); } // Log fault without creating an alert if (Math.abs(shooterMotor.getEncoder().getVelocity() - targetVelocity) > 100) { DogLog.logFault("Shooter/VelocityError", null); } // Use enum for fault names if (checkForError()) { DogLog.logFault(ShooterFault.VELOCITY_TRACKING_ERROR); } } public void clearErrors() { // Decrease fault count by 1 DogLog.decreaseFault("Shooter/OverCurrent"); // Clear fault completely (set count to 0) DogLog.clearFault("Shooter/EncoderDisconnected"); // Clear enum fault DogLog.clearFault(ShooterFault.VELOCITY_TRACKING_ERROR); } public boolean hasErrors() { // Check if any faults have ever been logged boolean anyFaultsLogged = DogLog.faultsLogged(); // Check if any faults are currently active (count > 0) boolean activeFaults = DogLog.faultsActive(); return activeFaults; } } ``` -------------------------------- ### Track Command Execution Time with DogLog Helper Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/reference/convenience-features.md A helper function that automatically wraps a command with DogLog.time() and DogLog.timeEnd() to measure its execution duration. Simplifies the process of timing command execution. Requires DogLog library. ```javascript var timedCommand = DogLog.time("MyClass/MyCommand", myClass.myCommand()); ``` -------------------------------- ### Import DogLog Library in Java Source: https://github.com/jonahsnider/doglog/blob/main/README.md This Java code snippet demonstrates how to import the DogLog library into your FRC project. It makes the `DogLog` class available for use in your code, typically at the beginning of your Java files. ```java import dev.doglog.DogLog; ``` -------------------------------- ### Log Primitive Types with DogLog Source: https://context7.com/jonahsnider/doglog/llms.txt Logs various primitive data types (double, boolean, integer, string, enum) to DataLog and optionally to NetworkTables. This is useful for real-time monitoring of robot states and sensor values. Requires `dev.doglog.DogLog` and WPILib dependencies. ```java import dev.doglog.DogLog; import edu.wpi.first.units.Units; public class Robot extends TimedRobot { private CANSparkMax motor = new CANSparkMax(1, MotorType.kBrushless); @Override public void robotPeriodic() { // Log double values DogLog.log("Arm/Position", motor.getEncoder().getPosition()); DogLog.log("Arm/Velocity", motor.getEncoder().getVelocity()); // Log boolean values DogLog.log("Arm/AtSetpoint", Math.abs(motor.getEncoder().getPosition() - 45.0) < 0.5); // Log integer values DogLog.log("Arm/MotorID", motor.getDeviceId()); // Log string values DogLog.log("Robot/State", "Climbing"); // Log enum values DogLog.log("Arm/ControlMode", motor.getIdleMode()); } } ``` -------------------------------- ### Log Arrays and Complex Types with DogLog Source: https://context7.com/jonahsnider/doglog/llms.txt Logs collections of data, including primitive arrays, WPILib structs (like Pose2d), arrays of structs, and Java records. This enables batch logging of complex state information. Requires `dev.doglog.DogLog` and relevant WPILib geometry/structs libraries. ```java import dev.doglog.DogLog; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Translation2d; public class VisionSubsystem extends SubsystemBase { private PhotonCamera camera = new PhotonCamera("main_camera"); @Override public void periodic() { // Log primitive arrays double[] motorVoltages = {12.0, 11.8, 12.1, 11.9}; DogLog.log("Motors/Voltages", motorVoltages); boolean[] limitSwitches = {true, false, false, true}; DogLog.log("LimitSwitches/States", limitSwitches); String[] cameras = {"front", "back", "intake"}; DogLog.log("Vision/Cameras", cameras); // Log struct (WPILib Pose2d implements StructSerializable) Pose2d robotPose = new Pose2d(5.2, 3.1, new Rotation2d(Math.PI / 4)); DogLog.log("Robot/Pose", robotPose); // Log struct arrays Pose2d[] trajectoryPoses = { new Pose2d(0, 0, new Rotation2d(0)), new Pose2d(1, 1, new Rotation2d(Math.PI / 2)), new Pose2d(2, 2, new Rotation2d(Math.PI)) }; DogLog.log("Auto/Trajectory", trajectoryPoses); // Log record (Java records are supported) record SensorData(double distance, double temperature, boolean active) {} SensorData data = new SensorData(15.3, 42.1, true); DogLog.log("Sensors/Data", data); } } ``` -------------------------------- ### Define and Log Faults Using Enums in Java Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Demonstrates how to define robot faults using an enum and log them by referencing the enum constants. This provides a more structured and type-safe way to manage faults. ```java public enum RobotFault { CAMERA_OFFLINE, AUTO_SHOT_TIMEOUT_TRIGGERED, BROWNOUT, } ``` ```java DogLog.logFault(RobotFault.CAMERA_OFFLINE); ``` -------------------------------- ### Log Data using DogLog in Java Source: https://github.com/jonahsnider/doglog/blob/main/README.md This Java code snippet shows how to log data using the DogLog library. It takes a string identifier (e.g., 'Arm/Position') and a value (e.g., a motor's position) to record in the FRC log. These statements can be placed in periodic methods or other relevant parts of the robot code. ```java DogLog.log("Arm/Position", motor.getPosition().getValue()); ``` -------------------------------- ### Log Timestamps with DogLog Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/reference/convenience-features.md Logs the current timestamp to a specified key, useful for graphing function call frequency and understanding when specific operations occur. No external dependencies are required beyond the DogLog library. ```java DogLog.timestamp("MyClass/MyFunction"); ``` -------------------------------- ### Log a Basic Fault in Java Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Logs a simple fault message using the DogLog library. This is the most basic way to record an issue. ```java DogLog.logFault("Camera offline"); ``` -------------------------------- ### Using Enums for Faults Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Represent faults using enum types for better code organization and type safety. ```APIDOC ## Using Enums for Faults ### Description Represent faults using an enum for improved code readability and maintainability. ### Method `DogLog.logFault(Enum fault)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **fault** (Enum) - Required - An enum constant representing the fault. ### Request Example ```java public enum RobotFault { CAMERA_OFFLINE, AUTO_SHOT_TIMEOUT_TRIGGERED, BROWNOUT } // Log a fault using an enum DogLog.logFault(RobotFault.CAMERA_OFFLINE); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### Track Execution Time with DogLog Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/reference/convenience-features.md Measures and logs the duration of code execution between DogLog.time() and DogLog.timeEnd() calls. This is useful for identifying performance bottlenecks in subsystems, commands, or functions. Requires DogLog library. ```javascript // Start the timer DogLog.time("MyClass/MyFunction"); myClass.myFunction(); // Stop the timer and log the recorded duration DogLog.timeEnd("MyClass/MyFunction"); ``` -------------------------------- ### Log a Fault with Custom Alert Urgency in Java Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Logs a fault and specifies a custom alert urgency (e.g., Warning) using an AlertType enum. This allows for finer control over how the fault is reported via WPILib persistent alerts. ```java DogLog.logFault("Arm not homed", AlertType.kWarning); ``` -------------------------------- ### Viewing Faults Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Access and interpret logged fault data. Fault counts, seen faults, and active faults are available under the Robot/Faults key. ```APIDOC ## Viewing Faults ### Description Faults are logged under the `Robot/Faults` key and can be accessed programmatically. This allows for monitoring fault occurrences and status. ### Method `DogLog.faultsLogged()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Check if any faults have been logged boolean anyFaults = DogLog.faultsLogged(); ``` ### Response #### Success Response (boolean) - **anyFaults** (boolean) - Returns true if any faults have been logged, false otherwise. #### Response Example ```json { "anyFaults": true } ``` ### Logged Data Structure - `Robot/Faults/Counts/`: The number of times a specific fault has occurred. - `Robot/Faults/Seen`: An array of all unique faults that have been logged. - `Robot/Faults/Active`: An array of currently active faults. ``` -------------------------------- ### Log a Fault Without Alerts in Java Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Logs a fault but disables the reporting of a WPILib persistent alert by passing null for the alert urgency. Useful for non-critical or temporary issues. ```java DogLog.logFault("Command timeout", null); ``` -------------------------------- ### Marking Faults as Resolved Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Manage the active state and count of logged faults. Decrease the fault count or clear it entirely. ```APIDOC ## Marking a Fault as Resolved ### Description Manage the occurrence count of a specific fault. You can decrease the count by one or reset it to zero. ### Method `DogLog.decreaseFault(String message)` `DogLog.clearFault(String message)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **message** (String) - Required - The description of the fault to modify. ### Request Example ```java // Decrease the count for 'Camera offline' fault by 1 DogLog.decreaseFault("Camera offline"); // Reset the count for 'Camera offline' fault to 0 DogLog.clearFault("Camera offline"); ``` ### Response #### Success Response (void) These methods do not return a value. #### Response Example N/A ``` -------------------------------- ### Logging Faults Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Record faults encountered by the robot. Faults can be logged with a simple string message, a custom alert type, or by disabling alert reporting. ```APIDOC ## Logging Faults ### Description Record a fault by calling `DogLog.logFault()`. You can provide a simple string message, customize the alert urgency, or disable alerts. ### Method `DogLog.logFault(String message, AlertType alertType)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **message** (String) - Required - A description of the fault. - **alertType** (AlertType) - Optional - The urgency of the alert (e.g., kWarning, kError). If null, alerts are disabled. ### Request Example ```java // Log a fault with default alert urgency DogLog.logFault("Camera offline"); // Log a fault with warning urgency DogLog.logFault("Arm not homed", AlertType.kWarning); // Log a fault without alerts DogLog.logFault("Command timeout", null); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### Clear a Fault Completely in Java Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Resets the occurrence count for a specific fault to zero. Once the count reaches zero, any associated alerts will be marked as inactive. ```java DogLog.clearFault("Camera offline"); ``` -------------------------------- ### Decrease Fault Count in Java Source: https://github.com/jonahsnider/doglog/blob/main/web/src/content/docs/guides/faults.md Decreases the occurrence count for a specific fault by one. This is used when a temporary fault condition is resolved. ```java DogLog.decreaseFault("Camera offline"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.