blob: 3d975d8141c6f778c425df661c180a2af22a2694 [file] [log] [blame]
James Kuszmaul78101402021-09-11 12:42:21 -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 {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors';
5
6import Connection = proxy.Connection;
7
8const TIME = AosPlotter.TIME;
9const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH;
10const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT;
11
12export function plotTurret(conn: Connection, element: Element) : void {
13 const aosPlotter = new AosPlotter(conn);
14 const goal = aosPlotter.addMessageSource('/superstructure', 'y2020.control_loops.superstructure.Goal');
15 const output = aosPlotter.addMessageSource('/superstructure', 'y2020.control_loops.superstructure.Output');
16 const status = aosPlotter.addMessageSource(
17 '/superstructure', 'y2020.control_loops.superstructure.Status');
18 const pdpValues =
19 aosPlotter.addMessageSource('/roborio/aos', 'frc971.PDPValues');
20
21 var currentTop = 0;
22
23 const turretPosPlot = aosPlotter.addPlot(
24 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
25 currentTop += DEFAULT_HEIGHT;
26 turretPosPlot.plot.getAxisLabels().setTitle('Turret Goal Position');
27 turretPosPlot.plot.getAxisLabels().setXLabel(TIME);
28 turretPosPlot.plot.getAxisLabels().setYLabel('rad');
29
30 turretPosPlot.addMessageLine(status, ['aimer', 'turret_position'])
31 .setColor(RED)
32 .setPointSize(0.0);
33 turretPosPlot.addMessageLine(status, ['turret', 'position'])
34 .setColor(GREEN)
35 .setPointSize(0.0);
36 turretPosPlot.addMessageLine(status, ['turret', 'unprofiled_goal_position'])
37 .setColor(BLUE)
38 .setPointSize(0.0);
39
40 const turretVoltagePlot = aosPlotter.addPlot(
41 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
42 currentTop += DEFAULT_HEIGHT;
43 turretVoltagePlot.plot.getAxisLabels().setTitle('Turret Voltage');
44 turretVoltagePlot.plot.getAxisLabels().setXLabel(TIME);
45 turretVoltagePlot.plot.getAxisLabels().setYLabel('V');
46
47 turretVoltagePlot.addMessageLine(output, ['turret_voltage'])
48 .setColor(RED)
49 .setPointSize(0.0);
50
51 const currentPlot = aosPlotter.addPlot(
52 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
53 currentTop += DEFAULT_HEIGHT;
54 currentPlot.plot.getAxisLabels().setTitle('Current');
55 currentPlot.plot.getAxisLabels().setXLabel(TIME);
56 currentPlot.plot.getAxisLabels().setYLabel('Amps');
57 currentPlot.plot.setDefaultYRange([0.0, 80.0]);
58
59 currentPlot.addMessageLine(pdpValues, ['currents[6]'])
60 .setColor(GREEN)
61 .setPointSize(0.0);
62
63
64 const targetDistancePlot = aosPlotter.addPlot(
65 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
66 currentTop += DEFAULT_HEIGHT;
67 targetDistancePlot.plot.getAxisLabels().setTitle('Target distance');
68 targetDistancePlot.plot.getAxisLabels().setXLabel(TIME);
69 targetDistancePlot.plot.getAxisLabels().setYLabel('m');
70
71 targetDistancePlot.addMessageLine(status, ['aimer', 'target_distance'])
72 .setColor(RED)
73 .setPointSize(0.0);
74
75 const targetChoicePlot = aosPlotter.addPlot(
76 element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]);
77 currentTop += DEFAULT_HEIGHT;
78 targetChoicePlot.plot.getAxisLabels().setTitle('Target choice');
79 targetChoicePlot.plot.getAxisLabels().setXLabel(TIME);
80 targetChoicePlot.plot.getAxisLabels().setYLabel('[bool]');
81 targetChoicePlot.plot.setDefaultYRange([-0.05, 1.05]);
82
83 targetChoicePlot.addMessageLine(status, ['aimer', 'aiming_for_inner_port'])
84 .setColor(RED)
85 .setPointSize(0.0);
86}