Skip to content

Commit 70fa0ab

Browse files
debug: touch events plot (commaai#34242)
* replay * remove
1 parent f6885dc commit 70fa0ab

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

selfdrive/debug/touch_replay.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)