mcpField
A
analyze-wpilog

analyze-wpilog

github.com/jonahsniderデータ・データベース2358 回インストール1 日前に更新
リポジトリ

analyze-wpilog について

analyze-wpilogは、TypeScriptまたはJavaScriptでWPILOGバイナリファイルを読み取る、FRCログ分析用スキルです。エントリー一覧、レコード解析、構造体のデコードに対応し、孤立レコードを扱う厳密モードも備えています。

主な機能

  1. 01WPILOGエントリーの一覧化
  2. 02DataLogレコードの解析
  3. 03名前と型によるレコードの絞り込み
  4. 04構造体データのデコード
  5. 05厳密モードでの孤立レコード検出

活用シーン

  1. 01ロボットログに含まれるエントリーの確認
  2. 02ロボット状態とモード時間の分析
  3. 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 でログファイルを簡単に読み取り、分析できます。

プロジェクトの作成

  1. pnpm init などを使用してプロジェクトを初期化します

  2. wpilog-parser を依存関係として追加します

  3. 分析対象を決める前に、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);

コメント