James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 1 | // Provides a basic plot for debugging IMU-related issues on a robot. |
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'; |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 5 | |
| 6 | import Connection = proxy.Connection; |
| 7 | |
| 8 | export function plotImu(conn: Connection, element: Element): void { |
| 9 | const width = 900; |
| 10 | const height = 400; |
| 11 | const aosPlotter = new AosPlotter(conn); |
| 12 | |
Austin Schuh | c2e9c50 | 2021-11-25 21:23:24 -0800 | [diff] [blame] | 13 | const accelPlot = aosPlotter.addPlot(element, [width, height]); |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 14 | accelPlot.plot.getAxisLabels().setTitle('Accelerometer Readings'); |
| 15 | accelPlot.plot.getAxisLabels().setYLabel('Acceleration (g)'); |
| 16 | accelPlot.plot.getAxisLabels().setXLabel('Monotonic Reading Time (sec)'); |
| 17 | |
| 18 | const drivetrainStatus = aosPlotter.addMessageSource( |
| 19 | '/drivetrain', 'frc971.control_loops.drivetrain.Status'); |
| 20 | |
| 21 | const imu = aosPlotter.addRawMessageSource( |
James Kuszmaul | 207ae32 | 2022-02-25 21:15:31 -0800 | [diff] [blame] | 22 | '/localizer', 'frc971.IMUValuesBatch', |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 23 | new ImuMessageHandler(conn.getSchema('frc971.IMUValuesBatch'))); |
| 24 | |
| 25 | const accelX = accelPlot.addMessageLine(imu, ['accelerometer_x']); |
| 26 | accelX.setColor([1, 0, 0]); |
| 27 | const accelY = accelPlot.addMessageLine(imu, ['accelerometer_y']); |
| 28 | accelY.setColor([0, 1, 0]); |
| 29 | const accelZ = accelPlot.addMessageLine(imu, ['accelerometer_z']); |
| 30 | accelZ.setColor([0, 0, 1]); |
| 31 | |
Austin Schuh | c2e9c50 | 2021-11-25 21:23:24 -0800 | [diff] [blame] | 32 | const gyroPlot = aosPlotter.addPlot(element, [width, height]); |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 33 | gyroPlot.plot.getAxisLabels().setTitle('Gyro Readings'); |
| 34 | gyroPlot.plot.getAxisLabels().setYLabel('Angular Velocity (rad / sec)'); |
| 35 | gyroPlot.plot.getAxisLabels().setXLabel('Monotonic Reading Time (sec)'); |
| 36 | |
| 37 | const gyroZeroX = |
| 38 | gyroPlot.addMessageLine(drivetrainStatus, ['zeroing', 'gyro_x_average']); |
| 39 | gyroZeroX.setColor([1, 0, 0]); |
| 40 | gyroZeroX.setPointSize(0); |
| 41 | gyroZeroX.setLabel('Gyro X Zero'); |
| 42 | const gyroZeroY = |
| 43 | gyroPlot.addMessageLine(drivetrainStatus, ['zeroing', 'gyro_y_average']); |
| 44 | gyroZeroY.setColor([0, 1, 0]); |
| 45 | gyroZeroY.setPointSize(0); |
| 46 | gyroZeroY.setLabel('Gyro Y Zero'); |
| 47 | const gyroZeroZ = |
| 48 | gyroPlot.addMessageLine(drivetrainStatus, ['zeroing', 'gyro_z_average']); |
| 49 | gyroZeroZ.setColor([0, 0, 1]); |
| 50 | gyroZeroZ.setPointSize(0); |
| 51 | gyroZeroZ.setLabel('Gyro Z Zero'); |
| 52 | |
| 53 | const gyroX = gyroPlot.addMessageLine(imu, ['gyro_x']); |
| 54 | gyroX.setColor([1, 0, 0]); |
| 55 | const gyroY = gyroPlot.addMessageLine(imu, ['gyro_y']); |
| 56 | gyroY.setColor([0, 1, 0]); |
| 57 | const gyroZ = gyroPlot.addMessageLine(imu, ['gyro_z']); |
| 58 | gyroZ.setColor([0, 0, 1]); |
| 59 | |
Austin Schuh | c2e9c50 | 2021-11-25 21:23:24 -0800 | [diff] [blame] | 60 | const tempPlot = aosPlotter.addPlot(element, [width, height / 2]); |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 61 | tempPlot.plot.getAxisLabels().setTitle('IMU Temperature'); |
| 62 | tempPlot.plot.getAxisLabels().setYLabel('Temperature (deg C)'); |
| 63 | tempPlot.plot.getAxisLabels().setXLabel('Monotonic Reading Time (sec)'); |
| 64 | |
| 65 | tempPlot.addMessageLine(imu, ['temperature']); |
| 66 | |
Austin Schuh | c2e9c50 | 2021-11-25 21:23:24 -0800 | [diff] [blame] | 67 | const statePlot = aosPlotter.addPlot(element, [width, height / 2]); |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 68 | statePlot.plot.getAxisLabels().setTitle('IMU State'); |
| 69 | statePlot.plot.getAxisLabels().setXLabel('Monotonic Sent Time (sec)'); |
| 70 | statePlot.plot.setDefaultYRange([-0.1, 1.1]); |
| 71 | |
| 72 | const zeroedLine = |
| 73 | statePlot.addMessageLine(drivetrainStatus, ['zeroing', 'zeroed']); |
| 74 | zeroedLine.setColor([1, 0, 0]); |
| 75 | zeroedLine.setDrawLine(false); |
| 76 | const faultedLine = |
| 77 | statePlot.addMessageLine(drivetrainStatus, ['zeroing', 'faulted']); |
| 78 | faultedLine.setColor([0, 1, 0]); |
| 79 | faultedLine.setPointSize(0); |
| 80 | } |