James Kuszmaul | 73fc135 | 2021-04-09 22:31:25 -0700 | [diff] [blame] | 1 | // Provides a plot for debugging drivetrain-related issues. |
| 2 | import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter'; |
| 3 | import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors'; |
| 4 | import * as proxy from 'org_frc971/aos/network/www/proxy'; |
| 5 | |
| 6 | import Connection = proxy.Connection; |
| 7 | |
| 8 | const TIME = AosPlotter.TIME; |
| 9 | const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH; |
| 10 | const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT; |
| 11 | |
| 12 | export function plotSpline(conn: Connection, element: Element): void { |
| 13 | const aosPlotter = new AosPlotter(conn); |
| 14 | |
| 15 | const goal = aosPlotter.addMessageSource( |
| 16 | '/drivetrain', 'frc971.control_loops.drivetrain.Goal'); |
| 17 | const position = aosPlotter.addMessageSource( |
| 18 | '/drivetrain', 'frc971.control_loops.drivetrain.Position'); |
| 19 | const status = aosPlotter.addMessageSource( |
| 20 | '/drivetrain', 'frc971.control_loops.drivetrain.Status'); |
| 21 | const output = aosPlotter.addMessageSource( |
| 22 | '/drivetrain', 'frc971.control_loops.drivetrain.Output'); |
| 23 | |
| 24 | let currentTop = 0; |
| 25 | |
| 26 | // Polydrivetrain (teleop control) plots |
| 27 | const longitudinalPlot = aosPlotter.addPlot( |
| 28 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 29 | currentTop += DEFAULT_HEIGHT / 2; |
| 30 | longitudinalPlot.plot.getAxisLabels().setTitle('Longitudinal Distance'); |
| 31 | longitudinalPlot.plot.getAxisLabels().setXLabel(TIME); |
| 32 | longitudinalPlot.plot.getAxisLabels().setYLabel('meters'); |
| 33 | |
| 34 | longitudinalPlot.addMessageLine( |
| 35 | status, ['trajectory_logging', 'distance_remaining']); |
| 36 | |
| 37 | const boolPlot = aosPlotter.addPlot( |
| 38 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 39 | currentTop += DEFAULT_HEIGHT / 2; |
| 40 | boolPlot.plot.getAxisLabels().setTitle('Bool Flags'); |
| 41 | boolPlot.plot.getAxisLabels().setXLabel(TIME); |
| 42 | boolPlot.plot.getAxisLabels().setYLabel('boolean'); |
| 43 | |
| 44 | boolPlot.addMessageLine(status, ['trajectory_logging', 'is_executing']) |
| 45 | .setColor(RED); |
| 46 | boolPlot.addMessageLine(status, ['trajectory_logging', 'is_executed']) |
| 47 | .setColor(BLUE); |
| 48 | |
| 49 | const handlePlot = aosPlotter.addPlot( |
| 50 | element, [0, currentTop], [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 51 | currentTop += DEFAULT_HEIGHT; |
| 52 | handlePlot.plot.getAxisLabels().setTitle('Spline Handles'); |
| 53 | handlePlot.plot.getAxisLabels().setXLabel(TIME); |
| 54 | handlePlot.plot.getAxisLabels().setYLabel('handle number'); |
| 55 | |
| 56 | handlePlot |
| 57 | .addMessageLine(status, ['trajectory_logging', 'available_splines[]']) |
| 58 | .setColor(RED) |
| 59 | .setDrawLine(false); |
| 60 | handlePlot |
| 61 | .addMessageLine(status, ['trajectory_logging', 'goal_spline_handle']) |
| 62 | .setColor(BLUE) |
| 63 | .setPointSize(0.0); |
| 64 | handlePlot |
| 65 | .addMessageLine(status, ['trajectory_logging', 'current_spline_idx']) |
| 66 | .setColor(GREEN) |
| 67 | .setPointSize(0.0); |
| 68 | } |