blob: 5ce14e6ae3334a4ae8e234153ab378315e8841f5 [file] [log] [blame]
Alex Perrycb7da4b2019-08-28 19:35:56 -07001include "frc971/control_loops/control_loops.fbs";
2
3namespace frc971.control_loops.drivetrain;
4
5// For logging information about what the code is doing with the shifters.
6table GearLogging {
7 // Which controller is being used.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -08008 controller_index:byte (id: 0);
Alex Perrycb7da4b2019-08-28 19:35:56 -07009
10 // Whether each loop for the drivetrain sides is the high-gear one.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080011 left_loop_high:bool (id: 1);
12 right_loop_high:bool (id: 2);
Alex Perrycb7da4b2019-08-28 19:35:56 -070013
14 // The states of each drivetrain shifter.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080015 left_state:byte (id: 3);
16 right_state:byte (id: 4);
Alex Perrycb7da4b2019-08-28 19:35:56 -070017}
18
19// For logging information about the state of the shifters.
20table CIMLogging {
21 // Whether the code thinks each drivetrain side is currently in gear.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080022 left_in_gear:bool (id: 0);
23 right_in_gear:bool (id: 1);
Alex Perrycb7da4b2019-08-28 19:35:56 -070024
25 // The angular velocities (in rad/s, positive forward) the code thinks motors
26 // on each side of the drivetrain are moving at.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080027 left_motor_speed:double (id: 2);
28 right_motor_speed:double (id: 3);
Alex Perrycb7da4b2019-08-28 19:35:56 -070029
30 // The velocity estimates for each drivetrain side of the robot (in m/s,
31 // positive forward) that can be used for shifting.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080032 left_velocity:double (id: 4);
33 right_velocity:double (id: 5);
Alex Perrycb7da4b2019-08-28 19:35:56 -070034}
35
James Kuszmaulaf5dfad2020-01-03 20:02:54 -080036// Logging information for the polydrivetrain implementation.
37table PolyDriveLogging {
38 // Calculated velocity goals for the left/right sides of the drivetrain, in
39 // m/s.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080040 goal_left_velocity:float (id: 0);
41 goal_right_velocity:float (id: 1);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -080042 // Feedforward components of the left/right voltages.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080043 ff_left_voltage:float (id: 2);
44 ff_right_voltage:float (id: 3);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -080045}
46
Alex Perrycb7da4b2019-08-28 19:35:56 -070047enum PlanningState : byte {
48 NO_PLAN,
49 BUILDING_TRAJECTORY,
50 PLANNING_TRAJECTORY,
51 PLANNED,
52}
53
54// For logging information about the state of the trajectory planning.
55table TrajectoryLogging {
56 // state of planning the trajectory.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080057 planning_state:PlanningState (id: 0);
Alex Perrycb7da4b2019-08-28 19:35:56 -070058
59 // State of the spline execution.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080060 is_executing:bool (id: 1);
Alex Perrycb7da4b2019-08-28 19:35:56 -070061 // Whether we have finished the spline specified by current_spline_idx.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080062 is_executed:bool (id: 2);
Alex Perrycb7da4b2019-08-28 19:35:56 -070063
64 // The handle of the goal spline. 0 means stop requested.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080065 goal_spline_handle:int (id: 3);
Alex Perrycb7da4b2019-08-28 19:35:56 -070066 // Handle of the executing spline. -1 means none requested. If there was no
67 // spline executing when a spline finished optimizing, it will become the
68 // current spline even if we aren't ready to start yet.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080069 current_spline_idx:int (id: 4);
Alex Perrycb7da4b2019-08-28 19:35:56 -070070 // Handle of the spline that is being optimized and staged.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080071 planning_spline_idx:int (id: 5);
Alex Perrycb7da4b2019-08-28 19:35:56 -070072
73 // Expected position and velocity on the spline
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080074 x:float (id: 6);
75 y:float (id: 7);
76 theta:float (id: 8);
77 left_velocity:float (id: 9);
78 right_velocity:float (id: 10);
79 distance_remaining:float (id: 11);
Alex Perrycb7da4b2019-08-28 19:35:56 -070080}
81
82// For logging state of the line follower.
83table LineFollowLogging {
84 // Whether we are currently freezing target choice.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080085 frozen:bool (id: 0);
Alex Perrycb7da4b2019-08-28 19:35:56 -070086 // Whether we currently have a target.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080087 have_target:bool (id: 1);
Alex Perrycb7da4b2019-08-28 19:35:56 -070088 // Absolute position of the current goal.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080089 x:float (id: 2);
90 y:float (id: 3);
91 theta:float (id: 4);
Alex Perrycb7da4b2019-08-28 19:35:56 -070092 // Current lateral offset from line pointing straight out of the target.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080093 offset:float (id: 5);
Alex Perrycb7da4b2019-08-28 19:35:56 -070094 // Current distance from the plane of the target, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080095 distance_to_target:float (id: 6);
Alex Perrycb7da4b2019-08-28 19:35:56 -070096 // Current goal heading.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080097 goal_theta:float (id: 7);
Alex Perrycb7da4b2019-08-28 19:35:56 -070098 // Current relative heading.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080099 rel_theta:float (id: 8);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700100}
101
James Kuszmaul18f669c2020-02-11 16:51:06 -0800102// Current states of the EKF. See hybrid_ekf.h for detailed comments.
103table LocalizerState {
104 // X/Y field position, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800105 x:float (id: 0);
106 y:float (id: 1);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800107 // Current heading, in radians.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800108 theta:float (id: 2);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800109 // Current estimate of the left encoder position, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800110 left_encoder:float (id: 3);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800111 // Velocity of the left side of the robot.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800112 left_velocity:float (id: 4);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800113 // Current estimate of the right encoder position, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800114 right_encoder:float (id: 5);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800115 // Velocity of the right side of the robot.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800116 right_velocity:float (id: 6);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800117 // Current "voltage error" terms, in V.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800118 left_voltage_error:float (id: 7);
119 right_voltage_error:float (id: 8);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800120 // Estimate of the offset between the encoder readings and true rotation of
121 // the robot, in rad/sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800122 angular_error:float (id: 9);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800123 // Current difference between the estimated longitudinal velocity of the robot
124 // and that experienced by the wheels, in m/s.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800125 longitudinal_velocity_offset:float (id: 10);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800126 // Lateral velocity of the robot, in m/s.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800127 lateral_velocity:float (id: 11);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800128}
129
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800130table DownEstimatorState {
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800131 quaternion_x:double (id: 0);
132 quaternion_y:double (id: 1);
133 quaternion_z:double (id: 2);
134 quaternion_w:double (id: 3);
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800135
136 // Side-to-side and forwards/backwards pitch numbers. Note that we do this
137 // instead of standard roll/pitch/yaw euler angles because it was a pain to
138 // try and numerically stable roll/pitch/yaw numbers, and Eigen's interface
139 // doesn't resolve the redundancies quite how we'd like.
140 // Lateral pitch is the side-to-side pitch of the robot; longitudinal pitch is
141 // the forwards to backwards pitch of the robot; longitudinal_pitch
142 // corresponds with the traditional usage of "pitch".
143 // All angles in radians.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800144 lateral_pitch:float (id: 4);
145 longitudinal_pitch:float (id: 5);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800146 // Current yaw angle (heading) of the robot, as estimated solely by
147 // integrating the Z-axis of the gyro (in rad).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800148 yaw:float (id: 6);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800149
150 // Current position of the robot, as determined solely from the
151 // IMU/down-estimator, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800152 position_x:float (id: 7);
153 position_y:float (id: 8);
154 position_z:float (id: 9);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800155
156 // Current velocity of the robot, as determined solely from the
157 // IMU/down-estimator, in meters / sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800158 velocity_x:float (id: 10);
159 velocity_y:float (id: 11);
160 velocity_z:float (id: 12);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800161
162 // Current acceleration of the robot, with pitch/roll (but not yaw)
163 // compensated out, in meters / sec / sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800164 accel_x:float (id: 13);
165 accel_y:float (id: 14);
166 accel_z:float (id: 15);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800167
168 // Current acceleration that we expect to see from the accelerometer, assuming
169 // no acceleration other than that due to gravity, in g's.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800170 expected_accel_x:float (id: 16);
171 expected_accel_y:float (id: 17);
172 expected_accel_z:float (id: 18);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800173
174 // Current estimate of the overall acceleration due to gravity, in g's. Should
175 // generally be within ~0.003 g's of 1.0.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800176 gravity_magnitude:float (id: 19);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800177
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800178 consecutive_still:int (id: 20);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800179}
180
181table ImuZeroerState {
182 // True if we have successfully zeroed the IMU.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800183 zeroed:bool (id: 0);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800184 // True if the zeroing code has observed some inconsistency in the IMU.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800185 faulted:bool (id: 1);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800186 // Number of continuous zeroing measurements that we have accumulated for use
187 // in the zeroing.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800188 number_of_zeroes:int (id: 2);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800189
190 // Current zeroing values beind used for each gyro axis, in rad / sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800191 gyro_x_average:float (id: 3);
192 gyro_y_average:float (id: 4);
193 gyro_z_average:float (id: 5);
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800194}
195
Alex Perrycb7da4b2019-08-28 19:35:56 -0700196table Status {
197 // Estimated speed of the center of the robot in m/s (positive forwards).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800198 robot_speed:double (id: 0);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700199
200 // Estimated relative position of each drivetrain side (in meters).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800201 estimated_left_position:double (id: 1);
202 estimated_right_position:double (id: 2);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700203
204 // Estimated velocity of each drivetrain side (in m/s).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800205 estimated_left_velocity:double (id: 3);
206 estimated_right_velocity:double (id: 4);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700207
208 // The voltage we wanted to send to each drivetrain side last cycle.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800209 uncapped_left_voltage:double (id: 5);
210 uncapped_right_voltage:double (id: 6);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700211
212 // The voltage error for the left and right sides.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800213 left_voltage_error:double (id: 7);
214 right_voltage_error:double (id: 8);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700215
216 // The profiled goal states.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800217 profiled_left_position_goal:double (id: 9);
218 profiled_right_position_goal:double (id: 10);
219 profiled_left_velocity_goal:double (id: 11);
220 profiled_right_velocity_goal:double (id: 12);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700221
222 // The KF offset
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800223 estimated_angular_velocity_error:double (id: 13);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700224 // The KF estimated heading.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800225 estimated_heading:double (id: 14);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700226
227 // xytheta of the robot.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800228 x:double (id: 15);
229 y:double (id: 16);
230 theta:double (id: 17);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700231
232 // True if the output voltage was capped last cycle.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800233 output_was_capped:bool (id: 18);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700234
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800235 // The pitch of the robot relative to the ground--only includes
236 // forwards/backwards rotation.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800237 ground_angle:double (id: 19);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700238
239 // Information about shifting logic and curent gear, for logging purposes
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800240 gear_logging:GearLogging (id: 20);
241 cim_logging:CIMLogging (id: 21);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -0800242
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800243 trajectory_logging:TrajectoryLogging (id: 22);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -0800244
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800245 line_follow_logging:LineFollowLogging (id: 23);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -0800246
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800247 poly_drive_logging:PolyDriveLogging (id: 24);
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800248
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800249 down_estimator:DownEstimatorState (id: 25);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800250
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800251 localizer:LocalizerState (id: 26);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800252
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800253 zeroing:ImuZeroerState (id: 27);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700254}
255
256root_type Status;