import { useMemo } from 'react'; import { useControlSystem } from '../controls/index.js'; import { OVERCURRENT_GROUPS } from '../controls/overcurrentLimiter.js'; const GROUP_LABELS = { drive: 'Drive wheels', aux: 'Aux motors', }; function formatPct(value) { if (!Number.isFinite(value)) return '--'; return `${Math.round(value * 100)}%`; } function ProgressBar({ value, color = 'bg-emerald-500' }) { const width = `${Math.round(Math.max(0, Math.min(1, value)) * 100)}%`; return (
); } export default function OvercurrentLimiterPanel() { const { state: { roverId }, overcurrentLimiter, } = useControlSystem(); const groups = useMemo(() => OVERCURRENT_GROUPS.map((group) => group.key), []); return (
Overcurrent limiter {overcurrentLimiter?.adminImmune ? 'Admin immune' : 'Active'}
{!roverId ? (

Assign a rover to view limiter status.

) : (
{groups.map((key) => { const cap = overcurrentLimiter?.caps?.[key]?.cap ?? 0; const over = overcurrentLimiter?.overcurrent?.groups?.[key] ?? false; const scale = overcurrentLimiter?.scales?.perGroup?.[key] ?? 1; return (
{GROUP_LABELS[key] || key} {over ? 'overcurrent' : 'ok'}
Cap {formatPct(cap)}
Scale {formatPct(scale)}
); })}
{`Down rate ${overcurrentLimiter?.config?.downRatePerSec}/s ยท Up rate ${overcurrentLimiter?.config?.upRatePerSec}/s`}
{`Release delay ${overcurrentLimiter?.config?.releaseDelaySec}s`}
{`Output rate ${overcurrentLimiter?.config?.outputRateMs}ms`}
)}
); }