blob: 3c44ed3db8eb0b55652979de95e49af0f574895d [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
42 // Caps on velocity/acceleration for profiling. 0 for the default.
43 .frc971.ProfileParameters profile_params;
44};
45
46struct HoodGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080047 // Angle the hood is currently at. An angle of zero is at the lower hard
48 // stop, angle increases as hood rises.
Austin Schuh0991edb2017-02-05 17:16:44 -080049 double angle;
Campbell Crowley75026292017-02-04 21:46:19 -080050
51 // Caps on velocity/acceleration for profiling. 0 for the default.
52 .frc971.ProfileParameters profile_params;
53};
54
55struct ShooterGoal {
Brian Silverman052e69d2017-02-12 16:19:55 -080056 // Angular velocity goals in radians/second. Positive is shooting out of the
57 // robot.
Campbell Crowley75026292017-02-04 21:46:19 -080058 double angular_velocity;
59};
60
Brian Silverman052e69d2017-02-12 16:19:55 -080061struct IndexerStatus {
62 // The current average velocity in radians/second. Positive is moving balls up
63 // towards the shooter. This is the angular velocity of the inner piece.
Campbell Crowley75026292017-02-04 21:46:19 -080064 double avg_angular_velocity;
65
66 // The current instantaneous filtered velocity in radians/second.
67 double angular_velocity;
68
Brian Silverman052e69d2017-02-12 16:19:55 -080069 // True if the indexer is ready. It is better to compare the velocities
Campbell Crowley75026292017-02-04 21:46:19 -080070 // directly so there isn't confusion on if the goal is up to date.
71 bool ready;
72
Austin Schuhcd3237a2017-02-18 14:19:26 -080073 // True if the indexer is stuck.
74 bool stuck;
Austin Schuha4dd26d2017-02-24 19:14:39 -080075 float stuck_voltage;
Austin Schuhcd3237a2017-02-18 14:19:26 -080076
77 // The state of the indexer state machine.
78 int32_t state;
79
80 // The estimated voltage error from the kalman filter in volts.
81 double voltage_error;
82 // The estimated voltage error from the stuck indexer kalman filter.
83 double stuck_voltage_error;
84
85 // The current velocity measured as delta x / delta t in radians/sec.
86 double instantaneous_velocity;
87
88 // The error between our measurement and expected measurement in radians.
89 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -080090};
91
Campbell Crowley75026292017-02-04 21:46:19 -080092struct ShooterStatus {
93 // The current average velocity in radians/second.
94 double avg_angular_velocity;
95
96 // The current instantaneous filtered velocity in radians/second.
97 double angular_velocity;
98
99 // True if the shooter is ready. It is better to compare the velocities
100 // directly so there isn't confusion on if the goal is up to date.
101 bool ready;
102
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800103 // The estimated voltage error from the kalman filter in volts.
104 double voltage_error;
105
106 // The current velocity measured as delta x / delta t in radians/sec.
107 double instantaneous_velocity;
Austin Schuh932a5ce2017-03-05 01:04:18 -0800108 double fixed_instantaneous_velocity;
Tyler Chatow2737d2a2017-02-08 21:20:51 -0800109
110 // The error between our measurement and expected measurement in radians.
111 double position_error;
Campbell Crowley75026292017-02-04 21:46:19 -0800112};
113
Austin Schuhea56e212017-03-04 22:33:12 -0800114struct ColumnPosition {
115 // Indexer angle in radians relative to the base. Positive is according to
116 // the right hand rule around +z.
117 .frc971.HallEffectAndPosition indexer;
118 // Turret angle in radians relative to the indexer. Positive is the same as
119 // the indexer.
120 .frc971.HallEffectAndPosition turret;
121};
122
Austin Schuh55934032017-03-11 12:45:27 -0800123struct ColumnEstimatorState {
124 bool error;
125 bool zeroed;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800126 .frc971.HallEffectAndPositionEstimatorState indexer;
Austin Schuh55934032017-03-11 12:45:27 -0800127 .frc971.HallEffectAndPositionEstimatorState turret;
128};
129
130struct TurretProfiledSubsystemStatus {
131 // Is the subsystem zeroed?
132 bool zeroed;
133
134 // The state of the subsystem, if applicable. -1 otherwise.
135 int32_t state;
136
137 // If true, we have aborted.
138 bool estopped;
139
140 // Position of the joint.
141 float position;
142 // Velocity of the joint in units/second.
143 float velocity;
144 // Profiled goal position of the joint.
145 float goal_position;
146 // Profiled goal velocity of the joint in units/second.
147 float goal_velocity;
148 // Unprofiled goal position from absoulte zero of the joint.
149 float unprofiled_goal_position;
150 // Unprofiled goal velocity of the joint in units/second.
151 float unprofiled_goal_velocity;
152
153 // The estimated voltage error.
154 float voltage_error;
155
156 // The calculated velocity with delta x/delta t
157 float calculated_velocity;
158
159 // Components of the control loop output
160 float position_power;
161 float velocity_power;
162 float feedforwards_power;
163
164 // State of the estimator.
165 ColumnEstimatorState estimator_state;
166};
167
Campbell Crowley75026292017-02-04 21:46:19 -0800168queue_group SuperstructureQueue {
169 implements aos.control_loops.ControlLoop;
170
171 message Goal {
172 IntakeGoal intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800173 IndexerGoal indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800174 TurretGoal turret;
175 HoodGoal hood;
176 ShooterGoal shooter;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800177 bool lights_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800178 };
179
180 message Status {
181 // Are all the subsystems zeroed?
182 bool zeroed;
183
184 // If true, we have aborted. This is the or of all subsystem estops.
185 bool estopped;
186
187 // Each subsystems status.
Adam Snaider79900c22017-02-08 20:23:15 -0800188 .frc971.control_loops.AbsoluteProfiledJointStatus intake;
Austin Schuh6a90cd92017-02-19 20:55:33 -0800189 .frc971.control_loops.IndexProfiledJointStatus hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800190 ShooterStatus shooter;
Austin Schuh55934032017-03-11 12:45:27 -0800191
192 TurretProfiledSubsystemStatus turret;
193 IndexerStatus indexer;
Campbell Crowley75026292017-02-04 21:46:19 -0800194 };
195
196 message Position {
197 // Position of the intake, zero when the intake is in, positive when it is
198 // out.
Adam Snaider79900c22017-02-08 20:23:15 -0800199 .frc971.PotAndAbsolutePosition intake;
Campbell Crowley75026292017-02-04 21:46:19 -0800200
Austin Schuhea56e212017-03-04 22:33:12 -0800201 // The position of the column.
202 ColumnPosition column;
Campbell Crowley75026292017-02-04 21:46:19 -0800203
Austin Schuh0991edb2017-02-05 17:16:44 -0800204 // The sensor readings for the hood. The units and sign are defined the
205 // same as what's in the Goal message.
Austin Schuh6a90cd92017-02-19 20:55:33 -0800206 .frc971.IndexPosition hood;
Campbell Crowley75026292017-02-04 21:46:19 -0800207
208 // Shooter wheel angle in radians.
209 double theta_shooter;
210 };
211
212 message Output {
213 // Voltages for some of the subsystems.
Austin Schuh0991edb2017-02-05 17:16:44 -0800214 double voltage_intake;
Brian Silverman052e69d2017-02-12 16:19:55 -0800215 double voltage_indexer;
Austin Schuh0991edb2017-02-05 17:16:44 -0800216 double voltage_shooter;
Campbell Crowley75026292017-02-04 21:46:19 -0800217
218 // Rollers on the intake.
Austin Schuh0991edb2017-02-05 17:16:44 -0800219 double voltage_intake_rollers;
Brian Silverman052e69d2017-02-12 16:19:55 -0800220 // Roller on the indexer
221 double voltage_indexer_rollers;
Campbell Crowley75026292017-02-04 21:46:19 -0800222
Austin Schuh0991edb2017-02-05 17:16:44 -0800223 double voltage_turret;
224 double voltage_hood;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800225
226 // If true, the lights are on.
227 bool lights_on;
Campbell Crowley75026292017-02-04 21:46:19 -0800228 };
229
230 queue Goal goal;
231 queue Position position;
232 queue Output output;
233 queue Status status;
234};
235
236queue_group SuperstructureQueue superstructure_queue;