Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 1 | package y2018.control_loops; |
| 2 | |
| 3 | import "aos/common/controls/control_loops.q"; |
| 4 | import "frc971/control_loops/control_loops.q"; |
| 5 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 6 | struct IntakeSideStatus { |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 7 | // Is the subsystem zeroed? |
| 8 | bool zeroed; |
| 9 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 10 | // The state of the subsystem, if applicable. |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 11 | int32_t state; |
| 12 | |
| 13 | // If true, we have aborted. |
| 14 | bool estopped; |
| 15 | |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 16 | // Estimated position of the spring. |
| 17 | float spring_position; |
| 18 | // Estimated velocity of the spring in units/second. |
| 19 | float spring_velocity; |
| 20 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 21 | // Estimated position of the joint. |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 22 | float motor_position; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 23 | // Estimated velocity of the joint in units/second. |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 24 | float motor_velocity; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 25 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 26 | // Goal position of the joint. |
| 27 | float goal_position; |
| 28 | // Goal velocity of the joint in units/second. |
| 29 | float goal_velocity; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 30 | |
| 31 | // The calculated velocity with delta x/delta t |
| 32 | float calculated_velocity; |
| 33 | |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 34 | // The voltage given last cycle; |
| 35 | float delayed_voltage; |
| 36 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 37 | // State of the estimator. |
| 38 | .frc971.AbsoluteEstimatorState estimator_state; |
| 39 | }; |
| 40 | |
| 41 | struct IntakeGoal { |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 42 | double roller_voltage; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 43 | |
| 44 | // Goal angle in radians of the intake. |
| 45 | // Zero radians is where the intake is pointing straight out, with positive |
| 46 | // radians inward towards the cube. |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 47 | double left_intake_angle; |
| 48 | double right_intake_angle; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 51 | struct IntakeElasticSensors { |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 52 | // Position of the motor end of the series elastic in radians. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 53 | .frc971.PotAndAbsolutePosition motor_position; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 54 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 55 | // Displacement of the spring in radians. |
| 56 | double spring_angle; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 57 | |
| 58 | // False if the beam break sensor isn't triggered, true if the beam breaker is |
| 59 | // triggered. |
| 60 | bool beam_break; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 63 | struct ArmStatus { |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 64 | // State of the estimators. |
| 65 | .frc971.AbsoluteEstimatorState proximal_estimator_state; |
| 66 | .frc971.AbsoluteEstimatorState distal_estimator_state; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 67 | |
| 68 | // The node we are currently going to. |
| 69 | uint32_t current_node; |
| 70 | // Distance (in radians) to the end of the path. |
| 71 | float path_distance_to_go; |
| 72 | // Goal position and velocity (radians) |
| 73 | float goal_theta0; |
| 74 | float goal_theta1; |
| 75 | float goal_omega0; |
| 76 | float goal_omega1; |
| 77 | |
| 78 | // Current position and velocity (radians) |
| 79 | float theta0; |
| 80 | float theta1; |
| 81 | |
| 82 | float omega0; |
| 83 | float omega1; |
| 84 | |
| 85 | // Estimated voltage error for the two joints. |
| 86 | float voltage_error0; |
| 87 | float voltage_error1; |
| 88 | |
| 89 | // True if we are zeroed. |
| 90 | bool zeroed; |
| 91 | |
| 92 | // True if the arm is zeroed. |
| 93 | bool estopped; |
| 94 | |
| 95 | // The current state machine state. |
| 96 | uint32_t state; |
| 97 | |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 98 | uint32_t grab_state; |
| 99 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 100 | // The number of times the LQR solver failed. |
| 101 | uint32_t failed_solutions; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 104 | struct ArmPosition { |
| 105 | // Values of the encoder and potentiometer at the base of the proximal |
| 106 | // (connected to drivebase) arm in radians. |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 107 | .frc971.PotAndAbsolutePosition proximal; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 108 | |
| 109 | // Values of the encoder and potentiometer at the base of the distal |
| 110 | // (connected to proximal) arm in radians. |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 111 | .frc971.PotAndAbsolutePosition distal; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct IntakeVoltage { |
| 115 | // Voltage of the motors on the series elastic on one side (left or right) of |
| 116 | // the intake. |
| 117 | double voltage_elastic; |
| 118 | |
| 119 | // Voltage of the rollers on one side (left or right) of the intake. |
| 120 | double voltage_rollers; |
| 121 | }; |
| 122 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 123 | queue_group SuperstructureQueue { |
| 124 | implements aos.control_loops.ControlLoop; |
| 125 | |
| 126 | message Goal { |
| 127 | IntakeGoal intake; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 128 | |
| 129 | // Used to identiy a position in the planned set of positions on the arm. |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 130 | uint32_t arm_goal_position; |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 131 | // If true, start the grab box sequence. |
| 132 | bool grab_box; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 133 | |
| 134 | bool open_claw; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 135 | bool close_claw; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 136 | |
| 137 | bool deploy_fork; |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 138 | |
| 139 | bool hook_release; |
| 140 | |
| 141 | double voltage_winch; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 142 | |
Austin Schuh | d76546a | 2018-07-08 16:05:14 -0700 | [diff] [blame] | 143 | double open_threshold; |
| 144 | |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 145 | bool disable_box_correct; |
Austin Schuh | d76546a | 2018-07-08 16:05:14 -0700 | [diff] [blame] | 146 | |
| 147 | bool trajectory_override; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | message Status { |
| 151 | // Are all the subsystems zeroed? |
| 152 | bool zeroed; |
| 153 | |
| 154 | // If true, any of the subsystems have aborted. |
| 155 | bool estopped; |
| 156 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 157 | // Status of both intake sides. |
| 158 | IntakeSideStatus left_intake; |
| 159 | IntakeSideStatus right_intake; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 160 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 161 | ArmStatus arm; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 162 | |
| 163 | double filtered_box_velocity; |
| 164 | uint32_t rotation_state; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | message Position { |
Sabina Davis | cfb872f | 2018-02-25 16:28:20 -0800 | [diff] [blame] | 168 | // Values of the series elastic encoders on the left side of the robot from |
| 169 | // the rear perspective in radians. |
| 170 | IntakeElasticSensors left_intake; |
| 171 | |
| 172 | // Values of the series elastic encoders on the right side of the robot from |
| 173 | // the rear perspective in radians. |
| 174 | IntakeElasticSensors right_intake; |
| 175 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 176 | ArmPosition arm; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 177 | |
| 178 | // Value of the beam breaker sensor. This value is true if the beam is |
| 179 | // broken, false if the beam isn't broken. |
| 180 | bool claw_beambreak_triggered; |
Austin Schuh | 4ef51af | 2018-03-04 01:08:45 -0800 | [diff] [blame] | 181 | // Value of the beambreak sensor detecting when the box has hit the frame |
| 182 | // cutout. |
| 183 | bool box_back_beambreak_triggered; |
Austin Schuh | 8e5950d | 2018-03-21 20:29:40 -0700 | [diff] [blame] | 184 | |
| 185 | // Distance to the box in meters. |
| 186 | double box_distance; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | message Output { |
Sabina Davis | cfb872f | 2018-02-25 16:28:20 -0800 | [diff] [blame] | 190 | // Voltage sent to the parts on the left side of the intake. |
| 191 | IntakeVoltage left_intake; |
| 192 | |
| 193 | // Voltage sent to the parts on the right side of the intake. |
| 194 | IntakeVoltage right_intake; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 195 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 196 | // Voltage sent to the motors on the proximal joint of the arm. |
| 197 | double voltage_proximal; |
| 198 | |
| 199 | // Voltage sent to the motors on the distal joint of the arm. |
| 200 | double voltage_distal; |
| 201 | |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 202 | // Voltage sent to the hanger. Positive pulls the robot up. |
| 203 | double voltage_winch; |
| 204 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 205 | // Clamped (when true) or unclamped (when false) status sent to the |
| 206 | // pneumatic claw on the arm. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 207 | bool claw_grabbed; |
| 208 | |
| 209 | // If true, release the arm brakes. |
| 210 | bool release_arm_brake; |
| 211 | // If true, release the hook |
| 212 | bool hook_release; |
| 213 | // If true, release the forks |
| 214 | bool forks_release; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | queue Goal goal; |
| 218 | queue Output output; |
| 219 | queue Status status; |
| 220 | queue Position position; |
| 221 | }; |
| 222 | |
| 223 | queue_group SuperstructureQueue superstructure_queue; |