James Kuszmaul | 9c23d26 | 2021-09-25 21:50:02 -0700 | [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 * as proxy from 'org_frc971/aos/network/www/proxy'; |
| 4 | import * as configuration from 'org_frc971/aos/configuration_generated'; |
| 5 | import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors'; |
| 6 | import {MessageHandler, TimestampedMessage} from 'org_frc971/aos/network/www/aos_plotter'; |
| 7 | import {Point} from 'org_frc971/aos/network/www/plotter'; |
| 8 | import {Table} from 'org_frc971/aos/network/www/reflection'; |
| 9 | import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer'; |
| 10 | |
| 11 | import Connection = proxy.Connection; |
| 12 | import Schema = configuration.reflection.Schema; |
| 13 | |
| 14 | const TIME = AosPlotter.TIME; |
| 15 | const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH; |
| 16 | const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT; |
| 17 | |
| 18 | |
| 19 | export function plotLocalizer(conn: Connection, element: Element) : void { |
| 20 | const aosPlotter = new AosPlotter(conn); |
| 21 | const localizerDebug = |
| 22 | aosPlotter.addMessageSource('/drivetrain', 'y2020.control_loops.drivetrain.LocalizerDebug'); |
| 23 | const imageMatch = |
| 24 | aosPlotter.addMessageSource('/pi1/camera', 'frc971.vision.sift.ImageMatchResult'); |
James Kuszmaul | ed177c4 | 2021-09-30 18:53:08 -0700 | [diff] [blame] | 25 | const drivetrainStatus = aosPlotter.addMessageSource( |
| 26 | '/drivetrain', 'frc971.control_loops.drivetrain.Status'); |
| 27 | const superstructureStatus = aosPlotter.addMessageSource( |
| 28 | '/superstructure', 'y2020.control_loops.superstructure.Status'); |
James Kuszmaul | 9c23d26 | 2021-09-25 21:50:02 -0700 | [diff] [blame] | 29 | |
| 30 | var currentTop = 0; |
| 31 | |
| 32 | const imageAcceptedPlot = aosPlotter.addPlot( |
| 33 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 34 | currentTop += DEFAULT_HEIGHT; |
| 35 | imageAcceptedPlot.plot.getAxisLabels().setTitle('Image Acceptance'); |
| 36 | imageAcceptedPlot.plot.getAxisLabels().setXLabel(TIME); |
| 37 | imageAcceptedPlot.plot.getAxisLabels().setYLabel('[bool]'); |
| 38 | imageAcceptedPlot.plot.setDefaultYRange([-0.05, 1.05]); |
| 39 | |
| 40 | imageAcceptedPlot.addMessageLine(localizerDebug, ['matches[]', 'accepted']) |
| 41 | .setColor(RED) |
| 42 | .setDrawLine(false); |
| 43 | |
| 44 | const impliedXPlot = aosPlotter.addPlot( |
| 45 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 46 | currentTop += DEFAULT_HEIGHT; |
| 47 | impliedXPlot.plot.getAxisLabels().setTitle('Implied Robot X'); |
| 48 | impliedXPlot.plot.getAxisLabels().setXLabel(TIME); |
| 49 | impliedXPlot.plot.getAxisLabels().setYLabel('[m]'); |
| 50 | |
| 51 | impliedXPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_x']) |
| 52 | .setColor(RED) |
| 53 | .setDrawLine(false); |
| 54 | impliedXPlot.addMessageLine(imageMatch, ['camera_poses[]', 'field_to_camera', 'data[3]']) |
| 55 | .setColor(BLUE) |
| 56 | .setDrawLine(false); |
James Kuszmaul | ed177c4 | 2021-09-30 18:53:08 -0700 | [diff] [blame] | 57 | impliedXPlot.addMessageLine(drivetrainStatus, ['x']) |
| 58 | .setColor(GREEN) |
| 59 | .setLabel('Localizer X'); |
James Kuszmaul | 9c23d26 | 2021-09-25 21:50:02 -0700 | [diff] [blame] | 60 | |
| 61 | const impliedYPlot = aosPlotter.addPlot( |
| 62 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 63 | currentTop += DEFAULT_HEIGHT; |
| 64 | impliedYPlot.plot.getAxisLabels().setTitle('Implied Robot Y'); |
| 65 | impliedYPlot.plot.getAxisLabels().setXLabel(TIME); |
| 66 | impliedYPlot.plot.getAxisLabels().setYLabel('[m]'); |
| 67 | |
| 68 | impliedYPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_y']) |
| 69 | .setColor(RED) |
| 70 | .setDrawLine(false); |
| 71 | impliedYPlot.addMessageLine(imageMatch, ['camera_poses[]', 'field_to_camera', 'data[7]']) |
| 72 | .setColor(BLUE) |
| 73 | .setDrawLine(false); |
James Kuszmaul | ed177c4 | 2021-09-30 18:53:08 -0700 | [diff] [blame] | 74 | impliedYPlot.addMessageLine(drivetrainStatus, ['y']) |
| 75 | .setColor(GREEN) |
| 76 | .setLabel('Localizer Y'); |
James Kuszmaul | 9c23d26 | 2021-09-25 21:50:02 -0700 | [diff] [blame] | 77 | |
| 78 | const impliedHeadingPlot = aosPlotter.addPlot( |
| 79 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 80 | currentTop += DEFAULT_HEIGHT; |
| 81 | impliedHeadingPlot.plot.getAxisLabels().setTitle('Implied Robot Theta'); |
| 82 | impliedHeadingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 83 | impliedHeadingPlot.plot.getAxisLabels().setYLabel('[rad]'); |
| 84 | |
| 85 | impliedHeadingPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_theta']) |
| 86 | .setColor(RED) |
| 87 | .setDrawLine(false); |
James Kuszmaul | ed177c4 | 2021-09-30 18:53:08 -0700 | [diff] [blame] | 88 | impliedHeadingPlot.addMessageLine(drivetrainStatus, ['theta']) |
| 89 | .setColor(GREEN) |
| 90 | .setLabel('Localizer Theta'); |
James Kuszmaul | 9c23d26 | 2021-09-25 21:50:02 -0700 | [diff] [blame] | 91 | |
| 92 | const impliedTurretGoalPlot = aosPlotter.addPlot( |
| 93 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 94 | currentTop += DEFAULT_HEIGHT; |
| 95 | impliedTurretGoalPlot.plot.getAxisLabels().setTitle('Implied Turret Goal'); |
| 96 | impliedTurretGoalPlot.plot.getAxisLabels().setXLabel(TIME); |
| 97 | impliedTurretGoalPlot.plot.getAxisLabels().setYLabel('[rad]'); |
| 98 | |
| 99 | impliedTurretGoalPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_turret_goal']) |
| 100 | .setColor(RED) |
| 101 | .setDrawLine(false); |
James Kuszmaul | ed177c4 | 2021-09-30 18:53:08 -0700 | [diff] [blame] | 102 | impliedTurretGoalPlot.addMessageLine(superstructureStatus, ['aimer', 'turret_position']) |
| 103 | .setColor(GREEN); |
James Kuszmaul | 9c23d26 | 2021-09-25 21:50:02 -0700 | [diff] [blame] | 104 | |
| 105 | const imageTimingPlot = aosPlotter.addPlot( |
| 106 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 107 | currentTop += DEFAULT_HEIGHT; |
| 108 | imageTimingPlot.plot.getAxisLabels().setTitle('Timing Plot'); |
| 109 | imageTimingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 110 | imageTimingPlot.plot.getAxisLabels().setYLabel('[ns]'); |
| 111 | |
| 112 | imageTimingPlot.addMessageLine(localizerDebug, ['matches[]', 'image_age_sec']) |
| 113 | .setColor(RED) |
| 114 | .setDrawLine(false); |
| 115 | } |