mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] DriverStation: Add usage reporting for opmodes (#8761)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "wpi/hal/DriverStationTypes.h"
|
||||
#include "wpi/hal/HAL.h"
|
||||
#include "wpi/hal/Power.h"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/nt/BooleanTopic.hpp"
|
||||
#include "wpi/nt/IntegerTopic.hpp"
|
||||
#include "wpi/nt/NetworkTable.hpp"
|
||||
@@ -677,6 +678,20 @@ void DriverStationBackend::PublishOpModes() {
|
||||
options.emplace_back(option);
|
||||
}
|
||||
HAL_SetOpModeOptions(options.data(), options.size());
|
||||
|
||||
int modeCounts[HAL_ROBOT_MODE_UTILITY + 1] = {0, 0, 0, 0};
|
||||
for (const auto& opMode : options) {
|
||||
++modeCounts[HAL_OpMode_GetRobotMode(opMode.id)];
|
||||
}
|
||||
|
||||
HAL_ReportUsage("OpMode/AUTONOMOUS",
|
||||
std::to_string(modeCounts[HAL_ROBOT_MODE_AUTONOMOUS]));
|
||||
HAL_ReportUsage("OpMode/TELEOPERATED",
|
||||
std::to_string(modeCounts[HAL_ROBOT_MODE_TELEOPERATED]));
|
||||
HAL_ReportUsage("OpMode/UTILITY",
|
||||
std::to_string(modeCounts[HAL_ROBOT_MODE_UTILITY]));
|
||||
HAL_ReportUsage("OpMode/UNKNOWN",
|
||||
std::to_string(modeCounts[HAL_ROBOT_MODE_UNKNOWN]));
|
||||
}
|
||||
|
||||
void DriverStationBackend::ClearOpModes() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Optional;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
import org.wpilib.datalog.BooleanArrayLogEntry;
|
||||
import org.wpilib.datalog.DataLog;
|
||||
import org.wpilib.datalog.FloatArrayLogEntry;
|
||||
@@ -1343,6 +1344,14 @@ public final class DriverStationBackend {
|
||||
} finally {
|
||||
m_opModesMutex.unlock();
|
||||
}
|
||||
|
||||
var modeCounts =
|
||||
m_opModes.values().stream()
|
||||
.collect(Collectors.groupingBy(OpModeOption::getMode, Collectors.counting()));
|
||||
|
||||
for (RobotMode mode : RobotMode.values()) {
|
||||
HAL.reportUsage("OpMode/" + mode, String.valueOf(modeCounts.getOrDefault(mode, 0L)));
|
||||
}
|
||||
}
|
||||
|
||||
/** Clears all operating mode options and publishes an empty list to the driver station. */
|
||||
|
||||
Reference in New Issue
Block a user