From 03ea2b180faa0521e7ab48b9e87881058940d11c Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 Sep 2024 20:25:22 -0700 Subject: [PATCH] longitudinal maneuver report improvements (#33551) * switch to route name * add car params and relative time * separate plots, easier to read --- .../longitudinal_maneuvers/generate_report.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/longitudinal_maneuvers/generate_report.py b/tools/longitudinal_maneuvers/generate_report.py index 262ea93ef3f911..b3ab8d9a7a6570 100755 --- a/tools/longitudinal_maneuvers/generate_report.py +++ b/tools/longitudinal_maneuvers/generate_report.py @@ -3,7 +3,7 @@ import base64 import io import os -import time +import json from pathlib import Path import matplotlib.pyplot as plt @@ -11,15 +11,21 @@ from openpilot.system.hardware.hw import Paths -def report(platform, maneuvers): +def format_car_params(CP): + return json.dumps({k: v for k, v in CP.to_dict().items() if not k.endswith('DEPRECATED')}, indent=2) + + +def report(platform, route, CP, maneuvers): output_path = Path(__file__).resolve().parent / "longitudinal_reports" - output_fn = output_path / f"{platform}_{time.strftime('%Y%m%d-%H_%M_%S')}.html" + output_fn = output_path / f"{platform}_{route}.html" output_path.mkdir(exist_ok=True) with open(output_fn, "w") as f: f.write("

Longitudinal maneuver report

\n") f.write(f"

{platform}

\n") + f.write(f"

{route}

\n") + f.write(f"

CarParams

{format_car_params(CP)}
\n") for description, runs in maneuvers: - print('plotting maneuver:', description, 'runs:', len(runs)) + print(f'plotting maneuver: {description}, runs: {len(runs)}') f.write("
\n") f.write(f"

{description}

\n") for run, msgs in enumerate(runs): @@ -28,6 +34,11 @@ def report(platform, maneuvers): t_carState, carState = zip(*[(m.logMonoTime, m.carState) for m in msgs if m.which() == 'carState'], strict=True) t_longitudinalPlan, longitudinalPlan = zip(*[(m.logMonoTime, m.longitudinalPlan) for m in msgs if m.which() == 'longitudinalPlan'], strict=True) + t_carControl = [(t - t_carControl[0]) / 1e9 for t in t_carControl] + t_carOutput = [(t - t_carOutput[0]) / 1e9 for t in t_carOutput] + t_carState = [(t - t_carState[0]) / 1e9 for t in t_carState] + t_longitudinalPlan = [(t - t_longitudinalPlan[0]) / 1e9 for t in t_longitudinalPlan] + longActive = [m.longActive for m in carControl] gasPressed = [m.gasPressed for m in carState] brakePressed = [m.brakePressed for m in carState] @@ -41,7 +52,7 @@ def report(platform, maneuvers): plt.rcParams['font.size'] = 40 fig = plt.figure(figsize=(30, 25)) - ax = fig.subplots(4, 1, sharex=True, gridspec_kw={'hspace': 0, 'height_ratios': [5, 3, 1, 1]}) + ax = fig.subplots(4, 1, sharex=True, gridspec_kw={'height_ratios': [5, 3, 1, 1]}) ax[0].grid(linewidth=4) ax[0].plot(t_carControl, [m.actuators.accel for m in carControl], label='carControl.actuators.accel', linewidth=6) @@ -112,4 +123,4 @@ def report(platform, maneuvers): if active_prev: maneuvers[-1][1][-1].append(msg) - report(platform, maneuvers) + report(platform, args.route, CP, maneuvers)