blob: 9e5081dda705f466f90e8f7b718b0a4bea3847a4 [file] [log] [blame]
James Kuszmaulef35d732022-02-12 16:37:32 -08001include "frc971/control_loops/drivetrain/drivetrain_status.fbs";
James Kuszmaul9f2f53c2023-02-19 14:08:18 -08002include "frc971/imu_reader/imu_failures.fbs";
James Kuszmaulef35d732022-02-12 16:37:32 -08003
4namespace frc971.controls;
5
James Kuszmaul8c4f6592022-02-26 15:49:30 -08006enum RejectionReason : byte {
7 IMAGE_FROM_FUTURE = 0,
8 NO_CALIBRATION = 1,
9 TURRET_TOO_FAST = 2,
10 MESSAGE_BRIDGE_DISCONNECTED = 3,
James Kuszmaulaa39d962022-03-06 14:54:28 -080011 LOW_CONFIDENCE = 4,
James Kuszmaul8c4f6592022-02-26 15:49:30 -080012}
13
14table CumulativeStatistics {
15 total_accepted:int (id: 0);
16 total_candidates:int (id: 1);
17 // Indexed by integer value of RejectionReason enum.
18 rejection_reason_count:[int] (id: 2);
19}
20
James Kuszmaulef35d732022-02-12 16:37:32 -080021// Stores the state associated with the acceleration-based modelling.
22table AccelBasedState {
23 // x/y position, in meters.
24 x:double (id: 0);
25 y:double (id: 1);
26 // heading, in radians.
27 theta:double (id: 2);
28 // Velocity in X/Y directions, in m/s.
29 velocity_x:double (id: 3);
30 velocity_y:double (id: 4);
31}
32
33// Stores the state associated with the drivetrain model-based state.
34// This model assumes zero lateral motion of the drivetrain.
35table ModelBasedState {
36 // x/y position, in meters.
37 x:double (id: 0);
38 y:double (id: 1);
39 // heading, in radians.
40 theta:double (id: 2);
41 // Expected encoder reading for the left side of the drivetrain, in meters.
42 left_encoder:double (id: 3);
43 // Modelled velocity of the left side of the drivetrain, in meters / second.
44 left_velocity:double (id: 4);
45 // Estimated voltage error, in volts.
46 left_voltage_error:double (id: 5);
47 // Same as the left_* fields, but for the right side of the drivetrain.
48 right_encoder:double (id: 6);
49 right_velocity:double (id: 7);
50 right_voltage_error:double (id: 8);
51}
52
53table ModelBasedStatus {
54 // Current acceleration and model-based states. Depending on using_model,
55 // one of these will be the ground-truth and the other will be calculated
56 // based on it. E.g. if using_model is true, then model_state will be
57 // populated as you'd expect, while accel_state will be populated to be
58 // consistent with model_state (e.g., no lateral motion).
59 accel_state:AccelBasedState (id: 0);
60 model_state:ModelBasedState (id: 1);
61 // using_model indicates whether we are currently in in model-based or
62 // accelerometer-based estimation.
63 using_model:bool (id: 2);
64 // Current residual associated with the amount of inconsistency between
65 // the two models. Will be zero if the drivetrain model is perfectly
66 // consistent with the IMU readings.
67 residual:double (id: 3);
68 // Status from the down estimator.
69 down_estimator:frc971.control_loops.drivetrain.DownEstimatorState (id: 4);
70 // Current ground-truth for x/y/theta. Should match those present in *_state.
71 x:double (id: 5);
72 y:double (id: 6);
73 theta:double (id: 7);
74 // Current accelerations implied by the current accelerometer + down estimator
75 // + yaw readings.
76 implied_accel_x:double (id: 8);
77 implied_accel_y:double (id: 9);
78 implied_accel_z:double (id: 10);
79 // oldest_* are the oldest surviving branches of the model that have just been
80 // running purely on one model.
81 oldest_accel_state:AccelBasedState (id: 11);
82 oldest_model_state:ModelBasedState (id: 12);
83 // Filtered version of the residual field--this is what is actually used by
84 // the code for determining when to swap between modes.
85 filtered_residual:double (id: 13);
86 // Components of the residual. Useful for debugging.
87 velocity_residual:double (id: 14);
88 accel_residual:double (id: 15);
89 theta_rate_residual:double (id: 16);
90 // Number of times we have missed an IMU reading. Should never increase except
91 // *maybe* during startup.
92 clock_resets:int (id: 17);
James Kuszmaul8c4f6592022-02-26 15:49:30 -080093 statistics:CumulativeStatistics (id: 18);
James Kuszmaulef35d732022-02-12 16:37:32 -080094}
95
96table LocalizerStatus {
97 model_based:ModelBasedStatus (id: 0);
98 // Whether the IMU is zeroed or not.
99 zeroed:bool (id: 1);
100 // Whether the IMU zeroing is faulted or not.
101 faulted_zero:bool (id: 2);
James Kuszmaul5ed29dd2022-02-13 18:32:06 -0800102 zeroing:control_loops.drivetrain.ImuZeroerState (id: 3);
103 // Offset between the pico clock and the pi clock, such that
104 // pico_timestamp + pico_offset_ns = pi_timestamp
105 pico_offset_ns:int64 (id: 4);
106 // Error in the offset, if we assume that the pi/pico clocks are identical and
107 // that there is a perfectly consistent latency between the two. Will be zero
108 // for the very first cycle, and then referenced off of the initial offset
109 // thereafter. If greater than zero, implies that the pico is "behind",
110 // whether due to unusually large latency or due to clock drift.
111 pico_offset_error_ns:int64 (id: 5);
112 left_encoder:double (id: 6);
113 right_encoder:double (id: 7);
James Kuszmaul5f27d8b2022-03-17 09:08:26 -0700114 imu_failures:ImuFailures (id: 8);
James Kuszmaulef35d732022-02-12 16:37:32 -0800115}
116
117root_type LocalizerStatus;