Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.Constants.PowerConstants;
import frc.robot.util.VirtualSubsystem;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedPowerDistribution;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
Expand Down Expand Up @@ -100,7 +102,7 @@ public Robot() {
// Initialize URCL
Logger.registerURCL(URCL.startExternal());
StatusLogger.disableAutoLogging(); // Disable REVLib's built-in logging
// LoggedPowerDistribution.getInstance(PowerConstants.kPDMCANid, PowerConstants.kPDMType);
LoggedPowerDistribution.getInstance(PowerConstants.kPDMCANid, PowerConstants.kPDMType);

// Start AdvantageKit logger
Logger.start();
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/frc/robot/util/RBSIPowerMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

package frc.robot.util;

import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.RobotController;
import frc.robot.Constants.PowerConstants;
import frc.robot.Constants.RobotDevices;
import frc.robot.util.Alert.AlertType;
import org.littletonrobotics.conduit.ConduitApi;
import org.littletonrobotics.junction.Logger;

/**
Expand All @@ -29,8 +29,9 @@
public class RBSIPowerMonitor extends VirtualSubsystem {

private final RBSISubsystem[] subsystems;
private final PowerDistribution m_pdm =
new PowerDistribution(PowerConstants.kPDMCANid, PowerDistribution.ModuleType.kRev);
// private final LoggedPowerDistribution m_pdm =
// LoggedPowerDistribution.getInstance(PowerConstants.kPDMCANid, PowerConstants.kPDMType);
ConduitApi conduit = ConduitApi.getInstance();

// Define local variables
private final LoggedTunableNumber batteryCapacityAh;
Expand Down Expand Up @@ -61,27 +62,27 @@ public RBSIPowerMonitor(LoggedTunableNumber batteryCapacityAh, RBSISubsystem...
@Override
public void periodic() {
// --- Read voltage & total current ---
double voltage = m_pdm.getVoltage();
double totalCurrent = m_pdm.getTotalCurrent();
double voltage = conduit.getPDPVoltage();
double totalCurrent = conduit.getPDPTotalCurrent();

// --- Safety alerts ---
if (totalCurrent > PowerConstants.kTotalMaxCurrent) {
new Alert("Total current draw exceeds limit!", AlertType.WARNING).set(true);
}

for (int ch = 0; ch < m_pdm.getNumChannels(); ch++) {
double current = m_pdm.getCurrent(ch);
for (int ch = 0; ch < conduit.getPDPChannelCount(); ch++) {
double current = conduit.getPDPChannelCurrent(ch);
if (current > PowerConstants.kMotorPortMaxCurrent) {
new Alert("Port " + ch + " current exceeds limit!", AlertType.WARNING).set(true);
}
}

// if (voltage < PowerConstants.kVoltageWarning) {
// new Alert("Low battery voltage!", AlertType.WARNING).set(true);
// }
// if (voltage < PowerConstants.kVoltageCritical) {
// new Alert("Critical battery voltage!", AlertType.ERROR).set(true);
// }
if (voltage < PowerConstants.kVoltageWarning) {
new Alert("Low battery voltage!", AlertType.WARNING).set(true);
}
if (voltage < PowerConstants.kVoltageCritical) {
new Alert("Critical battery voltage!", AlertType.ERROR).set(true);
}

// --- Battery estimation ---
long nowUs = RobotController.getFPGATime();
Expand Down Expand Up @@ -123,7 +124,7 @@ public void periodic() {
private void logGroupCurrent(String name, int[] ports) {
double sum = 0.0;
for (int port : ports) {
sum += m_pdm.getCurrent(port);
sum += conduit.getPDPChannelCurrent(port);
}
Logger.recordOutput("Power/Subsystems/" + name + "Current", sum);
}
Expand Down