Skip to content

Commit

Permalink
longitudinal maneuver report improvements (commaai#33551)
Browse files Browse the repository at this point in the history
* switch to route name

* add car params and relative time

* separate plots, easier to read
  • Loading branch information
sshane authored Sep 13, 2024
1 parent 5fc79bd commit 03ea2b1
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tools/longitudinal_maneuvers/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
import base64
import io
import os
import time
import json
from pathlib import Path
import matplotlib.pyplot as plt

from openpilot.tools.lib.logreader import LogReader
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("<h1>Longitudinal maneuver report</h1>\n")
f.write(f"<h3>{platform}</h3>\n")
f.write(f"<h3>{route}</h3>\n")
f.write(f"<details><summary><h3 style='display: inline-block;'>CarParams</h3></summary><pre>{format_car_params(CP)}</pre></details>\n")
for description, runs in maneuvers:
print('plotting maneuver:', description, 'runs:', len(runs))
print(f'plotting maneuver: {description}, runs: {len(runs)}')
f.write("<div style='border-top: 1px solid #000; margin: 20px 0;'></div>\n")
f.write(f"<h2>{description}</h2>\n")
for run, msgs in enumerate(runs):
Expand All @@ -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]
Expand All @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 03ea2b1

Please sign in to comment.