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']) |
milind-u | c63d094 | 2022-04-15 12:07:42 -0700 | [diff] [blame] | 35 | .setColor(PINK) |
| 36 | .setPointSize(4.0); |
Ravago Jones | 71e434b | 2022-03-06 14:09:40 -0800 | [diff] [blame] | 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']) |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [diff] [blame] | 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) |
Ravago Jones | 71e434b | 2022-03-06 14:09:40 -0800 | [diff] [blame] | 51 | .setPointSize(1.0); |
| 52 | |
Milind Upadhyay | 5c40678 | 2022-09-26 21:28:35 -0700 | [diff] [blame^] | 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 | |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [diff] [blame] | 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); |
Ravago Jones | 71e434b | 2022-03-06 14:09:40 -0800 | [diff] [blame] | 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); |
milind-u | c63d094 | 2022-04-15 12:07:42 -0700 | [diff] [blame] | 88 | intakePlot.addMessageLine(output, ['transfer_roller_voltage']) |
| 89 | .setColor(BROWN) |
| 90 | .setPointSize(3.0); |
Ravago Jones | 71e434b | 2022-03-06 14:09:40 -0800 | [diff] [blame] | 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); |
milind-u | c63d094 | 2022-04-15 12:07:42 -0700 | [diff] [blame] | 103 | otherPlot.addMessageLine(status, ['turret', 'position']) |
| 104 | .setColor(WHITE) |
| 105 | .setPointSize(4.0); |
Ravago Jones | 71e434b | 2022-03-06 14:09:40 -0800 | [diff] [blame] | 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); |
James Kuszmaul | ccc566f | 2022-03-12 14:10:00 -0800 | [diff] [blame] | 112 | otherPlot.addMessageLine(output, ['flipper_arms_voltage']) |
| 113 | .setColor(BROWN) |
| 114 | .setPointSize(4.0); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 115 | } |