Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame^] | 1 | // Provides a plot for debugging robot state-related issues. |
| 2 | import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter'; |
| 3 | import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors'; |
| 4 | import * as proxy from 'org_frc971/aos/network/www/proxy'; |
| 5 | |
| 6 | import Connection = proxy.Connection; |
| 7 | |
| 8 | const TIME = AosPlotter.TIME; |
| 9 | const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH * 2; |
| 10 | const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT * 3; |
| 11 | |
| 12 | export function plotSuperstructure(conn: Connection, element: Element): void { |
| 13 | const aosPlotter = new AosPlotter(conn); |
| 14 | const goal = aosPlotter.addMessageSource( |
| 15 | '/superstructure', 'y2023.control_loops.superstructure.Goal'); |
| 16 | const output = aosPlotter.addMessageSource( |
| 17 | '/superstructure', 'y2023.control_loops.superstructure.Output'); |
| 18 | const status = aosPlotter.addMessageSource( |
| 19 | '/superstructure', 'y2023.control_loops.superstructure.Status'); |
| 20 | const position = aosPlotter.addMessageSource( |
| 21 | '/superstructure', 'y2023.control_loops.superstructure.Position'); |
| 22 | const robotState = aosPlotter.addMessageSource('/aos', 'aos.RobotState'); |
| 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(PINK) |
| 36 | .setPointSize(4.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(BROWN) |
| 45 | .setPointSize(1.0); |
| 46 | positionPlot.addMessageLine(status, ['ready_to_fire']) |
| 47 | .setColor(GREEN) |
| 48 | .setPointSize(1.0); |
| 49 | positionPlot.addMessageLine(status, ['collided']) |
| 50 | .setColor(PINK) |
| 51 | .setPointSize(1.0); |
| 52 | |
| 53 | const goalPlot = |
| 54 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 55 | goalPlot.plot.getAxisLabels().setTitle('Goal'); |
| 56 | goalPlot.plot.getAxisLabels().setXLabel(TIME); |
| 57 | goalPlot.plot.getAxisLabels().setYLabel('value'); |
| 58 | goalPlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 59 | goalPlot.addMessageLine(goal, ['fire']).setColor(RED).setPointSize(1.0); |
| 60 | goalPlot.addMessageLine(goal, ['auto_aim']).setColor(BLUE).setPointSize(1.0); |
| 61 | |
| 62 | |
| 63 | const shotCountPlot = |
| 64 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 65 | shotCountPlot.plot.getAxisLabels().setTitle('Shot Count'); |
| 66 | shotCountPlot.plot.getAxisLabels().setXLabel(TIME); |
| 67 | shotCountPlot.plot.getAxisLabels().setYLabel('balls'); |
| 68 | shotCountPlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 69 | shotCountPlot.addMessageLine(status, ['shot_count']) |
| 70 | .setColor(RED) |
| 71 | .setPointSize(1.0); |
| 72 | |
| 73 | const intakePlot = |
| 74 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 75 | intakePlot.plot.getAxisLabels().setTitle('Intake'); |
| 76 | intakePlot.plot.getAxisLabels().setXLabel(TIME); |
| 77 | intakePlot.plot.getAxisLabels().setYLabel('wonky state units'); |
| 78 | intakePlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 79 | intakePlot.addMessageLine(status, ['intake_state']) |
| 80 | .setColor(RED) |
| 81 | .setPointSize(1.0); |
| 82 | intakePlot.addMessageLine(position, ['intake_beambreak_front']) |
| 83 | .setColor(GREEN) |
| 84 | .setPointSize(4.0); |
| 85 | intakePlot.addMessageLine(position, ['intake_beambreak_back']) |
| 86 | .setColor(PINK) |
| 87 | .setPointSize(1.0); |
| 88 | intakePlot.addMessageLine(output, ['transfer_roller_voltage']) |
| 89 | .setColor(BROWN) |
| 90 | .setPointSize(3.0); |
| 91 | |
| 92 | |
| 93 | const otherPlot = |
| 94 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 95 | otherPlot.plot.getAxisLabels().setTitle('Position'); |
| 96 | otherPlot.plot.getAxisLabels().setXLabel(TIME); |
| 97 | otherPlot.plot.getAxisLabels().setYLabel('rad'); |
| 98 | otherPlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 99 | |
| 100 | otherPlot.addMessageLine(status, ['catapult', 'position']) |
| 101 | .setColor(PINK) |
| 102 | .setPointSize(4.0); |
| 103 | otherPlot.addMessageLine(status, ['turret', 'position']) |
| 104 | .setColor(WHITE) |
| 105 | .setPointSize(4.0); |
| 106 | otherPlot.addMessageLine(position, ['flipper_arm_left', 'encoder']) |
| 107 | .setColor(BLUE) |
| 108 | .setPointSize(4.0); |
| 109 | otherPlot.addMessageLine(position, ['flipper_arm_right', 'encoder']) |
| 110 | .setColor(CYAN) |
| 111 | .setPointSize(4.0); |
| 112 | otherPlot.addMessageLine(output, ['flipper_arms_voltage']) |
| 113 | .setColor(BROWN) |
| 114 | .setPointSize(4.0); |
| 115 | } |