James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 1 | // Provides a plot for debugging drivetrain-related issues. |
Philipp Schrader | 548aedf | 2023-02-17 20:09:13 -0800 | [diff] [blame] | 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'; |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 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', 'frc971.controls.LocalizerStatus'); |
| 24 | const imu = aosPlotter.addRawMessageSource( |
James Kuszmaul | 5ed29dd | 2022-02-13 18:32:06 -0800 | [diff] [blame] | 25 | '/localizer', 'frc971.IMUValuesBatch', |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 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, ['model_based', 'model_state', 'left_encoder']) |
| 42 | .setColor(BROWN) |
| 43 | .setPointSize(0.0); |
| 44 | positionPlot |
| 45 | .addMessageLine(localizer, ['model_based', 'model_state', 'right_encoder']) |
| 46 | .setColor(CYAN) |
| 47 | .setPointSize(0.0); |
| 48 | positionPlot.addMessageLine(position, ['left_encoder']) |
| 49 | .setColor(BROWN) |
| 50 | .setDrawLine(false); |
James Kuszmaul | 5ed29dd | 2022-02-13 18:32:06 -0800 | [diff] [blame] | 51 | positionPlot.addMessageLine(imu, ['left_encoder']) |
| 52 | .setColor(BROWN) |
| 53 | .setDrawLine(false); |
| 54 | positionPlot.addMessageLine(localizer, ['left_encoder']) |
| 55 | .setColor(RED) |
| 56 | .setDrawLine(false); |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 57 | positionPlot.addMessageLine(position, ['right_encoder']) |
| 58 | .setColor(CYAN) |
| 59 | .setDrawLine(false); |
James Kuszmaul | 5ed29dd | 2022-02-13 18:32:06 -0800 | [diff] [blame] | 60 | positionPlot.addMessageLine(imu, ['right_encoder']) |
| 61 | .setColor(CYAN) |
| 62 | .setDrawLine(false); |
| 63 | positionPlot.addMessageLine(localizer, ['right_encoder']) |
| 64 | .setColor(GREEN) |
| 65 | .setDrawLine(false); |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 66 | |
| 67 | |
| 68 | // Drivetrain Velocities |
| 69 | const velocityPlot = aosPlotter.addPlot(element); |
| 70 | velocityPlot.plot.getAxisLabels().setTitle('Velocity Plots'); |
| 71 | velocityPlot.plot.getAxisLabels().setXLabel(TIME); |
| 72 | velocityPlot.plot.getAxisLabels().setYLabel('Wheel Velocity (m/s)'); |
| 73 | |
| 74 | const leftVelocity = |
| 75 | velocityPlot.addMessageLine(status, ['estimated_left_velocity']); |
| 76 | leftVelocity.setColor(RED); |
| 77 | const rightVelocity = |
| 78 | velocityPlot.addMessageLine(status, ['estimated_right_velocity']); |
| 79 | rightVelocity.setColor(GREEN); |
| 80 | |
| 81 | const leftSpeed = velocityPlot.addMessageLine(position, ["left_speed"]); |
| 82 | leftSpeed.setColor(BLUE); |
| 83 | const rightSpeed = velocityPlot.addMessageLine(position, ["right_speed"]); |
| 84 | rightSpeed.setColor(BROWN); |
| 85 | |
| 86 | const ekfLeftVelocity = velocityPlot.addMessageLine( |
| 87 | localizer, ['model_based', 'model_state', 'left_velocity']); |
| 88 | ekfLeftVelocity.setColor(RED); |
| 89 | ekfLeftVelocity.setPointSize(0.0); |
| 90 | const ekfRightVelocity = velocityPlot.addMessageLine( |
| 91 | localizer, ['model_based', 'model_state', 'right_velocity']); |
| 92 | ekfRightVelocity.setColor(GREEN); |
| 93 | ekfRightVelocity.setPointSize(0.0); |
| 94 | |
| 95 | velocityPlot |
| 96 | .addMessageLine( |
| 97 | localizer, ['model_based', 'oldest_model_state', 'left_velocity']) |
| 98 | .setColor(RED) |
| 99 | .setDrawLine(false); |
| 100 | |
| 101 | velocityPlot |
| 102 | .addMessageLine( |
| 103 | localizer, ['model_based', 'oldest_model_state', 'right_velocity']) |
| 104 | .setColor(GREEN) |
| 105 | .setDrawLine(false); |
| 106 | |
| 107 | const splineVelocityOffset = |
| 108 | velocityPlot |
| 109 | .addMessageLine(status, ['localizer', 'longitudinal_velocity_offset']) |
| 110 | .setColor(BROWN) |
| 111 | .setPointSize(0.0); |
| 112 | |
| 113 | const splineLateralVelocity = |
| 114 | velocityPlot.addMessageLine(status, ['localizer', 'lateral_velocity']) |
| 115 | .setColor(PINK) |
| 116 | .setPointSize(0.0); |
| 117 | |
| 118 | // Drivetrain Voltage |
| 119 | const voltagePlot = aosPlotter.addPlot(element); |
| 120 | voltagePlot.plot.getAxisLabels().setTitle('Voltage Plots'); |
| 121 | voltagePlot.plot.getAxisLabels().setXLabel(TIME); |
| 122 | voltagePlot.plot.getAxisLabels().setYLabel('Voltage (V)') |
| 123 | |
| 124 | voltagePlot.addMessageLine(localizer, ['model_based', 'model_state', 'left_voltage_error']) |
| 125 | .setColor(RED) |
| 126 | .setDrawLine(false); |
| 127 | voltagePlot.addMessageLine(localizer, ['model_based', 'model_state', 'right_voltage_error']) |
| 128 | .setColor(GREEN) |
| 129 | .setDrawLine(false); |
| 130 | voltagePlot.addMessageLine(output, ['left_voltage']) |
| 131 | .setColor(RED) |
| 132 | .setPointSize(0); |
| 133 | voltagePlot.addMessageLine(output, ['right_voltage']) |
| 134 | .setColor(GREEN) |
| 135 | .setPointSize(0); |
| 136 | |
| 137 | // Heading |
| 138 | const yawPlot = aosPlotter.addPlot(element); |
| 139 | yawPlot.plot.getAxisLabels().setTitle('Robot Yaw'); |
| 140 | yawPlot.plot.getAxisLabels().setXLabel(TIME); |
| 141 | yawPlot.plot.getAxisLabels().setYLabel('Yaw (rad)'); |
| 142 | |
| 143 | yawPlot.addMessageLine(status, ['localizer', 'theta']).setColor(GREEN); |
| 144 | |
| 145 | yawPlot.addMessageLine(status, ['down_estimator', 'yaw']).setColor(BLUE); |
| 146 | |
| 147 | yawPlot.addMessageLine(localizer, ['model_based', 'theta']).setColor(RED); |
| 148 | |
| 149 | // Pitch/Roll |
| 150 | const orientationPlot = aosPlotter.addPlot(element); |
| 151 | orientationPlot.plot.getAxisLabels().setTitle('Orientation'); |
| 152 | orientationPlot.plot.getAxisLabels().setXLabel(TIME); |
| 153 | orientationPlot.plot.getAxisLabels().setYLabel('Angle (rad)'); |
| 154 | |
| 155 | orientationPlot.addMessageLine(localizer, ['model_based', 'down_estimator', 'lateral_pitch']) |
| 156 | .setColor(RED) |
| 157 | .setLabel('roll'); |
| 158 | orientationPlot |
| 159 | .addMessageLine(localizer, ['model_based', 'down_estimator', 'longitudinal_pitch']) |
| 160 | .setColor(GREEN) |
| 161 | .setLabel('pitch'); |
| 162 | |
| 163 | const stillPlot = aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT / 3]); |
| 164 | stillPlot.plot.getAxisLabels().setTitle('Still Plot'); |
| 165 | stillPlot.plot.getAxisLabels().setXLabel(TIME); |
| 166 | stillPlot.plot.getAxisLabels().setYLabel('bool, g\'s'); |
| 167 | stillPlot.plot.setDefaultYRange([-0.1, 1.1]); |
| 168 | |
| 169 | stillPlot.addMessageLine(localizer, ['model_based', 'down_estimator', 'gravity_magnitude']) |
| 170 | .setColor(WHITE) |
| 171 | .setDrawLine(false); |
| 172 | stillPlot.addMessageLine(localizer, ['model_based', 'using_model']) |
| 173 | .setColor(PINK) |
| 174 | .setDrawLine(false); |
| 175 | |
| 176 | // Accelerometer/Gravity |
| 177 | const accelPlot = aosPlotter.addPlot(element); |
| 178 | accelPlot.plot.getAxisLabels().setTitle('Absoluate Velocities') |
| 179 | accelPlot.plot.getAxisLabels().setYLabel('Velocity (m/s)'); |
| 180 | accelPlot.plot.getAxisLabels().setXLabel('Monotonic Time (sec)'); |
| 181 | |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 182 | accelPlot.addMessageLine(localizer, ['model_based', 'accel_state', 'velocity_x']) |
| 183 | .setColor(RED) |
| 184 | .setDrawLine(false); |
| 185 | accelPlot.addMessageLine(localizer, ['model_based', 'accel_state', 'velocity_y']) |
| 186 | .setColor(GREEN) |
| 187 | .setDrawLine(false); |
| 188 | |
| 189 | accelPlot.addMessageLine(localizer, ['model_based', 'oldest_accel_state', 'velocity_x']) |
| 190 | .setColor(RED) |
| 191 | .setPointSize(0); |
| 192 | accelPlot.addMessageLine(localizer, ['model_based', 'oldest_accel_state', 'velocity_y']) |
| 193 | .setColor(GREEN) |
| 194 | .setPointSize(0); |
| 195 | |
| 196 | // Absolute X Position |
| 197 | const xPositionPlot = aosPlotter.addPlot(element); |
| 198 | xPositionPlot.plot.getAxisLabels().setTitle('X Position'); |
| 199 | xPositionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 200 | xPositionPlot.plot.getAxisLabels().setYLabel('X Position (m)'); |
| 201 | |
| 202 | xPositionPlot.addMessageLine(status, ['x']).setColor(RED); |
| 203 | xPositionPlot.addMessageLine(status, ['down_estimator', 'position_x']) |
| 204 | .setColor(BLUE); |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 205 | xPositionPlot.addMessageLine(localizer, ['model_based', 'x']).setColor(CYAN); |
| 206 | |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 207 | // Absolute Y Position |
| 208 | const yPositionPlot = aosPlotter.addPlot(element); |
| 209 | yPositionPlot.plot.getAxisLabels().setTitle('Y Position'); |
| 210 | yPositionPlot.plot.getAxisLabels().setXLabel(TIME); |
| 211 | yPositionPlot.plot.getAxisLabels().setYLabel('Y Position (m)'); |
| 212 | |
| 213 | const localizerY = yPositionPlot.addMessageLine(status, ['y']); |
| 214 | localizerY.setColor(RED); |
| 215 | yPositionPlot.addMessageLine(status, ['down_estimator', 'position_y']) |
| 216 | .setColor(BLUE); |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 217 | yPositionPlot.addMessageLine(localizer, ['model_based', 'y']).setColor(CYAN); |
| 218 | |
| 219 | // Gyro |
| 220 | const gyroPlot = aosPlotter.addPlot(element); |
| 221 | gyroPlot.plot.getAxisLabels().setTitle('Gyro Readings'); |
| 222 | gyroPlot.plot.getAxisLabels().setYLabel('Angular Velocity (rad / sec)'); |
| 223 | gyroPlot.plot.getAxisLabels().setXLabel('Monotonic Reading Time (sec)'); |
| 224 | |
| 225 | const gyroX = gyroPlot.addMessageLine(imu, ['gyro_x']); |
| 226 | gyroX.setColor(RED); |
| 227 | const gyroY = gyroPlot.addMessageLine(imu, ['gyro_y']); |
| 228 | gyroY.setColor(GREEN); |
| 229 | const gyroZ = gyroPlot.addMessageLine(imu, ['gyro_z']); |
| 230 | gyroZ.setColor(BLUE); |
| 231 | |
| 232 | const impliedAccelPlot = |
| 233 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 234 | impliedAccelPlot.plot.getAxisLabels().setTitle('Implied Accelerations'); |
| 235 | impliedAccelPlot.plot.getAxisLabels().setXLabel(TIME); |
| 236 | |
| 237 | impliedAccelPlot.addMessageLine(localizer, ['model_based', 'implied_accel_z']) |
| 238 | .setColor(BLUE); |
| 239 | impliedAccelPlot.addMessageLine(localizer, ['model_based', 'implied_accel_y']) |
| 240 | .setColor(GREEN); |
| 241 | impliedAccelPlot.addMessageLine(localizer, ['model_based', 'implied_accel_x']) |
| 242 | .setColor(RED); |
| 243 | |
| 244 | const costPlot = |
| 245 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
| 246 | costPlot.plot.getAxisLabels().setTitle('Costs'); |
| 247 | costPlot.plot.getAxisLabels().setXLabel(TIME); |
| 248 | |
| 249 | costPlot.addMessageLine(localizer, ['model_based', 'residual']) |
| 250 | .setColor(RED) |
| 251 | .setPointSize(0); |
| 252 | |
| 253 | costPlot.addMessageLine(localizer, ['model_based', 'filtered_residual']) |
| 254 | .setColor(BLUE) |
| 255 | .setPointSize(0); |
| 256 | |
| 257 | costPlot.addMessageLine(localizer, ['model_based', 'velocity_residual']) |
| 258 | .setColor(GREEN) |
| 259 | .setPointSize(0); |
| 260 | |
| 261 | costPlot.addMessageLine(localizer, ['model_based', 'theta_rate_residual']) |
| 262 | .setColor(BROWN) |
| 263 | .setPointSize(0); |
| 264 | |
| 265 | costPlot.addMessageLine(localizer, ['model_based', 'accel_residual']) |
| 266 | .setColor(CYAN) |
| 267 | .setPointSize(0); |
James Kuszmaul | 5ed29dd | 2022-02-13 18:32:06 -0800 | [diff] [blame] | 268 | |
| 269 | const timingPlot = |
| 270 | aosPlotter.addPlot(element, [DEFAULT_WIDTH, DEFAULT_HEIGHT]); |
James Kuszmaul | 5f27d8b | 2022-03-17 09:08:26 -0700 | [diff] [blame] | 271 | timingPlot.plot.getAxisLabels().setTitle('Fault Counting'); |
James Kuszmaul | 5ed29dd | 2022-02-13 18:32:06 -0800 | [diff] [blame] | 272 | timingPlot.plot.getAxisLabels().setXLabel(TIME); |
| 273 | |
| 274 | timingPlot.addMessageLine(localizer, ['model_based', 'clock_resets']) |
| 275 | .setColor(GREEN) |
| 276 | .setDrawLine(false); |
James Kuszmaul | 5f27d8b | 2022-03-17 09:08:26 -0700 | [diff] [blame] | 277 | |
| 278 | timingPlot |
| 279 | .addMessageLine( |
| 280 | localizer, ['imu_failures', 'imu_to_pico_checksum_mismatch']) |
| 281 | .setColor(BLUE) |
| 282 | .setDrawLine(false); |
| 283 | |
| 284 | timingPlot |
| 285 | .addMessageLine( |
| 286 | localizer, ['imu_failures', 'pico_to_pi_checksum_mismatch']) |
| 287 | .setColor(RED) |
| 288 | .setDrawLine(false); |
| 289 | |
| 290 | timingPlot |
| 291 | .addMessageLine( |
| 292 | localizer, ['imu_failures', 'other_zeroing_faults']) |
| 293 | .setColor(CYAN) |
| 294 | .setDrawLine(false); |
| 295 | |
| 296 | timingPlot |
| 297 | .addMessageLine( |
| 298 | localizer, ['imu_failures', 'missed_messages']) |
| 299 | .setColor(PINK) |
| 300 | .setDrawLine(false); |
James Kuszmaul | f7c8a09 | 2022-02-12 16:46:09 -0800 | [diff] [blame] | 301 | } |