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'); |
| 25 | |
| 26 | var currentTop = 0; |
| 27 | |
| 28 | const imageAcceptedPlot = aosPlotter.addPlot( |
| 29 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 30 | currentTop += DEFAULT_HEIGHT; |
| 31 | imageAcceptedPlot.plot.getAxisLabels().setTitle('Image Acceptance'); |
| 32 | imageAcceptedPlot.plot.getAxisLabels().setXLabel(TIME); |
| 33 | imageAcceptedPlot.plot.getAxisLabels().setYLabel('[bool]'); |
| 34 | imageAcceptedPlot.plot.setDefaultYRange([-0.05, 1.05]); |
| 35 | |
| 36 | imageAcceptedPlot.addMessageLine(localizerDebug, ['matches[]', 'accepted']) |
| 37 | .setColor(RED) |
| 38 | .setDrawLine(false); |
| 39 | |
| 40 | const impliedXPlot = aosPlotter.addPlot( |
| 41 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 42 | currentTop += DEFAULT_HEIGHT; |
| 43 | impliedXPlot.plot.getAxisLabels().setTitle('Implied Robot X'); |
| 44 | impliedXPlot.plot.getAxisLabels().setXLabel(TIME); |
| 45 | impliedXPlot.plot.getAxisLabels().setYLabel('[m]'); |
| 46 | |
| 47 | impliedXPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_x']) |
| 48 | .setColor(RED) |
| 49 | .setDrawLine(false); |
| 50 | impliedXPlot.addMessageLine(imageMatch, ['camera_poses[]', 'field_to_camera', 'data[3]']) |
| 51 | .setColor(BLUE) |
| 52 | .setDrawLine(false); |
| 53 | |
| 54 | const impliedYPlot = aosPlotter.addPlot( |
| 55 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 56 | currentTop += DEFAULT_HEIGHT; |
| 57 | impliedYPlot.plot.getAxisLabels().setTitle('Implied Robot Y'); |
| 58 | impliedYPlot.plot.getAxisLabels().setXLabel(TIME); |
| 59 | impliedYPlot.plot.getAxisLabels().setYLabel('[m]'); |
| 60 | |
| 61 | impliedYPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_y']) |
| 62 | .setColor(RED) |
| 63 | .setDrawLine(false); |
| 64 | impliedYPlot.addMessageLine(imageMatch, ['camera_poses[]', 'field_to_camera', 'data[7]']) |
| 65 | .setColor(BLUE) |
| 66 | .setDrawLine(false); |
| 67 | |
| 68 | const impliedHeadingPlot = aosPlotter.addPlot( |
| 69 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 70 | currentTop += DEFAULT_HEIGHT; |
| 71 | impliedHeadingPlot.plot.getAxisLabels().setTitle('Implied Robot Theta'); |
| 72 | impliedHeadingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 73 | impliedHeadingPlot.plot.getAxisLabels().setYLabel('[rad]'); |
| 74 | |
| 75 | impliedHeadingPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_robot_theta']) |
| 76 | .setColor(RED) |
| 77 | .setDrawLine(false); |
| 78 | |
| 79 | const impliedTurretGoalPlot = aosPlotter.addPlot( |
| 80 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 81 | currentTop += DEFAULT_HEIGHT; |
| 82 | impliedTurretGoalPlot.plot.getAxisLabels().setTitle('Implied Turret Goal'); |
| 83 | impliedTurretGoalPlot.plot.getAxisLabels().setXLabel(TIME); |
| 84 | impliedTurretGoalPlot.plot.getAxisLabels().setYLabel('[rad]'); |
| 85 | |
| 86 | impliedTurretGoalPlot.addMessageLine(localizerDebug, ['matches[]', 'implied_turret_goal']) |
| 87 | .setColor(RED) |
| 88 | .setDrawLine(false); |
| 89 | |
| 90 | const imageTimingPlot = aosPlotter.addPlot( |
| 91 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 92 | currentTop += DEFAULT_HEIGHT; |
| 93 | imageTimingPlot.plot.getAxisLabels().setTitle('Timing Plot'); |
| 94 | imageTimingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 95 | imageTimingPlot.plot.getAxisLabels().setYLabel('[ns]'); |
| 96 | |
| 97 | imageTimingPlot.addMessageLine(localizerDebug, ['matches[]', 'image_age_sec']) |
| 98 | .setColor(RED) |
| 99 | .setDrawLine(false); |
| 100 | } |