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