James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame^] | 1 | // Provides a plot for debugging drivetrain-related issues. |
| 2 | import {AosPlotter} from '../../aos/network/www/aos_plotter'; |
| 3 | import {ImuMessageHandler} from '../../frc971/wpilib/imu_plot_utils'; |
| 4 | import * as proxy from '../../aos/network/www/proxy'; |
| 5 | import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from '../../aos/network/www/colors'; |
| 6 | |
| 7 | import Connection = proxy.Connection; |
| 8 | |
| 9 | const TIME = AosPlotter.TIME; |
| 10 | const DEFAULT_WIDTH = AosPlotter.DEFAULT_WIDTH; |
| 11 | const DEFAULT_HEIGHT = AosPlotter.DEFAULT_HEIGHT; |
| 12 | |
| 13 | export function plotLocalizer(conn: Connection, element: Element): void { |
| 14 | const aosPlotter = new AosPlotter(conn); |
| 15 | |
| 16 | const position = aosPlotter.addMessageSource("/drivetrain", |
| 17 | "frc971.control_loops.drivetrain.Position"); |
| 18 | const status = aosPlotter.addMessageSource( |
| 19 | '/drivetrain', 'frc971.control_loops.drivetrain.Status'); |
| 20 | const output = aosPlotter.addMessageSource( |
| 21 | '/drivetrain', 'frc971.control_loops.drivetrain.Output'); |
| 22 | const localizer = aosPlotter.addMessageSource( |
| 23 | '/localizer', 'y2024.localizer.Status'); |
| 24 | const imu = aosPlotter.addRawMessageSource( |
| 25 | '/localizer', 'frc971.IMUValuesBatch', |
| 26 | new ImuMessageHandler(conn.getSchema('frc971.IMUValuesBatch'))); |
| 27 | |
| 28 | // Drivetrain Status estimated relative position |
| 29 | const positionPlot = aosPlotter.addPlot(element); |
| 30 | positionPlot.plot.getAxisLabels().setTitle("Estimated Relative Position " + |
| 31 | "of the Drivetrain"); |
| 32 | positionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 33 | positionPlot.plot.getAxisLabels().setYLabel("Relative Position (m)"); |
| 34 | const leftPosition = |
| 35 | positionPlot.addMessageLine(status, ["estimated_left_position"]); |
| 36 | leftPosition.setColor(RED); |
| 37 | const rightPosition = |
| 38 | positionPlot.addMessageLine(status, ["estimated_right_position"]); |
| 39 | rightPosition.setColor(GREEN); |
| 40 | positionPlot.addMessageLine(position, ['left_encoder']) |
| 41 | .setColor(BROWN) |
| 42 | .setDrawLine(false); |
| 43 | positionPlot.addMessageLine(position, ['right_encoder']) |
| 44 | .setColor(CYAN) |
| 45 | .setDrawLine(false); |
| 46 | |
| 47 | |
| 48 | // Drivetrain Velocities |
| 49 | const velocityPlot = aosPlotter.addPlot(element); |
| 50 | velocityPlot.plot.getAxisLabels().setTitle('Velocity Plots'); |
| 51 | velocityPlot.plot.getAxisLabels().setXLabel(TIME); |
| 52 | velocityPlot.plot.getAxisLabels().setYLabel('Wheel Velocity (m/s)'); |
| 53 | |
| 54 | const leftVelocity = |
| 55 | velocityPlot.addMessageLine(status, ['estimated_left_velocity']); |
| 56 | leftVelocity.setColor(RED); |
| 57 | const rightVelocity = |
| 58 | velocityPlot.addMessageLine(status, ['estimated_right_velocity']); |
| 59 | rightVelocity.setColor(GREEN); |
| 60 | |
| 61 | const leftSpeed = velocityPlot.addMessageLine(position, ["left_speed"]); |
| 62 | leftSpeed.setColor(BLUE); |
| 63 | const rightSpeed = velocityPlot.addMessageLine(position, ["right_speed"]); |
| 64 | rightSpeed.setColor(BROWN); |
| 65 | |
| 66 | const ekfLeftVelocity = velocityPlot.addMessageLine( |
| 67 | localizer, ['state', 'left_velocity']); |
| 68 | ekfLeftVelocity.setColor(RED); |
| 69 | ekfLeftVelocity.setPointSize(0.0); |
| 70 | const ekfRightVelocity = velocityPlot.addMessageLine( |
| 71 | localizer, ['state', 'right_velocity']); |
| 72 | ekfRightVelocity.setColor(GREEN); |
| 73 | ekfRightVelocity.setPointSize(0.0); |
| 74 | |
| 75 | // Lateral velocity |
| 76 | const lateralPlot = aosPlotter.addPlot(element); |
| 77 | lateralPlot.plot.getAxisLabels().setTitle('Lateral Velocity'); |
| 78 | lateralPlot.plot.getAxisLabels().setXLabel(TIME); |
| 79 | lateralPlot.plot.getAxisLabels().setYLabel('Velocity (m/s)'); |
| 80 | |
| 81 | lateralPlot.addMessageLine(localizer, ['state', 'lateral_velocity']).setColor(CYAN); |
| 82 | |
| 83 | // Drivetrain Voltage |
| 84 | const voltagePlot = aosPlotter.addPlot(element); |
| 85 | voltagePlot.plot.getAxisLabels().setTitle('Voltage Plots'); |
| 86 | voltagePlot.plot.getAxisLabels().setXLabel(TIME); |
| 87 | voltagePlot.plot.getAxisLabels().setYLabel('Voltage (V)') |
| 88 | |
| 89 | voltagePlot.addMessageLine(localizer, ['state', 'left_voltage_error']) |
| 90 | .setColor(RED) |
| 91 | .setDrawLine(false); |
| 92 | voltagePlot.addMessageLine(localizer, ['state', 'right_voltage_error']) |
| 93 | .setColor(GREEN) |
| 94 | .setDrawLine(false); |
| 95 | voltagePlot.addMessageLine(output, ['left_voltage']) |
| 96 | .setColor(RED) |
| 97 | .setPointSize(0); |
| 98 | voltagePlot.addMessageLine(output, ['right_voltage']) |
| 99 | .setColor(GREEN) |
| 100 | .setPointSize(0); |
| 101 | |
| 102 | // Heading |
| 103 | const yawPlot = aosPlotter.addPlot(element); |
| 104 | yawPlot.plot.getAxisLabels().setTitle('Robot Yaw'); |
| 105 | yawPlot.plot.getAxisLabels().setXLabel(TIME); |
| 106 | yawPlot.plot.getAxisLabels().setYLabel('Yaw (rad)'); |
| 107 | |
| 108 | yawPlot.addMessageLine(status, ['localizer', 'theta']).setColor(GREEN); |
| 109 | |
| 110 | yawPlot.addMessageLine(localizer, ['down_estimator', 'yaw']).setColor(BLUE); |
| 111 | |
| 112 | yawPlot.addMessageLine(localizer, ['state', 'theta']).setColor(RED); |
| 113 | |
| 114 | // Pitch/Roll |
| 115 | const orientationPlot = aosPlotter.addPlot(element); |
| 116 | orientationPlot.plot.getAxisLabels().setTitle('Orientation'); |
| 117 | orientationPlot.plot.getAxisLabels().setXLabel(TIME); |
| 118 | orientationPlot.plot.getAxisLabels().setYLabel('Angle (rad)'); |
| 119 | |
| 120 | orientationPlot.addMessageLine(localizer, ['down_estimator', 'lateral_pitch']) |
| 121 | .setColor(RED) |
| 122 | .setLabel('roll'); |
| 123 | orientationPlot |
| 124 | .addMessageLine(localizer, ['down_estimator', 'longitudinal_pitch']) |
| 125 | .setColor(GREEN) |
| 126 | .setLabel('pitch'); |
| 127 | |
| 128 | const stillPlot = aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 3]); |
| 129 | stillPlot.plot.getAxisLabels().setTitle('Still Plot'); |
| 130 | stillPlot.plot.getAxisLabels().setXLabel(TIME); |
| 131 | stillPlot.plot.getAxisLabels().setYLabel('bool, g\'s'); |
| 132 | stillPlot.plot.setDefaultYRange([-0.1, 1.1]); |
| 133 | |
| 134 | stillPlot.addMessageLine(localizer, ['down_estimator', 'gravity_magnitude']) |
| 135 | .setColor(WHITE) |
| 136 | .setDrawLine(false); |
| 137 | |
| 138 | // Absolute X Position |
| 139 | const xPositionPlot = aosPlotter.addPlot(element); |
| 140 | xPositionPlot.plot.getAxisLabels().setTitle('X Position'); |
| 141 | xPositionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 142 | xPositionPlot.plot.getAxisLabels().setYLabel('X Position (m)'); |
| 143 | |
| 144 | xPositionPlot.addMessageLine(status, ['x']).setColor(RED); |
| 145 | xPositionPlot.addMessageLine(localizer, ['down_estimator', 'position_x']) |
| 146 | .setColor(BLUE); |
| 147 | xPositionPlot.addMessageLine(localizer, ['state', 'x']).setColor(CYAN); |
| 148 | |
| 149 | // Absolute Y Position |
| 150 | const yPositionPlot = aosPlotter.addPlot(element); |
| 151 | yPositionPlot.plot.getAxisLabels().setTitle('Y Position'); |
| 152 | yPositionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 153 | yPositionPlot.plot.getAxisLabels().setYLabel('Y Position (m)'); |
| 154 | |
| 155 | const localizerY = yPositionPlot.addMessageLine(status, ['y']); |
| 156 | localizerY.setColor(RED); |
| 157 | yPositionPlot.addMessageLine(localizer, ['down_estimator', 'position_y']) |
| 158 | .setColor(BLUE); |
| 159 | yPositionPlot.addMessageLine(localizer, ['state', 'y']).setColor(CYAN); |
| 160 | |
| 161 | // Gyro |
| 162 | const gyroPlot = aosPlotter.addPlot(element); |
| 163 | gyroPlot.plot.getAxisLabels().setTitle('Gyro Readings'); |
| 164 | gyroPlot.plot.getAxisLabels().setYLabel('Angular Velocity (rad / sec)'); |
| 165 | gyroPlot.plot.getAxisLabels().setXLabel('Monotonic Reading Time (sec)'); |
| 166 | |
| 167 | const gyroX = gyroPlot.addMessageLine(imu, ['gyro_x']); |
| 168 | gyroX.setColor(RED); |
| 169 | const gyroY = gyroPlot.addMessageLine(imu, ['gyro_y']); |
| 170 | gyroY.setColor(GREEN); |
| 171 | const gyroZ = gyroPlot.addMessageLine(imu, ['gyro_z']); |
| 172 | gyroZ.setColor(BLUE); |
| 173 | |
| 174 | |
| 175 | const timingPlot = |
| 176 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 177 | timingPlot.plot.getAxisLabels().setTitle('Fault Counting'); |
| 178 | timingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 179 | |
| 180 | timingPlot |
| 181 | .addMessageLine( |
| 182 | localizer, ['imu', 'imu_failures', 'imu_to_pico_checksum_mismatch']) |
| 183 | .setColor(BLUE) |
| 184 | .setDrawLine(false); |
| 185 | |
| 186 | timingPlot |
| 187 | .addMessageLine( |
| 188 | localizer, ['imu', 'imu_failures', 'pico_to_pi_checksum_mismatch']) |
| 189 | .setColor(RED) |
| 190 | .setDrawLine(false); |
| 191 | |
| 192 | timingPlot |
| 193 | .addMessageLine( |
| 194 | localizer, ['imu', 'imu_failures', 'other_zeroing_faults']) |
| 195 | .setColor(CYAN) |
| 196 | .setDrawLine(false); |
| 197 | |
| 198 | timingPlot |
| 199 | .addMessageLine( |
| 200 | localizer, ['imu', 'imu_failures', 'missed_messages']) |
| 201 | .setColor(PINK) |
| 202 | .setDrawLine(false); |
| 203 | } |