Skip to content

903. API docs for RFID Battery Tracking and Addressable LED

Nathan zhou edited this page Jan 22, 2026 · 4 revisions

You can directly deploy the example project to fully test the development board. This section explains how to integrate the roboRIO-side drivers.

1. Copy demo classes

Copy batteryCAN.java and addressableLEDCAN.java from the example project into your subsystems directory.


2. Import the required classes

import frc.robot.subsystems.addressableLEDCAN;
import frc.robot.subsystems.batteryCAN;

3. Initialize the devices during robot initialization

Both classes use the same device number.

battery = new batteryCAN(device_number); // your ESP32 device number
leds = new addressableLEDCAN(device_number); // must match the LED ESP32 device number

4. Retrieve battery data

// --------------------
// Serial number
// --------------------
String serial = battery.getSerial();

// --------------------
// Lifecycle data
// --------------------
int cycleCount = battery.getCycleCount();
String firstUseDateTime = battery.getFirstUseDateTime();

// --------------------
// Status / note flag
// --------------------
int note = battery.getNote();

String noteLabel = switch (note) {
    case 0 -> "Normal";
    case 1 -> "Practice Only";
    case 2 -> "Scrap";
    case 3 -> "Other";
    default -> "Unknown";
};

5. Control LED strip modes

leds.setTotalPixel(totalPixels);
leds.sendGeneralCommand(mode, r, g, b, brightness, onOff, param0, param1);

6. Retrieve hardware status

All hardware-related APIs are provided in the batteryCAN class.

battery.getIsESPOnline();      // ESP32 online status
battery.isReaderDetected();   // RFID reader connection status
battery.getPDType();          // PDP / PDH detection status (used for energy monitoring debug)
battery.getESPState();        // ESP32 firmware runtime state (for firmware debugging)
battery.getWriteCount();      // Successful tag write counter
battery.getWriteFailCount();  // Failed tag write counter
battery.requestReboot();      // Reboot the ESP32 via CAN
battery.setOverrideState(overrideState); // Debug-only API to override firmware state (DEBUG USE ONLY!)

8. Energy usage monitoring

If a CAN-capable PDP or PDH is connected, the development board will automatically calculate energy usage. If a non-CAN power distribution board is used, you may calculate energy manually and send it to the board via API.

battery.setEnergyKJ(energyKJ);                 // Set energy value
battery.setUseRIOEnergy(isUsingRIOEnergy);     // If true, use user-provided energy
                                                // If true and energyKJ is not provided while this is flipped to true, 0 will be written
battery.setEnergyKJAndSend(energyKJ);          // Set energy and force isUsingRIOEnergy = true

9. Custom LED effects (non-built-in modes)

If you need custom LED effects, set the mode to 255 using leds.sendGeneralCommand. You can then write pixels directly using the API below.

  • slot range: 0–7
  • Up to 8 slots can be written simultaneously for higher throughput
  • ⚠️ Warning: This API consumes a large amount of CAN bandwidth and is strongly discouraged for normal use
leds.sendPixelWrite(index, pr, pg, pb, 0, pbrig, slot);

Clone this wiki locally