blob: e6729dddc385650b0574a2676e057f473d21ba69 [file] [log] [blame]
James Kuszmaul9c23d262021-09-25 21:50:02 -07001// Provides a plot for debugging robot state-related issues.
2import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter';
3import * as proxy from 'org_frc971/aos/network/www/proxy';
4import * as configuration from 'org_frc971/aos/configuration_generated';
5import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors';
6import {MessageHandler, TimestampedMessage} from 'org_frc971/aos/network/www/aos_plotter';
7import {Point} from 'org_frc971/aos/network/www/plotter';
8import {Table} from 'org_frc971/aos/network/www/reflection';
9import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer';
10
11import Connection = proxy.Connection;
12import Schema = configuration.reflection.Schema;
13
14const TIME = AosPlotter.TIME;
15const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH;
16const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT;
17
18
19export function plotLocalizer(conn: Connection, element: Element) : void {
20 const aosPlotter = new AosPlotter(conn);
21 const localizerDebug =
22 aosPlotter.addMessageSource('/drivetrain', 'y2020.control_loops.drivetrain.LocalizerDebug');
23 const imageMatch =
24 aosPlotter.addMessageSource('/pi1/camera', 'frc971.vision.sift.ImageMatchResult');
James Kuszmauled177c42021-09-30 18:53:08 -070025 const drivetrainStatus = aosPlotter.addMessageSource(
26 '/drivetrain', 'frc971.control_loops.drivetrain.Status');
27 const superstructureStatus = aosPlotter.addMessageSource(
28 '/superstructure', 'y2020.control_loops.superstructure.Status');
James Kuszmaul9c23d262021-09-25 21:50:02 -070029
30 var currentTop = 0;
31
32 const imageAcceptedPlot = aosPlotter.addPlot(
33 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
34 currentTop += DEFAULT_HEIGHT;
35 imageAcceptedPlot.plot.getAxisLabels().setTitle('Image Acceptance');
36 imageAcceptedPlot.plot.getAxisLabels().setXLabel(TIME);
37 imageAcceptedPlot.plot.getAxisLabels().setYLabel('[bool]');
38 imageAcceptedPlot.plot.setDefaultYRange([-0.05, 1.05]);
39
40 imageAcceptedPlot.addMessageLine(localizerDebug, ['matches[]', 'accepted'])
41 .setColor(RED)
42 .setDrawLine(false);
43
44 const impliedXPlot = aosPlotter.addPlot(
45 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
46 currentTop += DEFAULT_HEIGHT;
47 impliedXPlot.plot.getAxisLabels().setTitle('Implied Robot X');
48 impliedXPlot.plot.getAxisLabels().setXLabel(TIME);
49 impliedXPlot.plot.getAxisLabels().setYLabel('[m]');
50
51 impliedXPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_x'])
52 .setColor(RED)
53 .setDrawLine(false);
54 impliedXPlot.addMessageLine(imageMatch, ['camera_poses[]', 'field_to_camera', 'data[3]'])
55 .setColor(BLUE)
56 .setDrawLine(false);
James Kuszmauled177c42021-09-30 18:53:08 -070057 impliedXPlot.addMessageLine(drivetrainStatus, ['x'])
58 .setColor(GREEN)
59 .setLabel('Localizer X');
James Kuszmaul9c23d262021-09-25 21:50:02 -070060
61 const impliedYPlot = aosPlotter.addPlot(
62 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
63 currentTop += DEFAULT_HEIGHT;
64 impliedYPlot.plot.getAxisLabels().setTitle('Implied Robot Y');
65 impliedYPlot.plot.getAxisLabels().setXLabel(TIME);
66 impliedYPlot.plot.getAxisLabels().setYLabel('[m]');
67
68 impliedYPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_y'])
69 .setColor(RED)
70 .setDrawLine(false);
71 impliedYPlot.addMessageLine(imageMatch, ['camera_poses[]', 'field_to_camera', 'data[7]'])
72 .setColor(BLUE)
73 .setDrawLine(false);
James Kuszmauled177c42021-09-30 18:53:08 -070074 impliedYPlot.addMessageLine(drivetrainStatus, ['y'])
75 .setColor(GREEN)
76 .setLabel('Localizer Y');
James Kuszmaul9c23d262021-09-25 21:50:02 -070077
78 const impliedHeadingPlot = aosPlotter.addPlot(
79 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
80 currentTop += DEFAULT_HEIGHT;
81 impliedHeadingPlot.plot.getAxisLabels().setTitle('Implied Robot Theta');
82 impliedHeadingPlot.plot.getAxisLabels().setXLabel(TIME);
83 impliedHeadingPlot.plot.getAxisLabels().setYLabel('[rad]');
84
85 impliedHeadingPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_theta'])
86 .setColor(RED)
87 .setDrawLine(false);
James Kuszmauled177c42021-09-30 18:53:08 -070088 impliedHeadingPlot.addMessageLine(drivetrainStatus, ['theta'])
89 .setColor(GREEN)
90 .setLabel('Localizer Theta');
James Kuszmaul9c23d262021-09-25 21:50:02 -070091
92 const impliedTurretGoalPlot = aosPlotter.addPlot(
93 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
94 currentTop += DEFAULT_HEIGHT;
95 impliedTurretGoalPlot.plot.getAxisLabels().setTitle('Implied Turret Goal');
96 impliedTurretGoalPlot.plot.getAxisLabels().setXLabel(TIME);
97 impliedTurretGoalPlot.plot.getAxisLabels().setYLabel('[rad]');
98
99 impliedTurretGoalPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_turret_goal'])
100 .setColor(RED)
101 .setDrawLine(false);
James Kuszmauled177c42021-09-30 18:53:08 -0700102 impliedTurretGoalPlot.addMessageLine(superstructureStatus, ['aimer', 'turret_position'])
103 .setColor(GREEN);
James Kuszmaul9c23d262021-09-25 21:50:02 -0700104
105 const imageTimingPlot = aosPlotter.addPlot(
106 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
107 currentTop += DEFAULT_HEIGHT;
108 imageTimingPlot.plot.getAxisLabels().setTitle('Timing Plot');
109 imageTimingPlot.plot.getAxisLabels().setXLabel(TIME);
110 imageTimingPlot.plot.getAxisLabels().setYLabel('[ns]');
111
112 imageTimingPlot.addMessageLine(localizerDebug, ['matches[]', 'image_age_sec'])
113 .setColor(RED)
114 .setDrawLine(false);
115}