Skip to content
Merged
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: 2 additions & 2 deletions src/components/panels/ArmControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ const ArmControlPanel: React.FC = () => {
/>
</label>

<button onClick={handleGo} disabled={!selectedPose}>
<button onClick={handleGo} disabled={!selectedPose || armState !== 'Idle'}>
Go
</button>

Expand Down Expand Up @@ -539,4 +539,4 @@ const ArmControlPanel: React.FC = () => {
);
};

export default ArmControlPanel;
export default ArmControlPanel;
42 changes: 39 additions & 3 deletions src/components/panels/MotorStatusPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type MotorStatus = {
velocity: number;
output_current: number;
active_errors: number;
remaining: number;
};

const MOTORS = {
Expand Down Expand Up @@ -121,6 +122,12 @@ const MotorStatusPanel: React.FC = () => {
);
};

const handleResetAll = () => {
(Object.entries(MOTORS) as [MotorKey, typeof MOTORS[MotorKey]][]).forEach(
([key, { topic }]) => handleResetErrors(key, topic),
);
};
Comment thread
codeflight1 marked this conversation as resolved.

useEffect(() => {
if (!ros) return;

Expand All @@ -140,7 +147,8 @@ const MotorStatusPanel: React.FC = () => {
[key]: {
velocity: msg.velocity,
output_current: msg.output_current,
active_errors: msg.active_errors
active_errors: msg.active_errors,
remaining: 2
},
}));
};
Expand All @@ -152,8 +160,30 @@ const MotorStatusPanel: React.FC = () => {
return () => unsubscribers.forEach(unsub => unsub());
}, [ros]);

useEffect(() => {
const interval = window.setInterval(() => {
setMotorStats(prev => {
const next = { ...prev };
(Object.keys(prev) as MotorKey[]).forEach(key => {
const stat = prev[key];
if (!stat) return;
next[key] = { ...stat, remaining: stat.remaining - 0.1 };
});
return next;
});
}, 100);

return () => window.clearInterval(interval);
}, []);
return (
<div className="motor-panel">
<button
className="reset-button"
disabled={!ros}
onClick={handleResetAll}
>
Reset All
</button>
<table className="motor-table">
<thead>
<tr>
Expand All @@ -169,18 +199,24 @@ const MotorStatusPanel: React.FC = () => {
([key, { label, topic }]) => {
const stat = motorStats[key];
var errorStr = '-';
var color = "#6c757d";
if (stat) {
var errNames: string[] = [];
Object.keys(MotorError).forEach((key: string) => { if (stat.active_errors & MotorError[key]) errNames.push(key) })
errorStr = errNames.length ? errNames.join(', ') : "NONE";
color = errNames.length ? "#ef4444" : "#22c55e";
if (stat.remaining < 0) {
errorStr = "STALE";
color = "#ffc107";
}
}

return (
<tr key={key}>
<td>{label}</td>
<td>{stat && Number.isFinite(stat.velocity) ? stat.velocity.toFixed(2) : '-'}</td>
<td>{stat && Number.isFinite(stat.output_current) ? `${stat.output_current.toFixed(2)}A` : '-'}</td>
<td><span className="status-led" style={{ backgroundColor: errorStr == "NONE" ? "#22c55e" : "#ef4444" }}/><span style={{ paddingLeft: "8px" }}>{errorStr}</span></td>
<td><span className="status-led" style={{ backgroundColor: color }}/><span style={{ paddingLeft: "8px" }}>{errorStr}</span></td>
<td>
<button
className="reset-button"
Expand Down Expand Up @@ -262,4 +298,4 @@ const MotorStatusPanel: React.FC = () => {
);
};

export default MotorStatusPanel;
export default MotorStatusPanel;
28 changes: 21 additions & 7 deletions src/components/panels/NodeStatusPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const NodeStatusPanel: React.FC = () => {
const { ros } = useROS();

const [nodes, setNodes] = useState<Map<string, NodeInfo>>(new Map());
const [staleTime, setStaleTime] = useState<number>(0);

useEffect(() => {
if (!ros) return;
Expand Down Expand Up @@ -49,6 +50,7 @@ const NodeStatusPanel: React.FC = () => {

return updated;
});
setStaleTime(2);
} catch (e) {
console.error('Failed to parse node list:', e);
}
Expand All @@ -61,10 +63,20 @@ const NodeStatusPanel: React.FC = () => {
};
}, [ros]);

useEffect(() => {
const interval = window.setInterval(() => {
setStaleTime(prev => Math.max(-1, prev - 0.1));
}, 100);

return () => window.clearInterval(interval);
}, []);

const sortedNodes = Array.from(nodes.entries()).sort(([a], [b]) =>
a.localeCompare(b)
);

const stale = staleTime < 0;

return (
<div className="node-panel">
<table className="node-table">
Expand All @@ -89,15 +101,17 @@ const NodeStatusPanel: React.FC = () => {
<span
className="status-led"
style={{
backgroundColor: info.online
? '#22c55e'
: offline
? '#ef4444'
: '#6b7280',
backgroundColor: stale
? '#ffc107'
: info.online
? '#22c55e'
: offline
? '#ef4444'
: '#6b7280',
}}
/>
<span style={{ paddingLeft: 8 }}>
{info.online ? 'Online' : offline ? 'Offline' : 'Unknown'}
{stale ? 'Stale' : info.online ? 'Online' : offline ? 'Offline' : 'Unknown'}
</span>
</td>

Expand Down Expand Up @@ -154,4 +168,4 @@ const NodeStatusPanel: React.FC = () => {
);
};

export default NodeStatusPanel;
export default NodeStatusPanel;
Loading