blob: bac9051560a37eb7dca61d930fdeef95f7b465f4 [file] [log] [blame]
Campbell Crowley75026292017-02-04 21:46:19 -08001package y2017.control_loops;
2
3import "aos/common/controls/control_loops.q";
Austin Schuh3634ed32017-02-05 16:28:49 -08004import "frc971/control_loops/profiled_subsystem.q";
5// TODO(austin): Add this back in when the queue compiler supports diamond
6// inheritance.
7//import "frc971/control_loops/control_loops.q";
Campbell Crowley75026292017-02-04 21:46:19 -08008
9struct IntakeGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080010 // Zero for the intake is when the front tube is tangent with the front of the
11 // frame. Positive is out.
Campbell Crowley75026292017-02-04 21:46:19 -080012
13 // Goal distance of the intake.
14 double distance;
15
16 // Caps on velocity/acceleration for profiling. 0 for the default.
17 .frc971.ProfileParameters profile_params;
18
19 // Voltage to send to the rollers. Positive is sucking in.
Austin Schuh0991edb2017-02-05 17:16:44 -080020 double voltage_rollers;
Austin Schuhd5ccb862017-03-11 22:06:36 -080021
22 // If true, disable the intake so we can hang.
23 bool disable_intake;
Austin Schuh6a8131b2017-04-08 15:39:22 -070024
25 // The gear servo value.
26 double gear_servo;
Campbell Crowley75026292017-02-04 21:46:19 -080027};
28
Brian Silverman052e69d2017-02-12 16:19:55 -080029struct IndexerGoal {
30 // Indexer angular velocity goals in radians/second.
Campbell Crowley75026292017-02-04 21:46:19 -080031 double angular_velocity;
Campbell Crowley651c4b42017-02-17 22:30:50 -080032
33 // Roller voltage. Positive is sucking in.
34 double voltage_rollers;
Campbell Crowley75026292017-02-04 21:46:19 -080035};
36
37struct TurretGoal {
Campbell Crowley065a0812017-02-04 22:27:17 -080038 // An angle of zero means the turrent faces toward the front of the
Campbell Crowley75026292017-02-04 21:46:19 -080039 // robot where the intake is located. The angle increases when the turret
Campbell Crowley065a0812017-02-04 22:27:17 -080040 // turns clockwise (towards right from the front), and decreases when
41 // the turrent turns counter-clockwise (towards left from the front).
Campbell Crowley75026292017-02-04 21:46:19 -080042 // These are from a top view above the robot.
Campbell Crowley065a0812017-02-04 22:27:17 -080043 double angle;
Campbell Crowley75026292017-02-04 21:46:19 -080044
Austin Schuhac76bb32017-03-22 22:34:26 -070045 // If true, ignore the angle and track using vision. If we don't see
46 // anything, we'll use the turret goal above.
47 bool track;
48
Campbell Crowley75026292017-02-04 21:46:19 -080049 // Caps on velocity/acceleration for profiling. 0 for the default.
50 .frc971.ProfileParameters profile_params;
51};
52
53struct HoodGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080054 // Angle the hood is currently at. An angle of zero is at the lower hard
55 // stop, angle increases as hood rises.
Austin Schuh0991edb2017-02-05 17:16:44 -080056 double angle;
Campbell Crowley75026292017-02-04 21:46:19 -080057
58 // Caps on velocity/acceleration for profiling. 0 for the default.
59 .frc971.ProfileParameters profile_params;
60};
61
62struct ShooterGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080063 // Angular velocity goals in radians/second. Positive is shooting out of the
64 // robot.
Campbell Crowley75026292017-02-04 21:46:19 -080065 double angular_velocity;
66};
67
Brian Silverman052e69d2017-02-12 16:19:55 -080068struct IndexerStatus {
69 // The current average velocity in radians/second. Positive is moving balls up
70 // towards the shooter. This is the angular velocity of the inner piece.
Campbell Crowley75026292017-02-04 21:46:19 -080071 double avg_angular_velocity;
72
73 // The current instantaneous filtered velocity in radians/second.
74 double angular_velocity;
75
Brian Silverman052e69d2017-02-12 16:19:55 -080076 // True if the indexer is ready. It is better to compare the velocities
Campbell Crowley75026292017-02-04 21:46:19 -080077 // directly so there isn't confusion on if the goal is up to date.
78 bool ready;
79
Austin Schuhcd3237a2017-02-18 14:19:26 -080080 // True if the indexer is stuck.
81 bool stuck;
Austin Schuha4dd26d2017-02-24 19:14:39 -080082 float stuck_voltage;
Austin Schuhcd3237a2017-02-18 14:19:26 -080083
84 // The state of the indexer state machine.
85 int32_t state;
86
87 // The estimated voltage error from the kalman filter in volts.
88 double voltage_error;
89 // The estimated voltage error from the stuck indexer kalman filter.
90 double stuck_voltage_error;
91
92 // The current velocity measured as delta x / delta t in radians/sec.
93 double instantaneous_velocity;
94
95 // The error between our measurement and expected measurement in radians.
96 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -080097};
98
Campbell Crowley75026292017-02-04 21:46:19 -080099struct ShooterStatus {
100 // The current average velocity in radians/second.
101 double avg_angular_velocity;
102
103 // The current instantaneous filtered velocity in radians/second.
104 double angular_velocity;
105
106 // True if the shooter is ready. It is better to compare the velocities
107 // directly so there isn't confusion on if the goal is up to date.
108 bool ready;
109
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800110 // The estimated voltage error from the kalman filter in volts.
111 double voltage_error;
112
113 // The current velocity measured as delta x / delta t in radians/sec.
114 double instantaneous_velocity;
Austin Schuheb5c22e2017-04-09 18:30:28 -0700115 double filtered_velocity;
Austin Schuh932a5ce2017-03-05 01:04:18 -0800116 double fixed_instantaneous_velocity;
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800117
118 // The error between our measurement and expected measurement in radians.
119 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -0800120};
121
Austin Schuhea56e212017-03-04 22:33:12 -0800122struct ColumnPosition {
123 // Indexer angle in radians relative to the base. Positive is according to
124 // the right hand rule around +z.
125 .frc971.HallEffectAndPosition indexer;
126 // Turret angle in radians relative to the indexer. Positive is the same as
127 // the indexer.
128 .frc971.HallEffectAndPosition turret;
129};
130
Austin Schuh55934032017-03-11 12:45:27 -0800131struct ColumnEstimatorState {
132 bool error;
133 bool zeroed;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800134 .frc971.HallEffectAndPositionEstimatorState indexer;
Austin Schuh55934032017-03-11 12:45:27 -0800135 .frc971.HallEffectAndPositionEstimatorState turret;
136};
137
138struct TurretProfiledSubsystemStatus {
139 // Is the subsystem zeroed?
140 bool zeroed;
141
142 // The state of the subsystem, if applicable. -1 otherwise.
143 int32_t state;
144
145 // If true, we have aborted.
146 bool estopped;
147
148 // Position of the joint.
149 float position;
150 // Velocity of the joint in units/second.
151 float velocity;
152 // Profiled goal position of the joint.
153 float goal_position;
154 // Profiled goal velocity of the joint in units/second.
155 float goal_velocity;
156 // Unprofiled goal position from absoulte zero of the joint.
157 float unprofiled_goal_position;
158 // Unprofiled goal velocity of the joint in units/second.
159 float unprofiled_goal_velocity;
160
161 // The estimated voltage error.
162 float voltage_error;
163
164 // The calculated velocity with delta x/delta t
165 float calculated_velocity;
166
167 // Components of the control loop output
168 float position_power;
169 float velocity_power;
170 float feedforwards_power;
171
172 // State of the estimator.
173 ColumnEstimatorState estimator_state;
Austin Schuhac76bb32017-03-22 22:34:26 -0700174
175 double raw_vision_angle;
176 double vision_angle;
177 bool vision_tracking;
Austin Schuheb5c22e2017-04-09 18:30:28 -0700178
179 double turret_encoder_angle;
Austin Schuh55934032017-03-11 12:45:27 -0800180};
181
Campbell Crowley75026292017-02-04 21:46:19 -0800182queue_group SuperstructureQueue {
183 implements aos.control_loops.ControlLoop;
184
185 message Goal {
186 IntakeGoal intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800187 IndexerGoal indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800188 TurretGoal turret;
189 HoodGoal hood;
190 ShooterGoal shooter;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800191 bool lights_on;
Parker Schuh208a58d2017-04-12 20:51:38 -0700192 bool use_vision_for_shots;
Campbell Crowley75026292017-02-04 21:46:19 -0800193 };
194
195 message Status {
196 // Are all the subsystems zeroed?
197 bool zeroed;
198
199 // If true, we have aborted. This is the or of all subsystem estops.
200 bool estopped;
201
202 // Each subsystems status.
Adam Snaider79900c22017-02-08 20:23:15 -0800203 .frc971.control_loops.AbsoluteProfiledJointStatus intake;
Austin Schuh6a90cd92017-02-19 20:55:33 -0800204 .frc971.control_loops.IndexProfiledJointStatus hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800205 ShooterStatus shooter;
Austin Schuh55934032017-03-11 12:45:27 -0800206
207 TurretProfiledSubsystemStatus turret;
208 IndexerStatus indexer;
Parker Schuh208a58d2017-04-12 20:51:38 -0700209
210 float vision_distance;
Campbell Crowley75026292017-02-04 21:46:19 -0800211 };
212
213 message Position {
214 // Position of the intake, zero when the intake is in, positive when it is
215 // out.
Adam Snaider79900c22017-02-08 20:23:15 -0800216 .frc971.PotAndAbsolutePosition intake;
Campbell Crowley75026292017-02-04 21:46:19 -0800217
Austin Schuhea56e212017-03-04 22:33:12 -0800218 // The position of the column.
219 ColumnPosition column;
Campbell Crowley75026292017-02-04 21:46:19 -0800220
Austin Schuh0991edb2017-02-05 17:16:44 -0800221 // The sensor readings for the hood. The units and sign are defined the
222 // same as what's in the Goal message.
Austin Schuh6a90cd92017-02-19 20:55:33 -0800223 .frc971.IndexPosition hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800224
225 // Shooter wheel angle in radians.
226 double theta_shooter;
227 };
228
229 message Output {
230 // Voltages for some of the subsystems.
Austin Schuh0991edb2017-02-05 17:16:44 -0800231 double voltage_intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800232 double voltage_indexer;
Austin Schuh0991edb2017-02-05 17:16:44 -0800233 double voltage_shooter;
Campbell Crowley75026292017-02-04 21:46:19 -0800234
235 // Rollers on the intake.
Austin Schuh0991edb2017-02-05 17:16:44 -0800236 double voltage_intake_rollers;
Brian Silverman052e69d2017-02-12 16:19:55 -0800237 // Roller on the indexer
238 double voltage_indexer_rollers;
Campbell Crowley75026292017-02-04 21:46:19 -0800239
Austin Schuh0991edb2017-02-05 17:16:44 -0800240 double voltage_turret;
241 double voltage_hood;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800242
Austin Schuh6a8131b2017-04-08 15:39:22 -0700243 double gear_servo;
244
Adam Snaidere0554ef2017-03-11 23:02:45 -0800245 // If true, the lights are on.
246 bool lights_on;
Austin Schuhc587c882017-03-29 21:33:10 -0700247
248 bool red_light_on;
249 bool green_light_on;
250 bool blue_light_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800251 };
252
253 queue Goal goal;
254 queue Position position;
255 queue Output output;
256 queue Status status;
257};
258
259queue_group SuperstructureQueue superstructure_queue;