James Kuszmaul | 827a6d6 | 2023-03-26 12:40:29 -0700 | [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', 'y2023.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 |
| 41 | .addMessageLine(localizer, ['imu', 'left_encoder']) |
| 42 | .setColor(BROWN) |
| 43 | .setPointSize(0.0); |
| 44 | positionPlot |
| 45 | .addMessageLine(localizer, ['imu', 'right_encoder']) |
| 46 | .setColor(CYAN) |
| 47 | .setPointSize(0.0); |
| 48 | positionPlot.addMessageLine(position, ['left_encoder']) |
| 49 | .setColor(BROWN) |
| 50 | .setDrawLine(false); |
| 51 | positionPlot.addMessageLine(imu, ['left_encoder']) |
| 52 | .setColor(BROWN) |
| 53 | .setDrawLine(false); |
| 54 | positionPlot.addMessageLine(position, ['right_encoder']) |
| 55 | .setColor(CYAN) |
| 56 | .setDrawLine(false); |
| 57 | positionPlot.addMessageLine(imu, ['right_encoder']) |
| 58 | .setColor(CYAN) |
| 59 | .setDrawLine(false); |
| 60 | |
| 61 | |
| 62 | // Drivetrain Velocities |
| 63 | const velocityPlot = aosPlotter.addPlot(element); |
| 64 | velocityPlot.plot.getAxisLabels().setTitle('Velocity Plots'); |
| 65 | velocityPlot.plot.getAxisLabels().setXLabel(TIME); |
| 66 | velocityPlot.plot.getAxisLabels().setYLabel('Wheel Velocity (m/s)'); |
| 67 | |
| 68 | const leftVelocity = |
| 69 | velocityPlot.addMessageLine(status, ['estimated_left_velocity']); |
| 70 | leftVelocity.setColor(RED); |
| 71 | const rightVelocity = |
| 72 | velocityPlot.addMessageLine(status, ['estimated_right_velocity']); |
| 73 | rightVelocity.setColor(GREEN); |
| 74 | |
| 75 | const leftSpeed = velocityPlot.addMessageLine(position, ["left_speed"]); |
| 76 | leftSpeed.setColor(BLUE); |
| 77 | const rightSpeed = velocityPlot.addMessageLine(position, ["right_speed"]); |
| 78 | rightSpeed.setColor(BROWN); |
| 79 | |
| 80 | const ekfLeftVelocity = velocityPlot.addMessageLine( |
| 81 | localizer, ['state', 'left_velocity']); |
| 82 | ekfLeftVelocity.setColor(RED); |
| 83 | ekfLeftVelocity.setPointSize(0.0); |
| 84 | const ekfRightVelocity = velocityPlot.addMessageLine( |
| 85 | localizer, ['state', 'right_velocity']); |
| 86 | ekfRightVelocity.setColor(GREEN); |
| 87 | ekfRightVelocity.setPointSize(0.0); |
| 88 | |
| 89 | // Lateral velocity |
| 90 | const lateralPlot = aosPlotter.addPlot(element); |
| 91 | lateralPlot.plot.getAxisLabels().setTitle('Lateral Velocity'); |
| 92 | lateralPlot.plot.getAxisLabels().setXLabel(TIME); |
| 93 | lateralPlot.plot.getAxisLabels().setYLabel('Velocity (m/s)'); |
| 94 | |
| 95 | lateralPlot.addMessageLine(localizer, ['state', 'lateral_velocity']).setColor(CYAN); |
| 96 | |
| 97 | // Drivetrain Voltage |
| 98 | const voltagePlot = aosPlotter.addPlot(element); |
| 99 | voltagePlot.plot.getAxisLabels().setTitle('Voltage Plots'); |
| 100 | voltagePlot.plot.getAxisLabels().setXLabel(TIME); |
| 101 | voltagePlot.plot.getAxisLabels().setYLabel('Voltage (V)') |
| 102 | |
| 103 | voltagePlot.addMessageLine(localizer, ['state', 'left_voltage_error']) |
| 104 | .setColor(RED) |
| 105 | .setDrawLine(false); |
| 106 | voltagePlot.addMessageLine(localizer, ['state', 'right_voltage_error']) |
| 107 | .setColor(GREEN) |
| 108 | .setDrawLine(false); |
| 109 | voltagePlot.addMessageLine(output, ['left_voltage']) |
| 110 | .setColor(RED) |
| 111 | .setPointSize(0); |
| 112 | voltagePlot.addMessageLine(output, ['right_voltage']) |
| 113 | .setColor(GREEN) |
| 114 | .setPointSize(0); |
| 115 | |
| 116 | // Heading |
| 117 | const yawPlot = aosPlotter.addPlot(element); |
| 118 | yawPlot.plot.getAxisLabels().setTitle('Robot Yaw'); |
| 119 | yawPlot.plot.getAxisLabels().setXLabel(TIME); |
| 120 | yawPlot.plot.getAxisLabels().setYLabel('Yaw (rad)'); |
| 121 | |
| 122 | yawPlot.addMessageLine(status, ['localizer', 'theta']).setColor(GREEN); |
| 123 | |
| 124 | yawPlot.addMessageLine(localizer, ['down_estimator', 'yaw']).setColor(BLUE); |
| 125 | |
| 126 | yawPlot.addMessageLine(localizer, ['state', 'theta']).setColor(RED); |
| 127 | |
| 128 | // Pitch/Roll |
| 129 | const orientationPlot = aosPlotter.addPlot(element); |
| 130 | orientationPlot.plot.getAxisLabels().setTitle('Orientation'); |
| 131 | orientationPlot.plot.getAxisLabels().setXLabel(TIME); |
| 132 | orientationPlot.plot.getAxisLabels().setYLabel('Angle (rad)'); |
| 133 | |
| 134 | orientationPlot.addMessageLine(localizer, ['down_estimator', 'lateral_pitch']) |
| 135 | .setColor(RED) |
| 136 | .setLabel('roll'); |
| 137 | orientationPlot |
| 138 | .addMessageLine(localizer, ['down_estimator', 'longitudinal_pitch']) |
| 139 | .setColor(GREEN) |
| 140 | .setLabel('pitch'); |
| 141 | |
| 142 | const stillPlot = aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 3]); |
| 143 | stillPlot.plot.getAxisLabels().setTitle('Still Plot'); |
| 144 | stillPlot.plot.getAxisLabels().setXLabel(TIME); |
| 145 | stillPlot.plot.getAxisLabels().setYLabel('bool, g\'s'); |
| 146 | stillPlot.plot.setDefaultYRange([-0.1, 1.1]); |
| 147 | |
| 148 | stillPlot.addMessageLine(localizer, ['down_estimator', 'gravity_magnitude']) |
| 149 | .setColor(WHITE) |
| 150 | .setDrawLine(false); |
| 151 | |
| 152 | // Absolute X Position |
| 153 | const xPositionPlot = aosPlotter.addPlot(element); |
| 154 | xPositionPlot.plot.getAxisLabels().setTitle('X Position'); |
| 155 | xPositionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 156 | xPositionPlot.plot.getAxisLabels().setYLabel('X Position (m)'); |
| 157 | |
| 158 | xPositionPlot.addMessageLine(status, ['x']).setColor(RED); |
| 159 | xPositionPlot.addMessageLine(localizer, ['down_estimator', 'position_x']) |
| 160 | .setColor(BLUE); |
| 161 | xPositionPlot.addMessageLine(localizer, ['state', 'x']).setColor(CYAN); |
| 162 | |
| 163 | // Absolute Y Position |
| 164 | const yPositionPlot = aosPlotter.addPlot(element); |
| 165 | yPositionPlot.plot.getAxisLabels().setTitle('Y Position'); |
| 166 | yPositionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 167 | yPositionPlot.plot.getAxisLabels().setYLabel('Y Position (m)'); |
| 168 | |
| 169 | const localizerY = yPositionPlot.addMessageLine(status, ['y']); |
| 170 | localizerY.setColor(RED); |
| 171 | yPositionPlot.addMessageLine(localizer, ['down_estimator', 'position_y']) |
| 172 | .setColor(BLUE); |
| 173 | yPositionPlot.addMessageLine(localizer, ['state', 'y']).setColor(CYAN); |
| 174 | |
| 175 | // Gyro |
| 176 | const gyroPlot = aosPlotter.addPlot(element); |
| 177 | gyroPlot.plot.getAxisLabels().setTitle('Gyro Readings'); |
| 178 | gyroPlot.plot.getAxisLabels().setYLabel('Angular Velocity (rad / sec)'); |
| 179 | gyroPlot.plot.getAxisLabels().setXLabel('Monotonic Reading Time (sec)'); |
| 180 | |
| 181 | const gyroX = gyroPlot.addMessageLine(imu, ['gyro_x']); |
| 182 | gyroX.setColor(RED); |
| 183 | const gyroY = gyroPlot.addMessageLine(imu, ['gyro_y']); |
| 184 | gyroY.setColor(GREEN); |
| 185 | const gyroZ = gyroPlot.addMessageLine(imu, ['gyro_z']); |
| 186 | gyroZ.setColor(BLUE); |
| 187 | |
| 188 | |
| 189 | const timingPlot = |
| 190 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 191 | timingPlot.plot.getAxisLabels().setTitle('Fault Counting'); |
| 192 | timingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 193 | |
| 194 | timingPlot |
| 195 | .addMessageLine( |
| 196 | localizer, ['imu', 'imu_failures', 'imu_to_pico_checksum_mismatch']) |
| 197 | .setColor(BLUE) |
| 198 | .setDrawLine(false); |
| 199 | |
| 200 | timingPlot |
| 201 | .addMessageLine( |
| 202 | localizer, ['imu', 'imu_failures', 'pico_to_pi_checksum_mismatch']) |
| 203 | .setColor(RED) |
| 204 | .setDrawLine(false); |
| 205 | |
| 206 | timingPlot |
| 207 | .addMessageLine( |
| 208 | localizer, ['imu', 'imu_failures', 'other_zeroing_faults']) |
| 209 | .setColor(CYAN) |
| 210 | .setDrawLine(false); |
| 211 | |
| 212 | timingPlot |
| 213 | .addMessageLine( |
| 214 | localizer, ['imu', 'imu_failures', 'missed_messages']) |
| 215 | .setColor(PINK) |
| 216 | .setDrawLine(false); |
| 217 | } |