Efficient binary data logging system for robot telemetry.
import edu.wpi.first.util.datalog.*;// Create data logDataLog log = new DataLog("/home/lvuser/logs");// Create log entriesDoubleLogEntry velocityLog = new DoubleLogEntry(log, "/drive/velocity");BooleanLogEntry enabledLog = new BooleanLogEntry(log, "/robot/enabled");StringLogEntry eventLog = new StringLogEntry(log, "/robot/events");// Append datavelocityLog.append(2.5);enabledLog.append(true);eventLog.append("Match started");// With timestampvelocityLog.append(2.5, timestamp);// Close loglog.close();
import edu.wpi.first.util.datalog.*;// Open log file for readingDataLogReader reader = new DataLogReader("logfile.wpilog");// Iterate through recordsfor (DataLogRecord record : reader) { if (record.isStart()) { System.out.println("Entry: " + record.getStartData().name); } else if (record.isFinish()) { System.out.println("Finished: " + record.getEntry()); } else if (record.isSetMetadata()) { // Handle metadata } else if (record.isControl()) { // Handle control record }}
import edu.wpi.first.util.datalog.*;// Create background writer for async loggingDataLogBackgroundWriter log = new DataLogBackgroundWriter("/home/lvuser/logs");// Use like regular DataLogDoubleLogEntry entry = new DoubleLogEntry(log, "/data");entry.append(1.23);// Automatically flushes in background thread
import edu.wpi.first.util.protobuf.Protobuf;import edu.wpi.first.util.protobuf.ProtobufSerializable;// Use Protocol Buffers for serializationpublic class MyData implements ProtobufSerializable { public static final MyDataProto proto = new MyDataProto(); // Implementation using generated protobuf classes}
#include <wpi/mutex.h>#include <wpi/condition_variable.h>wpi::mutex mtx;wpi::condition_variable cv;// Use like std::mutex and std::condition_variable{ std::scoped_lock lock(mtx); // Critical section}
#include <wpi/SmallVector.h>// Vector with small buffer optimizationwpi::SmallVector<int, 8> vec; // No heap allocation until > 8 elementsvec.push_back(1);vec.push_back(2);
#include <wpi/fmt/format.h>#include <wpi/fmt/chrono.h>// Format stringsstd::string s = fmt::format("Value: {:.2f}", 3.14159);// Print to consolefmt::print("Robot enabled: {}\n", enabled);// Format to bufferfmt::memory_buffer buf;fmt::format_to(std::back_inserter(buf), "{} {}", "Hello", "World");