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 | |
Ravago Jones | 8b00478 | 2022-03-05 17:23:08 -0800 | [diff] [blame^] | 12 | export function plotIntakeFront(conn: Connection, element: Element) : void { |
Milind Upadhyay | eb739bb | 2022-03-02 10:49:21 -0800 | [diff] [blame] | 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 positionPlotFront = |
| 21 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 22 | positionPlotFront.plot.getAxisLabels().setTitle('Position'); |
| 23 | positionPlotFront.plot.getAxisLabels().setXLabel(TIME); |
| 24 | positionPlotFront.plot.getAxisLabels().setYLabel('rad'); |
| 25 | positionPlotFront.plot.setDefaultYRange([-1.0, 2.0]); |
| 26 | |
| 27 | positionPlotFront.addMessageLine(status, ['intake_front', 'position']).setColor(GREEN).setPointSize(4.0); |
| 28 | positionPlotFront.addMessageLine(status, ['intake_front', 'velocity']).setColor(PINK).setPointSize(1.0); |
| 29 | positionPlotFront.addMessageLine(status, ['intake_front', 'goal_position']).setColor(RED).setPointSize(4.0); |
| 30 | positionPlotFront.addMessageLine(status, ['intake_front', 'goal_velocity']).setColor(ORANGE).setPointSize(4.0); |
| 31 | positionPlotFront.addMessageLine(status, ['intake_front', 'estimator_state', 'position']).setColor(CYAN).setPointSize(1.0); |
| 32 | |
Milind Upadhyay | eb739bb | 2022-03-02 10:49:21 -0800 | [diff] [blame] | 33 | const voltagePlotFront = |
| 34 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 35 | voltagePlotFront.plot.getAxisLabels().setTitle('Voltage'); |
| 36 | voltagePlotFront.plot.getAxisLabels().setXLabel(TIME); |
| 37 | voltagePlotFront.plot.getAxisLabels().setYLabel('Volts'); |
| 38 | voltagePlotFront.plot.setDefaultYRange([-4.0, 14.0]); |
| 39 | |
Griffin Bui | 9fb87e6 | 2022-03-05 16:05:53 -0800 | [diff] [blame] | 40 | voltagePlotFront.addMessageLine(output, ['intake_voltage_front']).setColor(BLUE).setPointSize(4.0); |
Milind Upadhyay | eb739bb | 2022-03-02 10:49:21 -0800 | [diff] [blame] | 41 | voltagePlotFront.addMessageLine(status, ['intake_front', 'voltage_error']).setColor(RED).setPointSize(1.0); |
| 42 | voltagePlotFront.addMessageLine(status, ['intake_front', 'position_power']).setColor(BROWN).setPointSize(1.0); |
| 43 | voltagePlotFront.addMessageLine(status, ['intake_front', 'velocity_power']).setColor(CYAN).setPointSize(1.0); |
| 44 | voltagePlotFront.addMessageLine(robotState, ['voltage_battery']).setColor(GREEN).setPointSize(1.0); |
Ravago Jones | 8b00478 | 2022-03-05 17:23:08 -0800 | [diff] [blame^] | 45 | } |
| 46 | |
| 47 | export function plotIntakeBack(conn: Connection, element: Element) : void { |
| 48 | const aosPlotter = new AosPlotter(conn); |
| 49 | const goal = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Goal'); |
| 50 | const output = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Output'); |
| 51 | const status = aosPlotter.addMessageSource('/superstructure', 'y2022.control_loops.superstructure.Status'); |
| 52 | const robotState = aosPlotter.addMessageSource('/aos', 'aos.RobotState'); |
| 53 | |
| 54 | // Robot Enabled/Disabled and Mode |
| 55 | const positionPlotFront = |
| 56 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 57 | positionPlotFront.plot.getAxisLabels().setTitle('Position'); |
| 58 | positionPlotFront.plot.getAxisLabels().setXLabel(TIME); |
| 59 | positionPlotFront.plot.getAxisLabels().setYLabel('rad'); |
| 60 | positionPlotFront.plot.setDefaultYRange([-1.0, 2.0]); |
| 61 | |
| 62 | const positionPlotBack = |
| 63 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 64 | positionPlotBack.plot.getAxisLabels().setTitle('Position'); |
| 65 | positionPlotBack.plot.getAxisLabels().setXLabel(TIME); |
| 66 | positionPlotBack.plot.getAxisLabels().setYLabel('rad'); |
| 67 | positionPlotBack.plot.setDefaultYRange([-1.0, 2.0]); |
| 68 | |
| 69 | positionPlotBack.addMessageLine(status, ['intake_back', 'position']).setColor(GREEN).setPointSize(4.0); |
| 70 | positionPlotBack.addMessageLine(status, ['intake_back', 'velocity']).setColor(PINK).setPointSize(1.0); |
| 71 | positionPlotBack.addMessageLine(status, ['intake_back', 'goal_position']).setColor(RED).setPointSize(4.0); |
| 72 | positionPlotBack.addMessageLine(status, ['intake_back', 'goal_velocity']).setColor(ORANGE).setPointSize(4.0); |
| 73 | positionPlotBack.addMessageLine(status, ['intake_back', 'estimator_state', 'position']).setColor(CYAN).setPointSize(1.0); |
Milind Upadhyay | eb739bb | 2022-03-02 10:49:21 -0800 | [diff] [blame] | 74 | |
| 75 | |
| 76 | const voltagePlotBack = |
| 77 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 2]); |
| 78 | voltagePlotBack.plot.getAxisLabels().setTitle('Voltage'); |
| 79 | voltagePlotBack.plot.getAxisLabels().setXLabel(TIME); |
| 80 | voltagePlotBack.plot.getAxisLabels().setYLabel('Volts'); |
| 81 | voltagePlotBack.plot.setDefaultYRange([-4.0, 14.0]); |
| 82 | |
Griffin Bui | 9fb87e6 | 2022-03-05 16:05:53 -0800 | [diff] [blame] | 83 | voltagePlotBack.addMessageLine(output, ['intake_voltage_back']).setColor(BLUE).setPointSize(4.0); |
Milind Upadhyay | eb739bb | 2022-03-02 10:49:21 -0800 | [diff] [blame] | 84 | voltagePlotBack.addMessageLine(status, ['intake_back', 'voltage_error']).setColor(RED).setPointSize(1.0); |
| 85 | voltagePlotBack.addMessageLine(status, ['intake_back', 'position_power']).setColor(BROWN).setPointSize(1.0); |
| 86 | voltagePlotBack.addMessageLine(status, ['intake_back', 'velocity_power']).setColor(CYAN).setPointSize(1.0); |
| 87 | voltagePlotBack.addMessageLine(robotState, ['voltage_battery']).setColor(GREEN).setPointSize(1.0); |
| 88 | } |