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