forked from frc971/971-Robot-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corrections_plotter.ts
173 lines (148 loc) · 6.26 KB
/
corrections_plotter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import {ByteBuffer} from 'flatbuffers';
import {AosPlotter} from '../../aos/network/www/aos_plotter';
import {MessageHandler, TimestampedMessage} from '../../aos/network/www/aos_plotter';
import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from '../../aos/network/www/colors';
import {Connection} from '../../aos/network/www/proxy';
import {Table} from '../../aos/network/www/reflection';
import {Schema} from 'flatbuffers_reflection/reflection_generated';
import {Visualization, TargetEstimateDebug} from './visualization_generated';
const TIME = AosPlotter.TIME;
// magenta, yellow, cyan, black
const PI_COLORS = [[255, 0, 255], [255, 255, 0], [0, 255, 255], [0, 0, 0]];
class VisionMessageHandler extends MessageHandler {
constructor(private readonly schema: Schema) {
super(schema);
}
private readScalar(table: Table, fieldName: string): number|BigInt|null {
return this.parser.readScalar(table, fieldName);
}
addMessage(data: Uint8Array, time: number): void {
const message = Visualization.getRootAsVisualization(new ByteBuffer(data));
for (let ii = 0; ii < message.targetsLength(); ++ii) {
const target = message.targets(ii);
const time = Number(target.imageMonotonicTimestampNs()) * 1e-9;
if (time == 0) {
console.log('Dropping message without populated time?');
continue;
}
const table = Table.getNamedTable(
target.bb, this.schema, 'y2023.localizer.TargetEstimateDebug', target.bb_pos);
this.messages.push(new TimestampedMessage(table, time));
}
}
}
export function plotVision(conn: Connection, element: Element): void {
const aosPlotter = new AosPlotter(conn);
const targets = [];
for (const pi of ['pi1', 'pi2', 'pi3', 'pi4']) {
targets.push(aosPlotter.addRawMessageSource(
'/' + pi + '/camera', 'y2023.localizer.Visualization',
new VisionMessageHandler(
conn.getSchema('y2023.localizer.Visualization'))));
}
const localizerStatus = aosPlotter.addMessageSource(
'/localizer', 'y2023.localizer.Status');
const localizerOutput = aosPlotter.addMessageSource(
'/localizer', 'frc971.controls.LocalizerOutput');
const statsPlot = aosPlotter.addPlot(element);
statsPlot.plot.getAxisLabels().setTitle('Statistics');
statsPlot.plot.getAxisLabels().setXLabel(TIME);
statsPlot.plot.getAxisLabels().setYLabel('[bool, enum]');
statsPlot
.addMessageLine(localizerStatus, ['statistics[]', 'total_accepted'])
.setDrawLine(false)
.setColor(BLUE);
statsPlot
.addMessageLine(localizerStatus, ['statistics[]', 'total_candidates'])
.setDrawLine(false)
.setColor(RED);
const rejectionPlot = aosPlotter.addPlot(element);
rejectionPlot.plot.getAxisLabels().setTitle('Rejection Reasons');
rejectionPlot.plot.getAxisLabels().setXLabel(TIME);
rejectionPlot.plot.getAxisLabels().setYLabel('[bool, enum]');
for (let ii = 0; ii < targets.length; ++ii) {
rejectionPlot.addMessageLine(targets[ii], ['rejection_reason'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
const xPlot = aosPlotter.addPlot(element);
xPlot.plot.getAxisLabels().setTitle('X Position');
xPlot.plot.getAxisLabels().setXLabel(TIME);
xPlot.plot.getAxisLabels().setYLabel('[m]');
for (let ii = 0; ii < targets.length; ++ii) {
xPlot.addMessageLine(targets[ii], ['implied_robot_x'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
xPlot.addMessageLine(localizerOutput, ['x'])
.setDrawLine(false)
.setColor(BLUE);
const correctionXPlot = aosPlotter.addPlot(element);
correctionXPlot.plot.getAxisLabels().setTitle('X Corrections');
correctionXPlot.plot.getAxisLabels().setXLabel(TIME);
correctionXPlot.plot.getAxisLabels().setYLabel('[m]');
for (let ii = 0; ii < targets.length; ++ii) {
correctionXPlot.addMessageLine(targets[ii], ['correction_x'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
const yPlot = aosPlotter.addPlot(element);
yPlot.plot.getAxisLabels().setTitle('Y Position');
yPlot.plot.getAxisLabels().setXLabel(TIME);
yPlot.plot.getAxisLabels().setYLabel('[m]');
for (let ii = 0; ii < targets.length; ++ii) {
yPlot.addMessageLine(targets[ii], ['implied_robot_y'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
yPlot.addMessageLine(localizerOutput, ['y'])
.setDrawLine(false)
.setColor(BLUE);
const correctionYPlot = aosPlotter.addPlot(element);
correctionYPlot.plot.getAxisLabels().setTitle('Y Corrections');
correctionYPlot.plot.getAxisLabels().setXLabel(TIME);
correctionYPlot.plot.getAxisLabels().setYLabel('[m]');
for (let ii = 0; ii < targets.length; ++ii) {
correctionYPlot.addMessageLine(targets[ii], ['correction_y'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
const thetaPlot = aosPlotter.addPlot(element);
thetaPlot.plot.getAxisLabels().setTitle('Yaw');
thetaPlot.plot.getAxisLabels().setXLabel(TIME);
thetaPlot.plot.getAxisLabels().setYLabel('[m]');
for (let ii = 0; ii < targets.length; ++ii) {
thetaPlot.addMessageLine(targets[ii], ['implied_robot_theta'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
thetaPlot.addMessageLine(localizerOutput, ['theta'])
.setDrawLine(false)
.setColor(BLUE);
const aprilTagPlot = aosPlotter.addPlot(element);
aprilTagPlot.plot.getAxisLabels().setTitle('April Tag IDs');
aprilTagPlot.plot.getAxisLabels().setXLabel(TIME);
aprilTagPlot.plot.getAxisLabels().setYLabel('[id]');
for (let ii = 0; ii < targets.length; ++ii) {
aprilTagPlot.addMessageLine(targets[ii], ['april_tag'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
const imageAgePlot = aosPlotter.addPlot(element);
imageAgePlot.plot.getAxisLabels().setTitle('Image Age');
imageAgePlot.plot.getAxisLabels().setXLabel(TIME);
imageAgePlot.plot.getAxisLabels().setYLabel('[sec]');
for (let ii = 0; ii < targets.length; ++ii) {
imageAgePlot.addMessageLine(targets[ii], ['image_age_sec'])
.setDrawLine(false)
.setColor(PI_COLORS[ii])
.setLabel('pi' + (ii + 1));
}
}