blob: c7283b2774ac92317d67d55e570de2ec690d8b8d [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 Schuh932a5ce2017-03-05 01:04:18 -0800115 double fixed_instantaneous_velocity;
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800116
117 // The error between our measurement and expected measurement in radians.
118 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -0800119};
120
Austin Schuhea56e212017-03-04 22:33:12 -0800121struct ColumnPosition {
122 // Indexer angle in radians relative to the base. Positive is according to
123 // the right hand rule around +z.
124 .frc971.HallEffectAndPosition indexer;
125 // Turret angle in radians relative to the indexer. Positive is the same as
126 // the indexer.
127 .frc971.HallEffectAndPosition turret;
128};
129
Austin Schuh55934032017-03-11 12:45:27 -0800130struct ColumnEstimatorState {
131 bool error;
132 bool zeroed;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800133 .frc971.HallEffectAndPositionEstimatorState indexer;
Austin Schuh55934032017-03-11 12:45:27 -0800134 .frc971.HallEffectAndPositionEstimatorState turret;
135};
136
137struct TurretProfiledSubsystemStatus {
138 // Is the subsystem zeroed?
139 bool zeroed;
140
141 // The state of the subsystem, if applicable. -1 otherwise.
142 int32_t state;
143
144 // If true, we have aborted.
145 bool estopped;
146
147 // Position of the joint.
148 float position;
149 // Velocity of the joint in units/second.
150 float velocity;
151 // Profiled goal position of the joint.
152 float goal_position;
153 // Profiled goal velocity of the joint in units/second.
154 float goal_velocity;
155 // Unprofiled goal position from absoulte zero of the joint.
156 float unprofiled_goal_position;
157 // Unprofiled goal velocity of the joint in units/second.
158 float unprofiled_goal_velocity;
159
160 // The estimated voltage error.
161 float voltage_error;
162
163 // The calculated velocity with delta x/delta t
164 float calculated_velocity;
165
166 // Components of the control loop output
167 float position_power;
168 float velocity_power;
169 float feedforwards_power;
170
171 // State of the estimator.
172 ColumnEstimatorState estimator_state;
Austin Schuhac76bb32017-03-22 22:34:26 -0700173
174 double raw_vision_angle;
175 double vision_angle;
176 bool vision_tracking;
Austin Schuh55934032017-03-11 12:45:27 -0800177};
178
Campbell Crowley75026292017-02-04 21:46:19 -0800179queue_group SuperstructureQueue {
180 implements aos.control_loops.ControlLoop;
181
182 message Goal {
183 IntakeGoal intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800184 IndexerGoal indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800185 TurretGoal turret;
186 HoodGoal hood;
187 ShooterGoal shooter;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800188 bool lights_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800189 };
190
191 message Status {
192 // Are all the subsystems zeroed?
193 bool zeroed;
194
195 // If true, we have aborted. This is the or of all subsystem estops.
196 bool estopped;
197
198 // Each subsystems status.
Adam Snaider79900c22017-02-08 20:23:15 -0800199 .frc971.control_loops.AbsoluteProfiledJointStatus intake;
Austin Schuh6a90cd92017-02-19 20:55:33 -0800200 .frc971.control_loops.IndexProfiledJointStatus hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800201 ShooterStatus shooter;
Austin Schuh55934032017-03-11 12:45:27 -0800202
203 TurretProfiledSubsystemStatus turret;
204 IndexerStatus indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800205 };
206
207 message Position {
208 // Position of the intake, zero when the intake is in, positive when it is
209 // out.
Adam Snaider79900c22017-02-08 20:23:15 -0800210 .frc971.PotAndAbsolutePosition intake;
Campbell Crowley75026292017-02-04 21:46:19 -0800211
Austin Schuhea56e212017-03-04 22:33:12 -0800212 // The position of the column.
213 ColumnPosition column;
Campbell Crowley75026292017-02-04 21:46:19 -0800214
Austin Schuh0991edb2017-02-05 17:16:44 -0800215 // The sensor readings for the hood. The units and sign are defined the
216 // same as what's in the Goal message.
Austin Schuh6a90cd92017-02-19 20:55:33 -0800217 .frc971.IndexPosition hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800218
219 // Shooter wheel angle in radians.
220 double theta_shooter;
221 };
222
223 message Output {
224 // Voltages for some of the subsystems.
Austin Schuh0991edb2017-02-05 17:16:44 -0800225 double voltage_intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800226 double voltage_indexer;
Austin Schuh0991edb2017-02-05 17:16:44 -0800227 double voltage_shooter;
Campbell Crowley75026292017-02-04 21:46:19 -0800228
229 // Rollers on the intake.
Austin Schuh0991edb2017-02-05 17:16:44 -0800230 double voltage_intake_rollers;
Brian Silverman052e69d2017-02-12 16:19:55 -0800231 // Roller on the indexer
232 double voltage_indexer_rollers;
Campbell Crowley75026292017-02-04 21:46:19 -0800233
Austin Schuh0991edb2017-02-05 17:16:44 -0800234 double voltage_turret;
235 double voltage_hood;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800236
Austin Schuh6a8131b2017-04-08 15:39:22 -0700237 double gear_servo;
238
Adam Snaidere0554ef2017-03-11 23:02:45 -0800239 // If true, the lights are on.
240 bool lights_on;
Austin Schuhc587c882017-03-29 21:33:10 -0700241
242 bool red_light_on;
243 bool green_light_on;
244 bool blue_light_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800245 };
246
247 queue Goal goal;
248 queue Position position;
249 queue Output output;
250 queue Status status;
251};
252
253queue_group SuperstructureQueue superstructure_queue;