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