blob: fe691ed69709b617709b3991c80dc7fd164f5b37 [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.
James Kuszmaul75a18c52021-03-10 22:02:07 -080057 planning_state:PlanningState (id: 0, deprecated);
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
James Kuszmaul75a18c52021-03-10 22:02:07 -080064 // The handle of the goal spline. Empty means no goal/stop requested.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080065 goal_spline_handle:int (id: 3);
James Kuszmaul75a18c52021-03-10 22:02:07 -080066 // Handle of the executing spline. Will generally be identical to
67 // goal_spline_handle if the spline is available; however, if the commanded
68 // spline has not yet been planned, this will be empty.
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.
James Kuszmaul75a18c52021-03-10 22:02:07 -080071 planning_spline_idx:int (id: 5, deprecated);
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);
James Kuszmaul75a18c52021-03-10 22:02:07 -080080
81 // Splines that we have full plans for.
82 available_splines:[int] (id: 12);
Alex Perrycb7da4b2019-08-28 19:35:56 -070083}
84
85// For logging state of the line follower.
86table LineFollowLogging {
87 // Whether we are currently freezing target choice.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080088 frozen:bool (id: 0);
Alex Perrycb7da4b2019-08-28 19:35:56 -070089 // Whether we currently have a target.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080090 have_target:bool (id: 1);
Alex Perrycb7da4b2019-08-28 19:35:56 -070091 // Absolute position of the current goal.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080092 x:float (id: 2);
93 y:float (id: 3);
94 theta:float (id: 4);
Alex Perrycb7da4b2019-08-28 19:35:56 -070095 // Current lateral offset from line pointing straight out of the target.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080096 offset:float (id: 5);
Alex Perrycb7da4b2019-08-28 19:35:56 -070097 // Current distance from the plane of the target, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -080098 distance_to_target:float (id: 6);
Alex Perrycb7da4b2019-08-28 19:35:56 -070099 // Current goal heading.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800100 goal_theta:float (id: 7);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700101 // Current relative heading.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800102 rel_theta:float (id: 8);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700103}
104
James Kuszmaul18f669c2020-02-11 16:51:06 -0800105// Current states of the EKF. See hybrid_ekf.h for detailed comments.
106table LocalizerState {
107 // X/Y field position, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800108 x:float (id: 0);
109 y:float (id: 1);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800110 // Current heading, in radians.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800111 theta:float (id: 2);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800112 // Current estimate of the left encoder position, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800113 left_encoder:float (id: 3);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800114 // Velocity of the left side of the robot.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800115 left_velocity:float (id: 4);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800116 // Current estimate of the right encoder position, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800117 right_encoder:float (id: 5);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800118 // Velocity of the right side of the robot.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800119 right_velocity:float (id: 6);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800120 // Current "voltage error" terms, in V.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800121 left_voltage_error:float (id: 7);
122 right_voltage_error:float (id: 8);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800123 // Estimate of the offset between the encoder readings and true rotation of
124 // the robot, in rad/sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800125 angular_error:float (id: 9);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800126 // Current difference between the estimated longitudinal velocity of the robot
127 // and that experienced by the wheels, in m/s.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800128 longitudinal_velocity_offset:float (id: 10);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800129 // Lateral velocity of the robot, in m/s.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800130 lateral_velocity:float (id: 11);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800131}
132
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800133table DownEstimatorState {
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800134 quaternion_x:double (id: 0);
135 quaternion_y:double (id: 1);
136 quaternion_z:double (id: 2);
137 quaternion_w:double (id: 3);
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800138
139 // Side-to-side and forwards/backwards pitch numbers. Note that we do this
140 // instead of standard roll/pitch/yaw euler angles because it was a pain to
141 // try and numerically stable roll/pitch/yaw numbers, and Eigen's interface
142 // doesn't resolve the redundancies quite how we'd like.
143 // Lateral pitch is the side-to-side pitch of the robot; longitudinal pitch is
144 // the forwards to backwards pitch of the robot; longitudinal_pitch
145 // corresponds with the traditional usage of "pitch".
146 // All angles in radians.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800147 lateral_pitch:float (id: 4);
148 longitudinal_pitch:float (id: 5);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800149 // Current yaw angle (heading) of the robot, as estimated solely by
150 // integrating the Z-axis of the gyro (in rad).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800151 yaw:float (id: 6);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800152
153 // Current position of the robot, as determined solely from the
154 // IMU/down-estimator, in meters.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800155 position_x:float (id: 7);
156 position_y:float (id: 8);
157 position_z:float (id: 9);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800158
159 // Current velocity of the robot, as determined solely from the
160 // IMU/down-estimator, in meters / sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800161 velocity_x:float (id: 10);
162 velocity_y:float (id: 11);
163 velocity_z:float (id: 12);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800164
165 // Current acceleration of the robot, with pitch/roll (but not yaw)
166 // compensated out, in meters / sec / sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800167 accel_x:float (id: 13);
168 accel_y:float (id: 14);
169 accel_z:float (id: 15);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800170
171 // Current acceleration that we expect to see from the accelerometer, assuming
172 // no acceleration other than that due to gravity, in g's.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800173 expected_accel_x:float (id: 16);
174 expected_accel_y:float (id: 17);
175 expected_accel_z:float (id: 18);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800176
177 // Current estimate of the overall acceleration due to gravity, in g's. Should
178 // generally be within ~0.003 g's of 1.0.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800179 gravity_magnitude:float (id: 19);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800180
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800181 consecutive_still:int (id: 20);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800182}
183
184table ImuZeroerState {
185 // True if we have successfully zeroed the IMU.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800186 zeroed:bool (id: 0);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800187 // True if the zeroing code has observed some inconsistency in the IMU.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800188 faulted:bool (id: 1);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800189 // Number of continuous zeroing measurements that we have accumulated for use
190 // in the zeroing.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800191 number_of_zeroes:int (id: 2);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800192
193 // Current zeroing values beind used for each gyro axis, in rad / sec.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800194 gyro_x_average:float (id: 3);
195 gyro_y_average:float (id: 4);
196 gyro_z_average:float (id: 5);
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800197}
198
Alex Perrycb7da4b2019-08-28 19:35:56 -0700199table Status {
200 // Estimated speed of the center of the robot in m/s (positive forwards).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800201 robot_speed:double (id: 0);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700202
203 // Estimated relative position of each drivetrain side (in meters).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800204 estimated_left_position:double (id: 1);
205 estimated_right_position:double (id: 2);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700206
207 // Estimated velocity of each drivetrain side (in m/s).
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800208 estimated_left_velocity:double (id: 3);
209 estimated_right_velocity:double (id: 4);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700210
211 // The voltage we wanted to send to each drivetrain side last cycle.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800212 uncapped_left_voltage:double (id: 5);
213 uncapped_right_voltage:double (id: 6);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700214
215 // The voltage error for the left and right sides.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800216 left_voltage_error:double (id: 7);
217 right_voltage_error:double (id: 8);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700218
219 // The profiled goal states.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800220 profiled_left_position_goal:double (id: 9);
221 profiled_right_position_goal:double (id: 10);
222 profiled_left_velocity_goal:double (id: 11);
223 profiled_right_velocity_goal:double (id: 12);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700224
225 // The KF offset
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800226 estimated_angular_velocity_error:double (id: 13);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700227 // The KF estimated heading.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800228 estimated_heading:double (id: 14);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700229
230 // xytheta of the robot.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800231 x:double (id: 15);
232 y:double (id: 16);
233 theta:double (id: 17);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700234
235 // True if the output voltage was capped last cycle.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800236 output_was_capped:bool (id: 18);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700237
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800238 // The pitch of the robot relative to the ground--only includes
239 // forwards/backwards rotation.
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800240 ground_angle:double (id: 19);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700241
242 // Information about shifting logic and curent gear, for logging purposes
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800243 gear_logging:GearLogging (id: 20);
244 cim_logging:CIMLogging (id: 21);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -0800245
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800246 trajectory_logging:TrajectoryLogging (id: 22);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -0800247
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800248 line_follow_logging:LineFollowLogging (id: 23);
James Kuszmaulaf5dfad2020-01-03 20:02:54 -0800249
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800250 poly_drive_logging:PolyDriveLogging (id: 24);
James Kuszmaul3e1bb272020-01-17 18:38:19 -0800251
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800252 down_estimator:DownEstimatorState (id: 25);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800253
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800254 localizer:LocalizerState (id: 26);
James Kuszmaul18f669c2020-02-11 16:51:06 -0800255
Ravago Jonesfb6a7a52020-11-14 13:47:46 -0800256 zeroing:ImuZeroerState (id: 27);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700257}
258
259root_type Status;