Add typescript plot for catapult
Change-Id: I85edabb05fa6bc2f770724e170cda467095e37d0
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/y2022/BUILD b/y2022/BUILD
index c20f18d..cf52280 100644
--- a/y2022/BUILD
+++ b/y2022/BUILD
@@ -9,6 +9,9 @@
data = [
":config",
],
+ dirs = [
+ "//y2022/www:www_files",
+ ],
start_binaries = [
"//aos/events/logging:logger_main",
"//aos/network:web_proxy_main",
diff --git a/y2022/control_loops/superstructure/BUILD b/y2022/control_loops/superstructure/BUILD
index 9bae7c7..644b53b 100644
--- a/y2022/control_loops/superstructure/BUILD
+++ b/y2022/control_loops/superstructure/BUILD
@@ -1,4 +1,4 @@
-load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_ts_library")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
package(default_visibility = ["//visibility:public"])
@@ -35,6 +35,18 @@
],
)
+flatbuffer_ts_library(
+ name = "superstructure_status_ts_fbs",
+ srcs = [
+ "superstructure_status.fbs",
+ ],
+ includes = [
+ "//frc971/control_loops:control_loops_fbs_includes",
+ "//frc971/control_loops:profiled_subsystem_fbs_includes",
+ ],
+ target_compatible_with = ["@platforms//os:linux"],
+)
+
flatbuffer_cc_library(
name = "superstructure_position_fbs",
srcs = [
@@ -115,3 +127,14 @@
"//aos/network/www:proxy",
],
)
+
+ts_library(
+ name = "catapult_plotter",
+ srcs = ["catapult_plotter.ts"],
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ "//aos/network/www:aos_plotter",
+ "//aos/network/www:colors",
+ "//aos/network/www:proxy",
+ ],
+)
diff --git a/y2022/control_loops/superstructure/catapult_plotter.ts b/y2022/control_loops/superstructure/catapult_plotter.ts
new file mode 100644
index 0000000..cfa360d
--- /dev/null
+++ b/y2022/control_loops/superstructure/catapult_plotter.ts
@@ -0,0 +1,57 @@
+// Provides a plot for debugging robot state-related issues.
+import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter';
+import * as proxy from 'org_frc971/aos/network/www/proxy';
+import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE, ORANGE} from 'org_frc971/aos/network/www/colors';
+
+import Connection = proxy.Connection;
+
+const TIME = AosPlotter.TIME;
+const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH * 5 / 2;
+const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT * 3;
+
+export function plotCatapult(conn: Connection, element: Element) : void {
+ const aosPlotter = new AosPlotter(conn);
+ const goal = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Goal');
+ const output = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Output');
+ const status = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Status');
+ const robotState = aosPlotter.addMessageSource('/aos', 'aos.RobotState');
+
+ // Robot Enabled/Disabled and Mode
+ const positionPlot =
+ aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]);
+ positionPlot.plot.getAxisLabels().setTitle('Position');
+ positionPlot.plot.getAxisLabels().setXLabel(TIME);
+ positionPlot.plot.getAxisLabels().setYLabel('rad');
+ positionPlot.plot.setDefaultYRange([-1.0, 2.0]);
+
+ positionPlot.addMessageLine(goal, ['catapult', 'return_position', 'unsafe_goal']).setColor(BLUE).setPointSize(1.0);
+ positionPlot.addMessageLine(goal, ['catapult', 'fire']).setColor(WHITE).setPointSize(1.0);
+ positionPlot.addMessageLine(status, ['mpc_active']).setColor(WHITE).setPointSize(3.0);
+ positionPlot.addMessageLine(status, ['catapult', 'goal_position']).setColor(RED).setPointSize(4.0);
+ positionPlot.addMessageLine(status, ['catapult', 'goal_velocity']).setColor(ORANGE).setPointSize(4.0);
+ positionPlot.addMessageLine(status, ['catapult', 'position']).setColor(GREEN).setPointSize(4.0);
+ positionPlot.addMessageLine(status, ['catapult', 'velocity']).setColor(PINK).setPointSize(1.0);
+ positionPlot.addMessageLine(status, ['catapult', 'calculated_velocity']).setColor(BROWN).setPointSize(1.0);
+ positionPlot.addMessageLine(status, ['catapult', 'estimator_state', 'position']).setColor(CYAN).setPointSize(1.0);
+
+ const voltagePlot =
+ aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]);
+ voltagePlot.plot.getAxisLabels().setTitle('Voltage');
+ voltagePlot.plot.getAxisLabels().setXLabel(TIME);
+ voltagePlot.plot.getAxisLabels().setYLabel('Volts');
+ voltagePlot.plot.setDefaultYRange([-4.0, 14.0]);
+
+ voltagePlot.addMessageLine(output, ['catapult_voltage']).setColor(BLUE).setPointSize(4.0);
+ voltagePlot.addMessageLine(status, ['catapult', 'voltage_error']).setColor(RED).setPointSize(1.0);
+ voltagePlot.addMessageLine(status, ['catapult', 'position_power']).setColor(BROWN).setPointSize(1.0);
+ voltagePlot.addMessageLine(status, ['catapult', 'velocity_power']).setColor(CYAN).setPointSize(1.0);
+ voltagePlot.addMessageLine(robotState, ['voltage_battery']).setColor(GREEN).setPointSize(1.0);
+
+ const solvePlot =
+ aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]);
+ solvePlot.plot.getAxisLabels().setTitle('Solve Time');
+ solvePlot.plot.getAxisLabels().setXLabel(TIME);
+ solvePlot.plot.getAxisLabels().setYLabel('Seconds');
+ solvePlot.plot.setDefaultYRange([-0.0005, 0.001]);
+ solvePlot.addMessageLine(status, ['solve_time']).setColor(WHITE).setPointSize(4.0);
+}
diff --git a/y2022/www/BUILD b/y2022/www/BUILD
new file mode 100644
index 0000000..55cbde2
--- /dev/null
+++ b/y2022/www/BUILD
@@ -0,0 +1,21 @@
+load("//frc971/downloader:downloader.bzl", "aos_downloader_dir")
+
+filegroup(
+ name = "files",
+ srcs = glob([
+ "**/*.html",
+ "**/*.css",
+ ]),
+ visibility = ["//visibility:public"],
+)
+
+aos_downloader_dir(
+ name = "www_files",
+ srcs = [
+ ":files",
+ "//frc971/analysis:plot_index_bundle.min.js",
+ ],
+ dir = "www",
+ target_compatible_with = ["@platforms//os:linux"],
+ visibility = ["//visibility:public"],
+)
diff --git a/y2022/www/index.html b/y2022/www/index.html
new file mode 100644
index 0000000..70442f9
--- /dev/null
+++ b/y2022/www/index.html
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ <a href="plotter.html">Plots</a>
+ </body>
+</html>
diff --git a/y2022/www/plotter.html b/y2022/www/plotter.html
new file mode 100644
index 0000000..629ceaa
--- /dev/null
+++ b/y2022/www/plotter.html
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <script src="plot_index_bundle.min.js" defer></script>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/y2022/www/styles.css b/y2022/www/styles.css
new file mode 100644
index 0000000..c486115
--- /dev/null
+++ b/y2022/www/styles.css
@@ -0,0 +1,81 @@
+.channel {
+ display: flex;
+ border-bottom: 1px solid;
+ font-size: 24px;
+}
+#field {
+ display: inline-block
+}
+
+#targets,
+#readouts,
+#vision_readouts {
+ display: inline-block;
+ vertical-align: top;
+ float: right;
+}
+
+#legend {
+ display: inline-block;
+}
+
+#outer_target {
+ border: 1px solid black;
+ width: 140px;
+ background-color: white;
+}
+
+#inner_target {
+ width: 60px;
+ height: 60px;
+ margin: 40px;
+ border: 1px solid black;
+ background-color: white;
+}
+
+#outer_target.targetted,
+#inner_target.targetted {
+ background-color: green;
+}
+
+table, th, td {
+ border: 1px solid black;
+ border-collapse: collapse;
+ padding: 5px;
+ margin: 10px;
+}
+
+th, td {
+ text-align: right;
+ width: 70px;
+}
+
+td:first-child {
+ width: 150px;
+}
+
+.near {
+ background-color: LightGreen;
+ border-radius: 10px;
+}
+
+.zeroing {
+ background-color: yellow;
+ border-radius: 10px;
+}
+
+.faulted {
+ background-color: red;
+ border-radius: 10px;
+}
+
+#vision_readouts > div {
+ display: table-row;
+ padding: 5px;
+}
+
+#vision_readouts > div > div {
+ display: table-cell;
+ padding: 5px;
+ text-align: right;
+}