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 | |
| 63 | struct IntakePosition { |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 64 | // Values of the series elastic encoders on the left side of the robot from |
| 65 | // the rear perspective in radians. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 66 | IntakeElasticSensors left; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 67 | |
| 68 | // Values of the series elastic encoders on the right side of the robot from |
| 69 | // the rear perspective in radians. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 70 | IntakeElasticSensors right; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 73 | struct ArmStatus { |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 74 | // State of the estimators. |
| 75 | .frc971.AbsoluteEstimatorState proximal_estimator_state; |
| 76 | .frc971.AbsoluteEstimatorState distal_estimator_state; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 77 | |
| 78 | // The node we are currently going to. |
| 79 | uint32_t current_node; |
| 80 | // Distance (in radians) to the end of the path. |
| 81 | float path_distance_to_go; |
| 82 | // Goal position and velocity (radians) |
| 83 | float goal_theta0; |
| 84 | float goal_theta1; |
| 85 | float goal_omega0; |
| 86 | float goal_omega1; |
| 87 | |
| 88 | // Current position and velocity (radians) |
| 89 | float theta0; |
| 90 | float theta1; |
| 91 | |
| 92 | float omega0; |
| 93 | float omega1; |
| 94 | |
| 95 | // Estimated voltage error for the two joints. |
| 96 | float voltage_error0; |
| 97 | float voltage_error1; |
| 98 | |
| 99 | // True if we are zeroed. |
| 100 | bool zeroed; |
| 101 | |
| 102 | // True if the arm is zeroed. |
| 103 | bool estopped; |
| 104 | |
| 105 | // The current state machine state. |
| 106 | uint32_t state; |
| 107 | |
| 108 | // The number of times the LQR solver failed. |
| 109 | uint32_t failed_solutions; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 112 | struct ArmPosition { |
| 113 | // Values of the encoder and potentiometer at the base of the proximal |
| 114 | // (connected to drivebase) arm in radians. |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 115 | .frc971.PotAndAbsolutePosition proximal; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 116 | |
| 117 | // Values of the encoder and potentiometer at the base of the distal |
| 118 | // (connected to proximal) arm in radians. |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 119 | .frc971.PotAndAbsolutePosition distal; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | struct IntakeVoltage { |
| 123 | // Voltage of the motors on the series elastic on one side (left or right) of |
| 124 | // the intake. |
| 125 | double voltage_elastic; |
| 126 | |
| 127 | // Voltage of the rollers on one side (left or right) of the intake. |
| 128 | double voltage_rollers; |
| 129 | }; |
| 130 | |
| 131 | struct IntakeOutput { |
| 132 | // Voltage sent to the parts on the left side of the intake. |
| 133 | IntakeVoltage left; |
| 134 | |
| 135 | // Voltage sent to the parts on the right side of the intake. |
| 136 | IntakeVoltage right; |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | queue_group SuperstructureQueue { |
| 141 | implements aos.control_loops.ControlLoop; |
| 142 | |
| 143 | message Goal { |
| 144 | IntakeGoal intake; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 145 | |
| 146 | // 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] | 147 | uint32_t arm_goal_position; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 148 | |
| 149 | bool open_claw; |
| 150 | |
| 151 | bool deploy_fork; |
| 152 | }; |
| 153 | |
| 154 | message Status { |
| 155 | // Are all the subsystems zeroed? |
| 156 | bool zeroed; |
| 157 | |
| 158 | // If true, any of the subsystems have aborted. |
| 159 | bool estopped; |
| 160 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 161 | // Status of both intake sides. |
| 162 | IntakeSideStatus left_intake; |
| 163 | IntakeSideStatus right_intake; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 164 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 165 | ArmStatus arm; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | message Position { |
| 169 | IntakePosition intake; |
| 170 | ArmPosition arm; |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 171 | |
| 172 | // Value of the beam breaker sensor. This value is true if the beam is |
| 173 | // broken, false if the beam isn't broken. |
| 174 | bool claw_beambreak_triggered; |
Austin Schuh | 4ef51af | 2018-03-04 01:08:45 -0800 | [diff] [blame^] | 175 | // Value of the beambreak sensor detecting when the box has hit the frame |
| 176 | // cutout. |
| 177 | bool box_back_beambreak_triggered; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | message Output { |
| 181 | IntakeOutput intake; |
| 182 | |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 183 | // Voltage sent to the motors on the proximal joint of the arm. |
| 184 | double voltage_proximal; |
| 185 | |
| 186 | // Voltage sent to the motors on the distal joint of the arm. |
| 187 | double voltage_distal; |
| 188 | |
| 189 | // Clamped (when true) or unclamped (when false) status sent to the |
| 190 | // pneumatic claw on the arm. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 191 | bool claw_grabbed; |
| 192 | |
| 193 | // If true, release the arm brakes. |
| 194 | bool release_arm_brake; |
| 195 | // If true, release the hook |
| 196 | bool hook_release; |
| 197 | // If true, release the forks |
| 198 | bool forks_release; |
Neil Balch | d5206fe | 2018-01-24 20:25:12 -0800 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | queue Goal goal; |
| 202 | queue Output output; |
| 203 | queue Status status; |
| 204 | queue Position position; |
| 205 | }; |
| 206 | |
| 207 | queue_group SuperstructureQueue superstructure_queue; |