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; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 21 | }; |
| 22 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 23 | struct IndexerGoal { |
| 24 | // Indexer angular velocity goals in radians/second. |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 25 | double angular_velocity; |
Campbell Crowley | 651c4b4 | 2017-02-17 22:30:50 -0800 | [diff] [blame] | 26 | |
| 27 | // Roller voltage. Positive is sucking in. |
| 28 | double voltage_rollers; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct TurretGoal { |
Campbell Crowley | 065a081 | 2017-02-04 22:27:17 -0800 | [diff] [blame] | 32 | // 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] | 33 | // robot where the intake is located. The angle increases when the turret |
Campbell Crowley | 065a081 | 2017-02-04 22:27:17 -0800 | [diff] [blame] | 34 | // turns clockwise (towards right from the front), and decreases when |
| 35 | // the turrent turns counter-clockwise (towards left from the front). |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 36 | // These are from a top view above the robot. |
Campbell Crowley | 065a081 | 2017-02-04 22:27:17 -0800 | [diff] [blame] | 37 | double angle; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 38 | |
| 39 | // Caps on velocity/acceleration for profiling. 0 for the default. |
| 40 | .frc971.ProfileParameters profile_params; |
| 41 | }; |
| 42 | |
| 43 | struct HoodGoal { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 44 | // Angle the hood is currently at. An angle of zero is at the lower hard |
| 45 | // stop, angle increases as hood rises. |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 46 | double angle; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 47 | |
| 48 | // Caps on velocity/acceleration for profiling. 0 for the default. |
| 49 | .frc971.ProfileParameters profile_params; |
| 50 | }; |
| 51 | |
| 52 | struct ShooterGoal { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 53 | // Angular velocity goals in radians/second. Positive is shooting out of the |
| 54 | // robot. |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 55 | double angular_velocity; |
| 56 | }; |
| 57 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 58 | struct IndexerStatus { |
| 59 | // The current average velocity in radians/second. Positive is moving balls up |
| 60 | // towards the shooter. This is the angular velocity of the inner piece. |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 61 | double avg_angular_velocity; |
| 62 | |
| 63 | // The current instantaneous filtered velocity in radians/second. |
| 64 | double angular_velocity; |
| 65 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 66 | // 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] | 67 | // directly so there isn't confusion on if the goal is up to date. |
| 68 | bool ready; |
| 69 | |
Austin Schuh | cd3237a | 2017-02-18 14:19:26 -0800 | [diff] [blame] | 70 | // True if the indexer is stuck. |
| 71 | bool stuck; |
Austin Schuh | a4dd26d | 2017-02-24 19:14:39 -0800 | [diff] [blame] | 72 | float stuck_voltage; |
Austin Schuh | cd3237a | 2017-02-18 14:19:26 -0800 | [diff] [blame] | 73 | |
| 74 | // The state of the indexer state machine. |
| 75 | int32_t state; |
| 76 | |
| 77 | // The estimated voltage error from the kalman filter in volts. |
| 78 | double voltage_error; |
| 79 | // The estimated voltage error from the stuck indexer kalman filter. |
| 80 | double stuck_voltage_error; |
| 81 | |
| 82 | // The current velocity measured as delta x / delta t in radians/sec. |
| 83 | double instantaneous_velocity; |
| 84 | |
| 85 | // The error between our measurement and expected measurement in radians. |
| 86 | double position_error; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 89 | struct ShooterStatus { |
| 90 | // The current average velocity in radians/second. |
| 91 | double avg_angular_velocity; |
| 92 | |
| 93 | // The current instantaneous filtered velocity in radians/second. |
| 94 | double angular_velocity; |
| 95 | |
| 96 | // True if the shooter is ready. It is better to compare the velocities |
| 97 | // directly so there isn't confusion on if the goal is up to date. |
| 98 | bool ready; |
| 99 | |
Tyler Chatow | 2737d2a | 2017-02-08 21:20:51 -0800 | [diff] [blame] | 100 | // The estimated voltage error from the kalman filter in volts. |
| 101 | double voltage_error; |
| 102 | |
| 103 | // The current velocity measured as delta x / delta t in radians/sec. |
| 104 | double instantaneous_velocity; |
Austin Schuh | 932a5ce | 2017-03-05 01:04:18 -0800 | [diff] [blame] | 105 | double fixed_instantaneous_velocity; |
Tyler Chatow | 2737d2a | 2017-02-08 21:20:51 -0800 | [diff] [blame] | 106 | |
| 107 | // The error between our measurement and expected measurement in radians. |
| 108 | double position_error; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
Austin Schuh | ea56e21 | 2017-03-04 22:33:12 -0800 | [diff] [blame] | 111 | struct ColumnPosition { |
| 112 | // Indexer angle in radians relative to the base. Positive is according to |
| 113 | // the right hand rule around +z. |
| 114 | .frc971.HallEffectAndPosition indexer; |
| 115 | // Turret angle in radians relative to the indexer. Positive is the same as |
| 116 | // the indexer. |
| 117 | .frc971.HallEffectAndPosition turret; |
| 118 | }; |
| 119 | |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 120 | struct ColumnEstimatorState { |
| 121 | bool error; |
| 122 | bool zeroed; |
| 123 | .frc971.HallEffectAndPositionEstimatorState intake; |
| 124 | .frc971.HallEffectAndPositionEstimatorState turret; |
| 125 | }; |
| 126 | |
| 127 | struct TurretProfiledSubsystemStatus { |
| 128 | // Is the subsystem zeroed? |
| 129 | bool zeroed; |
| 130 | |
| 131 | // The state of the subsystem, if applicable. -1 otherwise. |
| 132 | int32_t state; |
| 133 | |
| 134 | // If true, we have aborted. |
| 135 | bool estopped; |
| 136 | |
| 137 | // Position of the joint. |
| 138 | float position; |
| 139 | // Velocity of the joint in units/second. |
| 140 | float velocity; |
| 141 | // Profiled goal position of the joint. |
| 142 | float goal_position; |
| 143 | // Profiled goal velocity of the joint in units/second. |
| 144 | float goal_velocity; |
| 145 | // Unprofiled goal position from absoulte zero of the joint. |
| 146 | float unprofiled_goal_position; |
| 147 | // Unprofiled goal velocity of the joint in units/second. |
| 148 | float unprofiled_goal_velocity; |
| 149 | |
| 150 | // The estimated voltage error. |
| 151 | float voltage_error; |
| 152 | |
| 153 | // The calculated velocity with delta x/delta t |
| 154 | float calculated_velocity; |
| 155 | |
| 156 | // Components of the control loop output |
| 157 | float position_power; |
| 158 | float velocity_power; |
| 159 | float feedforwards_power; |
| 160 | |
| 161 | // State of the estimator. |
| 162 | ColumnEstimatorState estimator_state; |
| 163 | }; |
| 164 | |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 165 | queue_group SuperstructureQueue { |
| 166 | implements aos.control_loops.ControlLoop; |
| 167 | |
| 168 | message Goal { |
| 169 | IntakeGoal intake; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 170 | IndexerGoal indexer; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 171 | TurretGoal turret; |
| 172 | HoodGoal hood; |
| 173 | ShooterGoal shooter; |
| 174 | }; |
| 175 | |
| 176 | message Status { |
| 177 | // Are all the subsystems zeroed? |
| 178 | bool zeroed; |
| 179 | |
| 180 | // If true, we have aborted. This is the or of all subsystem estops. |
| 181 | bool estopped; |
| 182 | |
| 183 | // Each subsystems status. |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 184 | .frc971.control_loops.AbsoluteProfiledJointStatus intake; |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 185 | .frc971.control_loops.IndexProfiledJointStatus hood; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 186 | ShooterStatus shooter; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 187 | |
| 188 | TurretProfiledSubsystemStatus turret; |
| 189 | IndexerStatus indexer; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | message Position { |
| 193 | // Position of the intake, zero when the intake is in, positive when it is |
| 194 | // out. |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 195 | .frc971.PotAndAbsolutePosition intake; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 196 | |
Austin Schuh | ea56e21 | 2017-03-04 22:33:12 -0800 | [diff] [blame] | 197 | // The position of the column. |
| 198 | ColumnPosition column; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 199 | |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 200 | // The sensor readings for the hood. The units and sign are defined the |
| 201 | // same as what's in the Goal message. |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 202 | .frc971.IndexPosition hood; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 203 | |
| 204 | // Shooter wheel angle in radians. |
| 205 | double theta_shooter; |
| 206 | }; |
| 207 | |
| 208 | message Output { |
| 209 | // Voltages for some of the subsystems. |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 210 | double voltage_intake; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 211 | double voltage_indexer; |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 212 | double voltage_shooter; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 213 | |
| 214 | // Rollers on the intake. |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 215 | double voltage_intake_rollers; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 216 | // Roller on the indexer |
| 217 | double voltage_indexer_rollers; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 218 | |
Austin Schuh | 0991edb | 2017-02-05 17:16:44 -0800 | [diff] [blame] | 219 | double voltage_turret; |
| 220 | double voltage_hood; |
Campbell Crowley | 7502629 | 2017-02-04 21:46:19 -0800 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | queue Goal goal; |
| 224 | queue Position position; |
| 225 | queue Output output; |
| 226 | queue Status status; |
| 227 | }; |
| 228 | |
| 229 | queue_group SuperstructureQueue superstructure_queue; |