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