|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import argparse |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +import matplotlib.pyplot as plt |
| 6 | + |
| 7 | +from openpilot.tools.lib.logreader import LogReader |
| 8 | + |
| 9 | +if __name__ == '__main__': |
| 10 | + parser = argparse.ArgumentParser() |
| 11 | + parser.add_argument('--width', default=2160, type=int) |
| 12 | + parser.add_argument('--height', default=1080, type=int) |
| 13 | + parser.add_argument('--route', default='rlog', type=str) |
| 14 | + args = parser.parse_args() |
| 15 | + |
| 16 | + w = args.width |
| 17 | + h = args.height |
| 18 | + route = args.route |
| 19 | + |
| 20 | + fingers = [[-1, -1]] * 5 |
| 21 | + touch_points = [] |
| 22 | + current_slot = 0 |
| 23 | + |
| 24 | + lr = list(LogReader(route)) |
| 25 | + for msg in lr: |
| 26 | + if msg.which() == 'touch': |
| 27 | + for event in msg.touch: |
| 28 | + if event.type == 3 and event.code == 47: |
| 29 | + current_slot = event.value |
| 30 | + elif event.type == 3 and event.code == 57 and event.value == -1: |
| 31 | + fingers[current_slot] = [-1, -1] |
| 32 | + elif event.type == 3 and event.code == 53: |
| 33 | + fingers[current_slot][1] = h - (h - event.value) |
| 34 | + if fingers[current_slot][0] != -1: |
| 35 | + touch_points.append(fingers[current_slot].copy()) |
| 36 | + elif event.type == 3 and event.code == 54: |
| 37 | + fingers[current_slot][0] = w - event.value |
| 38 | + if fingers[current_slot][1] != -1: |
| 39 | + touch_points.append(fingers[current_slot].copy()) |
| 40 | + |
| 41 | + unique_points, counts = np.unique(touch_points, axis=0, return_counts=True) |
| 42 | + |
| 43 | + plt.figure(figsize=(10, 3)) |
| 44 | + plt.scatter(unique_points[:, 0], unique_points[:, 1], c=counts, s=counts * 20, edgecolors='red') |
| 45 | + plt.colorbar() |
| 46 | + plt.title(f'Touches for {route}') |
| 47 | + plt.grid(True) |
| 48 | + plt.show() |
0 commit comments