关于 analyze-wpilog
analyze-wpilog 是面向 FRC 日志分析的技能,使用 TypeScript/JavaScript 读取 WPILOG 二进制日志。它提供条目目录、记录解析和结构体解码,并支持严格模式处理孤立记录。
主要功能
- 01生成 WPILOG 条目目录
- 02解析 DataLog 记录
- 03按名称和类型筛选记录
- 04解码结构体数据
- 05严格模式检测孤立记录
适用场景
- 01检查机器人日志中包含的条目
- 02分析机器人状态和运行模式时长
- 03读取定位等结构化日志数据
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ jonahsnider/ wpilog-parser --skill analyze-wpilog安装后在 Claude Code 中输入/analyze-wpilog确认已加载。
详细介绍
wpilog-parser
WPILOG 是 FRC 生态系统中日志库使用的二进制日志格式。wpilog-parser 库让你可以使用 TS/JS 轻松读取和分析日志文件。
创建项目
-
使用
pnpm init或类似命令初始化项目 -
将
wpilog-parser添加为依赖项 -
在决定要分析的内容之前,先列出 WPILOG 文件中的条目
pnpm wpilog catalog ./example.wpilog默认输出为纯文本。需要其他格式时,可使用
--json、--jsonl/--ndjson或--csv。
分析日志
使用 parseDataLog 解析 DataLog 字节。按 name 筛选,并通过 type 进一步缩小范围:
import { readFile } from 'node:fs/promises';
import { isDataRecord, parseDataLog, RecordType } from 'wpilog-parser';
const bytes = await readFile('./example.wpilog');
for (const record of parseDataLog(bytes)) {
if (!isDataRecord(record)) continue;
if (record.name === '/Robot/Intake/Voltage' && record.type === RecordType.Double) {
console.log(record.timestamp, record.payload);
}
}
解码结构体
import { parseDataLog, RecordType } from 'wpilog-parser';
for (const record of parseDataLog(bytes)) {
if (record.type === RecordType.Struct && record.name === '/Robot/Localization/EstimatedPose') {
console.log(record.timestamp, record.payload);
// 18688018n {
// translation: { x: 10.289, y: 0.47 },
// rotation: { value: 1.5707961072652017 },
// }
}
}
严格模式
for (const record of parseDataLog(bytes, { strict: true })) {
// throws on orphan data records instead of skipping
}
机器人状态速查表
启用 DriverStation 日志记录后,每个 WPILOG 都包含以下 boolean 条目:
| 条目 | 含义 |
|---|---|
/DS:enabled | 机器人启用时为 true(任何模式下均如此)。 |
/DS:autonomous | 自主模式期间为 true。false 表示遥控模式(除非 /DS:test 为真)。 |
/DS:test | 测试模式期间为 true。 |
/DS:estop | 急停时为 true。 |
模式标志(autonomous、test)反映的是 DS 在启用机器人时将运行的模式,因此请结合 /DS:enabled 一起检查。时间戳的单位为微秒(bigint)。
跟踪启用状态/模式的持续时间
import { isDataRecord, parseDataLog, RecordType } from 'wpilog-parser';
type Mode = 'auto' | 'teleop' | 'test';
function modeOf(auto: boolean, test: boolean): Mode {
if (test) return 'test';
if (auto) return 'auto';
return 'teleop';
}
let enabled = false;
let auto = false;
let test = false;
let enabledSince: bigint | null = null;
const totals = { auto: 0n, teleop: 0n, test: 0n };
for (const r of parseDataLog(bytes)) {
if (!isDataRecord(r) || r.type !== RecordType.Boolean) continue;
const wasEnabled = enabled;
const prevMode = modeOf(auto, test);
if (r.name === '/DS:enabled') enabled = r.payload;
else if (r.name === '/DS:autonomous') auto = r.payload;
else if (r.name === '/DS:test') test = r.payload;
else continue;
if (wasEnabled && (!enabled || modeOf(auto, test) !== prevMode)) {
totals[prevMode] += r.timestamp - (enabledSince ?? r.timestamp);
enabledSince = enabled ? r.timestamp : null;
} else if (!wasEnabled && enabled) {
enabledSince = r.timestamp;
}
}
// Durations in microseconds; divide by 1_000_000n for seconds.
console.log(totals);
评论
支持 Markdown