milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | // Provides a plot for debugging robot state-related issues. |
| 2 | import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter'; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 3 | import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors'; |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 4 | import * as proxy from 'org_frc971/aos/network/www/proxy'; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 5 | |
| 6 | import Connection = proxy.Connection; |
| 7 | |
| 8 | const TIME = AosPlotter.TIME; |
Austin Schuh | c9b42db | 2022-03-12 12:03:29 -0800 | [diff] [blame] | 9 | const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH * 2; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 10 | const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT * 3; |
| 11 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 12 | export function plotSuperstructure(conn: Connection, element: Element): void { |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 13 | const aosPlotter = new AosPlotter(conn); |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 14 | const goal = aosPlotter.addMessageSource( |
| 15 | '/superstructure', 'y2022.control_loops.superstructure.Goal'); |
| 16 | const output = aosPlotter.addMessageSource( |
| 17 | '/superstructure', 'y2022.control_loops.superstructure.Output'); |
| 18 | const status = aosPlotter.addMessageSource( |
| 19 | '/superstructure', 'y2022.control_loops.superstructure.Status'); |
| 20 | const position = aosPlotter.addMessageSource( |
| 21 | '/superstructure', 'y2022.control_loops.superstructure.Position'); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 22 | const robotState = aosPlotter.addMessageSource('/aos', 'aos.RobotState'); |
Ravago Jones | 71e434b | 2022-03-06 14:09:40 -0800 | [diff] [blame] | 23 | |
| 24 | const positionPlot = |
| 25 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 26 | positionPlot.plot.getAxisLabels().setTitle('States'); |
| 27 | positionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 28 | positionPlot.plot.getAxisLabels().setYLabel('wonky state units'); |
| 29 | positionPlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 30 | |
| 31 | positionPlot.addMessageLine(position, ['turret_beambreak']) |
| 32 | .setColor(RED) |
| 33 | .setPointSize(4.0); |
| 34 | positionPlot.addMessageLine(status, ['state']) |
| 35 | .setColor(CYAN) |
| 36 | .setPointSize(1.0); |
| 37 | positionPlot.addMessageLine(status, ['flippers_open']) |
| 38 | .setColor(WHITE) |
| 39 | .setPointSize(1.0); |
| 40 | positionPlot.addMessageLine(status, ['reseating_in_catapult']) |
| 41 | .setColor(BLUE) |
| 42 | .setPointSize(1.0); |
| 43 | positionPlot.addMessageLine(status, ['fire']) |
| 44 | .setColor(CYAN) |
| 45 | .setPointSize(1.0); |
| 46 | |
| 47 | |
| 48 | const intakePlot = |
| 49 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 50 | intakePlot.plot.getAxisLabels().setTitle('Intake'); |
| 51 | intakePlot.plot.getAxisLabels().setXLabel(TIME); |
| 52 | intakePlot.plot.getAxisLabels().setYLabel('wonky state units'); |
| 53 | intakePlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 54 | intakePlot.addMessageLine(status, ['intake_state']) |
| 55 | .setColor(RED) |
| 56 | .setPointSize(1.0); |
| 57 | intakePlot.addMessageLine(position, ['intake_beambreak_front']) |
| 58 | .setColor(GREEN) |
| 59 | .setPointSize(4.0); |
| 60 | intakePlot.addMessageLine(position, ['intake_beambreak_back']) |
| 61 | .setColor(PINK) |
| 62 | .setPointSize(1.0); |
| 63 | |
| 64 | |
| 65 | const otherPlot = |
| 66 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 67 | otherPlot.plot.getAxisLabels().setTitle('Position'); |
| 68 | otherPlot.plot.getAxisLabels().setXLabel(TIME); |
| 69 | otherPlot.plot.getAxisLabels().setYLabel('rad'); |
| 70 | otherPlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 71 | |
| 72 | otherPlot.addMessageLine(status, ['catapult', 'position']) |
| 73 | .setColor(PINK) |
| 74 | .setPointSize(4.0); |
| 75 | otherPlot.addMessageLine(position, ['flipper_arm_left', 'encoder']) |
| 76 | .setColor(BLUE) |
| 77 | .setPointSize(4.0); |
| 78 | otherPlot.addMessageLine(position, ['flipper_arm_right', 'encoder']) |
| 79 | .setColor(CYAN) |
| 80 | .setPointSize(4.0); |
James Kuszmaul | ccc566f | 2022-03-12 14:10:00 -0800 | [diff] [blame] | 81 | otherPlot.addMessageLine(output, ['flipper_arms_voltage']) |
| 82 | .setColor(BROWN) |
| 83 | .setPointSize(4.0); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 84 | } |