Milind Upadhyay | eb739bb | 2022-03-02 10:49:21 -0800 | [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 {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE, ORANGE} from 'org_frc971/aos/network/www/colors'; |
| 5 | |
| 6 | import Connection = proxy.Connection; |
| 7 | |
| 8 | const TIME = AosPlotter.TIME; |
| 9 | const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH * 5 / 2; |
| 10 | const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT * 3; |
| 11 | |
| 12 | export function plotClimber(conn: Connection, element: Element) : void { |
| 13 | const aosPlotter = new AosPlotter(conn); |
| 14 | const goal = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Goal'); |
| 15 | const output = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Output'); |
| 16 | const status = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Status'); |
| 17 | const robotState = aosPlotter.addMessageSource('/aos', 'aos.RobotState'); |
| 18 | |
| 19 | // Robot Enabled/Disabled and Mode |
| 20 | const positionPlot = |
| 21 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 22 | positionPlot.plot.getAxisLabels().setTitle('Position'); |
| 23 | positionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 24 | positionPlot.plot.getAxisLabels().setYLabel('rad'); |
| 25 | positionPlot.plot.setDefaultYRange([-1.0, 2.0]); |
| 26 | |
| 27 | positionPlot.addMessageLine(status, ['climber', 'position']).setColor(GREEN).setPointSize(4.0); |
| 28 | positionPlot.addMessageLine(status, ['climber', 'velocity']).setColor(PINK).setPointSize(1.0); |
| 29 | positionPlot.addMessageLine(status, ['climber', 'goal_position']).setColor(RED).setPointSize(4.0); |
| 30 | positionPlot.addMessageLine(status, ['climber', 'goal_velocity']).setColor(ORANGE).setPointSize(4.0); |
| 31 | positionPlot.addMessageLine(status, ['climber', 'estimator_state', 'position']).setColor(CYAN).setPointSize(1.0); |
| 32 | |
| 33 | const voltagePlot = |
| 34 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 35 | voltagePlot.plot.getAxisLabels().setTitle('Voltage'); |
| 36 | voltagePlot.plot.getAxisLabels().setXLabel(TIME); |
| 37 | voltagePlot.plot.getAxisLabels().setYLabel('Volts'); |
| 38 | voltagePlot.plot.setDefaultYRange([-4.0, 14.0]); |
| 39 | |
| 40 | voltagePlot.addMessageLine(output, ['climber_voltage']).setColor(BLUE).setPointSize(4.0); |
| 41 | voltagePlot.addMessageLine(status, ['climber', 'voltage_error']).setColor(RED).setPointSize(1.0); |
| 42 | voltagePlot.addMessageLine(status, ['climber', 'position_power']).setColor(BROWN).setPointSize(1.0); |
| 43 | voltagePlot.addMessageLine(status, ['climber', 'velocity_power']).setColor(CYAN).setPointSize(1.0); |
| 44 | voltagePlot.addMessageLine(robotState, ['voltage_battery']).setColor(GREEN).setPointSize(1.0); |
| 45 | |
| 46 | } |