James Kuszmaul | b35e234 | 2022-03-06 15:44:00 -0800 | [diff] [blame^] | 1 | import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter'; |
| 2 | import * as proxy from 'org_frc971/aos/network/www/proxy'; |
| 3 | import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors'; |
| 4 | |
| 5 | import Connection = proxy.Connection; |
| 6 | |
| 7 | const TIME = AosPlotter.TIME; |
| 8 | // magenta, yellow, cyan, orange |
| 9 | const PI_COLORS = [[255, 0, 255], [255, 255, 0], [0, 255, 255], [255, 165, 0]]; |
| 10 | |
| 11 | export function plotVision(conn: Connection, element: Element): void { |
| 12 | const aosPlotter = new AosPlotter(conn); |
| 13 | |
| 14 | const targets = []; |
| 15 | for (const pi of ["pi1", "pi2", "pi3", "pi4"]) { |
| 16 | targets.push(aosPlotter.addMessageSource( |
| 17 | '/' + pi + '/camera', 'y2022.vision.TargetEstimate')); |
| 18 | } |
| 19 | const localizer = aosPlotter.addMessageSource( |
| 20 | '/localizer', 'frc971.controls.LocalizerVisualization'); |
| 21 | const localizerOutput = aosPlotter.addMessageSource( |
| 22 | '/localizer', 'frc971.controls.LocalizerOutput'); |
| 23 | const superstructureStatus = aosPlotter.addMessageSource( |
| 24 | '/superstructure', 'y2022.control_loops.superstructure.Status'); |
| 25 | |
| 26 | const rejectionPlot = aosPlotter.addPlot(element); |
| 27 | rejectionPlot.plot.getAxisLabels().setTitle("Rejection Reasons"); |
| 28 | rejectionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 29 | rejectionPlot.plot.getAxisLabels().setYLabel("[bool, enum]"); |
| 30 | |
| 31 | rejectionPlot.addMessageLine(localizer, ['targets[]', 'accepted']) |
| 32 | .setDrawLine(false) |
| 33 | .setColor(BLUE); |
| 34 | rejectionPlot.addMessageLine(localizer, ['targets[]', 'rejection_reason']) |
| 35 | .setDrawLine(false) |
| 36 | .setColor(RED); |
| 37 | |
| 38 | const xPlot = aosPlotter.addPlot(element); |
| 39 | xPlot.plot.getAxisLabels().setTitle("X Position"); |
| 40 | xPlot.plot.getAxisLabels().setXLabel(TIME); |
| 41 | xPlot.plot.getAxisLabels().setYLabel("[m]"); |
| 42 | |
| 43 | xPlot.addMessageLine(localizer, ['targets[]', 'implied_robot_x']) |
| 44 | .setDrawLine(false) |
| 45 | .setColor(RED); |
| 46 | xPlot.addMessageLine(localizerOutput, ['x']) |
| 47 | .setDrawLine(false) |
| 48 | .setColor(BLUE); |
| 49 | |
| 50 | const yPlot = aosPlotter.addPlot(element); |
| 51 | yPlot.plot.getAxisLabels().setTitle("X Position"); |
| 52 | yPlot.plot.getAxisLabels().setXLabel(TIME); |
| 53 | yPlot.plot.getAxisLabels().setYLabel("[m]"); |
| 54 | |
| 55 | yPlot.addMessageLine(localizer, ['targets[]', 'implied_robot_y']) |
| 56 | .setDrawLine(false) |
| 57 | .setColor(RED); |
| 58 | yPlot.addMessageLine(localizerOutput, ['y']) |
| 59 | .setDrawLine(false) |
| 60 | .setColor(BLUE); |
| 61 | |
| 62 | const turretPlot = aosPlotter.addPlot(element); |
| 63 | turretPlot.plot.getAxisLabels().setTitle("Turret Position"); |
| 64 | turretPlot.plot.getAxisLabels().setXLabel(TIME); |
| 65 | turretPlot.plot.getAxisLabels().setYLabel("[m]"); |
| 66 | |
| 67 | turretPlot.addMessageLine(localizer, ['targets[]', 'implied_turret_goal']) |
| 68 | .setDrawLine(false) |
| 69 | .setColor(RED); |
| 70 | turretPlot.addMessageLine(superstructureStatus, ['turret', 'position']) |
| 71 | .setPointSize(0.0) |
| 72 | .setColor(BLUE); |
| 73 | turretPlot |
| 74 | .addMessageLine( |
| 75 | superstructureStatus, ['aimer', 'turret_position']) |
| 76 | .setPointSize(0.0) |
| 77 | .setColor(GREEN); |
| 78 | |
| 79 | const anglePlot = aosPlotter.addPlot(element); |
| 80 | anglePlot.plot.getAxisLabels().setTitle("TargetEstimate Angle"); |
| 81 | anglePlot.plot.getAxisLabels().setXLabel(TIME); |
| 82 | anglePlot.plot.getAxisLabels().setYLabel("[rad]"); |
| 83 | |
| 84 | for (let ii = 0; ii < targets.length; ++ii) { |
| 85 | anglePlot.addMessageLine(targets[ii], ['angle_to_target']) |
| 86 | .setDrawLine(false) |
| 87 | .setColor(PI_COLORS[ii]) |
| 88 | .setLabel('pi' + ii); |
| 89 | } |
| 90 | |
| 91 | const distancePlot = aosPlotter.addPlot(element); |
| 92 | distancePlot.plot.getAxisLabels().setTitle("TargetEstimate Distance"); |
| 93 | distancePlot.plot.getAxisLabels().setXLabel(TIME); |
| 94 | distancePlot.plot.getAxisLabels().setYLabel("[rad]"); |
| 95 | |
| 96 | for (let ii = 0; ii < targets.length; ++ii) { |
| 97 | distancePlot.addMessageLine(targets[ii], ['distance']) |
| 98 | .setDrawLine(false) |
| 99 | .setColor(PI_COLORS[ii]) |
| 100 | .setLabel('pi' + ii); |
| 101 | } |
| 102 | |
| 103 | const confidencePlot = aosPlotter.addPlot(element); |
| 104 | confidencePlot.plot.getAxisLabels().setTitle("TargetEstimate Confidence"); |
| 105 | confidencePlot.plot.getAxisLabels().setXLabel(TIME); |
| 106 | confidencePlot.plot.getAxisLabels().setYLabel("[rad]"); |
| 107 | |
| 108 | for (let ii = 0; ii < targets.length; ++ii) { |
| 109 | confidencePlot.addMessageLine(targets[ii], ['confidence']) |
| 110 | .setDrawLine(false) |
| 111 | .setColor(PI_COLORS[ii]) |
| 112 | .setLabel('pi' + ii); |
| 113 | } |
| 114 | } |