Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 1 | package y2017.control_loops; |
| 2 | |
| 3 | import "aos/common/controls/control_loops.q"; |
Austin Schuh | 3634ed3 | 2017-02-05 16:28:49 -0800 | [diff] [blame] | 4 | import "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 Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 8 | |
| 9 | struct IntakeGoal { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 10 | // Zero for the intake is when the front tube is tangent with the front of the |
| 11 | // frame. Positive is out. |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 12 | |
| 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 Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 20 | double voltage_rollers; |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 21 | |
| 22 | // If true, disable the intake so we can hang. |
| 23 | bool disable_intake; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame^] | 24 | |
| 25 | // The gear servo value. |
| 26 | double gear_servo; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 27 | }; |
| 28 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 29 | struct IndexerGoal { |
| 30 | // Indexer angular velocity goals in radians/second. |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 31 | double angular_velocity; |
Campbell Crowley | 651c4b4 | 2017-02-17 22:30:50 -0800 | [diff] [blame] | 32 | |
| 33 | // Roller voltage. Positive is sucking in. |
| 34 | double voltage_rollers; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct TurretGoal { |
Campbell Crowley | 065a081 | 2017-02-04 22:27:17 -0800 | [diff] [blame] | 38 | // An angle of zero means the turrent faces toward the front of the |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 39 | // robot where the intake is located. The angle increases when the turret |
Campbell Crowley | 065a081 | 2017-02-04 22:27:17 -0800 | [diff] [blame] | 40 | // turns clockwise (towards right from the front), and decreases when |
| 41 | // the turrent turns counter-clockwise (towards left from the front). |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 42 | // These are from a top view above the robot. |
Campbell Crowley | 065a081 | 2017-02-04 22:27:17 -0800 | [diff] [blame] | 43 | double angle; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 44 | |
Austin Schuh | ac76bb3 | 2017-03-22 22:34:26 -0700 | [diff] [blame] | 45 | // 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 Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 49 | // Caps on velocity/acceleration for profiling. 0 for the default. |
| 50 | .frc971.ProfileParameters profile_params; |
| 51 | }; |
| 52 | |
| 53 | struct HoodGoal { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 54 | // Angle the hood is currently at. An angle of zero is at the lower hard |
| 55 | // stop, angle increases as hood rises. |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 56 | double angle; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 57 | |
| 58 | // Caps on velocity/acceleration for profiling. 0 for the default. |
| 59 | .frc971.ProfileParameters profile_params; |
| 60 | }; |
| 61 | |
| 62 | struct ShooterGoal { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 63 | // Angular velocity goals in radians/second. Positive is shooting out of the |
| 64 | // robot. |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 65 | double angular_velocity; |
| 66 | }; |
| 67 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 68 | struct 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 Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 71 | double avg_angular_velocity; |
| 72 | |
| 73 | // The current instantaneous filtered velocity in radians/second. |
| 74 | double angular_velocity; |
| 75 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 76 | // True if the indexer is ready. It is better to compare the velocities |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 77 | // directly so there isn't confusion on if the goal is up to date. |
| 78 | bool ready; |
| 79 | |
Austin Schuh | cd3237a | 2017-02-18 14:19:26 -0800 | [diff] [blame] | 80 | // True if the indexer is stuck. |
| 81 | bool stuck; |
Austin Schuh | a4dd26d | 2017-02-24 19:14:39 -0800 | [diff] [blame] | 82 | float stuck_voltage; |
Austin Schuh | cd3237a | 2017-02-18 14:19:26 -0800 | [diff] [blame] | 83 | |
| 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 Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 99 | struct 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 Chatow | 2737d2a | 2017-02-08 21:20:51 -0800 | [diff] [blame] | 110 | // 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 Schuh | 932a5ce | 2017-03-05 01:04:18 -0800 | [diff] [blame] | 115 | double fixed_instantaneous_velocity; |
Tyler Chatow | 2737d2a | 2017-02-08 21:20:51 -0800 | [diff] [blame] | 116 | |
| 117 | // The error between our measurement and expected measurement in radians. |
| 118 | double position_error; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
Austin Schuh | ea56e21 | 2017-03-04 22:33:12 -0800 | [diff] [blame] | 121 | struct 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 Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 130 | struct ColumnEstimatorState { |
| 131 | bool error; |
| 132 | bool zeroed; |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 133 | .frc971.HallEffectAndPositionEstimatorState indexer; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 134 | .frc971.HallEffectAndPositionEstimatorState turret; |
| 135 | }; |
| 136 | |
| 137 | struct 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 Schuh | ac76bb3 | 2017-03-22 22:34:26 -0700 | [diff] [blame] | 173 | |
| 174 | double raw_vision_angle; |
| 175 | double vision_angle; |
| 176 | bool vision_tracking; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 179 | queue_group SuperstructureQueue { |
| 180 | implements aos.control_loops.ControlLoop; |
| 181 | |
| 182 | message Goal { |
| 183 | IntakeGoal intake; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 184 | IndexerGoal indexer; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 185 | TurretGoal turret; |
| 186 | HoodGoal hood; |
| 187 | ShooterGoal shooter; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 188 | bool lights_on; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 189 | }; |
| 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 Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 199 | .frc971.control_loops.AbsoluteProfiledJointStatus intake; |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 200 | .frc971.control_loops.IndexProfiledJointStatus hood; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 201 | ShooterStatus shooter; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 202 | |
| 203 | TurretProfiledSubsystemStatus turret; |
| 204 | IndexerStatus indexer; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | message Position { |
| 208 | // Position of the intake, zero when the intake is in, positive when it is |
| 209 | // out. |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 210 | .frc971.PotAndAbsolutePosition intake; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 211 | |
Austin Schuh | ea56e21 | 2017-03-04 22:33:12 -0800 | [diff] [blame] | 212 | // The position of the column. |
| 213 | ColumnPosition column; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 214 | |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 215 | // The sensor readings for the hood. The units and sign are defined the |
| 216 | // same as what's in the Goal message. |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 217 | .frc971.IndexPosition hood; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 218 | |
| 219 | // Shooter wheel angle in radians. |
| 220 | double theta_shooter; |
| 221 | }; |
| 222 | |
| 223 | message Output { |
| 224 | // Voltages for some of the subsystems. |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 225 | double voltage_intake; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 226 | double voltage_indexer; |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 227 | double voltage_shooter; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 228 | |
| 229 | // Rollers on the intake. |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 230 | double voltage_intake_rollers; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 231 | // Roller on the indexer |
| 232 | double voltage_indexer_rollers; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 233 | |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 234 | double voltage_turret; |
| 235 | double voltage_hood; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 236 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame^] | 237 | double gear_servo; |
| 238 | |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 239 | // If true, the lights are on. |
| 240 | bool lights_on; |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 241 | |
| 242 | bool red_light_on; |
| 243 | bool green_light_on; |
| 244 | bool blue_light_on; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | queue Goal goal; |
| 248 | queue Position position; |
| 249 | queue Output output; |
| 250 | queue Status status; |
| 251 | }; |
| 252 | |
| 253 | queue_group SuperstructureQueue superstructure_queue; |