blob: dbd4819a299844e794fe61288ff7d25d186265e2 [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;
Campbell Crowley75026292017-02-04 21:46:19 -080024};
25
Brian Silverman052e69d2017-02-12 16:19:55 -080026struct IndexerGoal {
27 // Indexer angular velocity goals in radians/second.
Campbell Crowley75026292017-02-04 21:46:19 -080028 double angular_velocity;
Campbell Crowley651c4b42017-02-17 22:30:50 -080029
30 // Roller voltage. Positive is sucking in.
31 double voltage_rollers;
Campbell Crowley75026292017-02-04 21:46:19 -080032};
33
34struct TurretGoal {
Campbell Crowley065a0812017-02-04 22:27:17 -080035 // An angle of zero means the turrent faces toward the front of the
Campbell Crowley75026292017-02-04 21:46:19 -080036 // robot where the intake is located. The angle increases when the turret
Campbell Crowley065a0812017-02-04 22:27:17 -080037 // turns clockwise (towards right from the front), and decreases when
38 // the turrent turns counter-clockwise (towards left from the front).
Campbell Crowley75026292017-02-04 21:46:19 -080039 // These are from a top view above the robot.
Campbell Crowley065a0812017-02-04 22:27:17 -080040 double angle;
Campbell Crowley75026292017-02-04 21:46:19 -080041
Austin Schuhac76bb32017-03-22 22:34:26 -070042 // If true, ignore the angle and track using vision. If we don't see
43 // anything, we'll use the turret goal above.
44 bool track;
45
Campbell Crowley75026292017-02-04 21:46:19 -080046 // Caps on velocity/acceleration for profiling. 0 for the default.
47 .frc971.ProfileParameters profile_params;
48};
49
50struct HoodGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080051 // Angle the hood is currently at. An angle of zero is at the lower hard
52 // stop, angle increases as hood rises.
Austin Schuh0991edb2017-02-05 17:16:44 -080053 double angle;
Campbell Crowley75026292017-02-04 21:46:19 -080054
55 // Caps on velocity/acceleration for profiling. 0 for the default.
56 .frc971.ProfileParameters profile_params;
57};
58
59struct ShooterGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080060 // Angular velocity goals in radians/second. Positive is shooting out of the
61 // robot.
Campbell Crowley75026292017-02-04 21:46:19 -080062 double angular_velocity;
63};
64
Brian Silverman052e69d2017-02-12 16:19:55 -080065struct IndexerStatus {
66 // The current average velocity in radians/second. Positive is moving balls up
67 // towards the shooter. This is the angular velocity of the inner piece.
Campbell Crowley75026292017-02-04 21:46:19 -080068 double avg_angular_velocity;
69
70 // The current instantaneous filtered velocity in radians/second.
71 double angular_velocity;
72
Brian Silverman052e69d2017-02-12 16:19:55 -080073 // True if the indexer is ready. It is better to compare the velocities
Campbell Crowley75026292017-02-04 21:46:19 -080074 // directly so there isn't confusion on if the goal is up to date.
75 bool ready;
76
Austin Schuhcd3237a2017-02-18 14:19:26 -080077 // True if the indexer is stuck.
78 bool stuck;
Austin Schuha4dd26d2017-02-24 19:14:39 -080079 float stuck_voltage;
Austin Schuhcd3237a2017-02-18 14:19:26 -080080
81 // The state of the indexer state machine.
82 int32_t state;
83
84 // The estimated voltage error from the kalman filter in volts.
85 double voltage_error;
86 // The estimated voltage error from the stuck indexer kalman filter.
87 double stuck_voltage_error;
88
89 // The current velocity measured as delta x / delta t in radians/sec.
90 double instantaneous_velocity;
91
92 // The error between our measurement and expected measurement in radians.
93 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -080094};
95
Campbell Crowley75026292017-02-04 21:46:19 -080096struct ShooterStatus {
97 // The current average velocity in radians/second.
98 double avg_angular_velocity;
99
100 // The current instantaneous filtered velocity in radians/second.
101 double angular_velocity;
102
103 // True if the shooter is ready. It is better to compare the velocities
104 // directly so there isn't confusion on if the goal is up to date.
105 bool ready;
106
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800107 // The estimated voltage error from the kalman filter in volts.
108 double voltage_error;
109
110 // The current velocity measured as delta x / delta t in radians/sec.
111 double instantaneous_velocity;
Austin Schuh932a5ce2017-03-05 01:04:18 -0800112 double fixed_instantaneous_velocity;
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800113
114 // The error between our measurement and expected measurement in radians.
115 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -0800116};
117
Austin Schuhea56e212017-03-04 22:33:12 -0800118struct ColumnPosition {
119 // Indexer angle in radians relative to the base. Positive is according to
120 // the right hand rule around +z.
121 .frc971.HallEffectAndPosition indexer;
122 // Turret angle in radians relative to the indexer. Positive is the same as
123 // the indexer.
124 .frc971.HallEffectAndPosition turret;
125};
126
Austin Schuh55934032017-03-11 12:45:27 -0800127struct ColumnEstimatorState {
128 bool error;
129 bool zeroed;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800130 .frc971.HallEffectAndPositionEstimatorState indexer;
Austin Schuh55934032017-03-11 12:45:27 -0800131 .frc971.HallEffectAndPositionEstimatorState turret;
132};
133
134struct TurretProfiledSubsystemStatus {
135 // Is the subsystem zeroed?
136 bool zeroed;
137
138 // The state of the subsystem, if applicable. -1 otherwise.
139 int32_t state;
140
141 // If true, we have aborted.
142 bool estopped;
143
144 // Position of the joint.
145 float position;
146 // Velocity of the joint in units/second.
147 float velocity;
148 // Profiled goal position of the joint.
149 float goal_position;
150 // Profiled goal velocity of the joint in units/second.
151 float goal_velocity;
152 // Unprofiled goal position from absoulte zero of the joint.
153 float unprofiled_goal_position;
154 // Unprofiled goal velocity of the joint in units/second.
155 float unprofiled_goal_velocity;
156
157 // The estimated voltage error.
158 float voltage_error;
159
160 // The calculated velocity with delta x/delta t
161 float calculated_velocity;
162
163 // Components of the control loop output
164 float position_power;
165 float velocity_power;
166 float feedforwards_power;
167
168 // State of the estimator.
169 ColumnEstimatorState estimator_state;
Austin Schuhac76bb32017-03-22 22:34:26 -0700170
171 double raw_vision_angle;
172 double vision_angle;
173 bool vision_tracking;
Austin Schuh55934032017-03-11 12:45:27 -0800174};
175
Campbell Crowley75026292017-02-04 21:46:19 -0800176queue_group SuperstructureQueue {
177 implements aos.control_loops.ControlLoop;
178
179 message Goal {
180 IntakeGoal intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800181 IndexerGoal indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800182 TurretGoal turret;
183 HoodGoal hood;
184 ShooterGoal shooter;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800185 bool lights_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800186 };
187
188 message Status {
189 // Are all the subsystems zeroed?
190 bool zeroed;
191
192 // If true, we have aborted. This is the or of all subsystem estops.
193 bool estopped;
194
195 // Each subsystems status.
Adam Snaider79900c22017-02-08 20:23:15 -0800196 .frc971.control_loops.AbsoluteProfiledJointStatus intake;
Austin Schuh6a90cd92017-02-19 20:55:33 -0800197 .frc971.control_loops.IndexProfiledJointStatus hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800198 ShooterStatus shooter;
Austin Schuh55934032017-03-11 12:45:27 -0800199
200 TurretProfiledSubsystemStatus turret;
201 IndexerStatus indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800202 };
203
204 message Position {
205 // Position of the intake, zero when the intake is in, positive when it is
206 // out.
Adam Snaider79900c22017-02-08 20:23:15 -0800207 .frc971.PotAndAbsolutePosition intake;
Campbell Crowley75026292017-02-04 21:46:19 -0800208
Austin Schuhea56e212017-03-04 22:33:12 -0800209 // The position of the column.
210 ColumnPosition column;
Campbell Crowley75026292017-02-04 21:46:19 -0800211
Austin Schuh0991edb2017-02-05 17:16:44 -0800212 // The sensor readings for the hood. The units and sign are defined the
213 // same as what's in the Goal message.
Austin Schuh6a90cd92017-02-19 20:55:33 -0800214 .frc971.IndexPosition hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800215
216 // Shooter wheel angle in radians.
217 double theta_shooter;
218 };
219
220 message Output {
221 // Voltages for some of the subsystems.
Austin Schuh0991edb2017-02-05 17:16:44 -0800222 double voltage_intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800223 double voltage_indexer;
Austin Schuh0991edb2017-02-05 17:16:44 -0800224 double voltage_shooter;
Campbell Crowley75026292017-02-04 21:46:19 -0800225
226 // Rollers on the intake.
Austin Schuh0991edb2017-02-05 17:16:44 -0800227 double voltage_intake_rollers;
Brian Silverman052e69d2017-02-12 16:19:55 -0800228 // Roller on the indexer
229 double voltage_indexer_rollers;
Campbell Crowley75026292017-02-04 21:46:19 -0800230
Austin Schuh0991edb2017-02-05 17:16:44 -0800231 double voltage_turret;
232 double voltage_hood;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800233
234 // If true, the lights are on.
235 bool lights_on;
Austin Schuhc587c882017-03-29 21:33:10 -0700236
237 bool red_light_on;
238 bool green_light_on;
239 bool blue_light_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800240 };
241
242 queue Goal goal;
243 queue Position position;
244 queue Output output;
245 queue Status status;
246};
247
248queue_group SuperstructureQueue superstructure_queue;