blob: 049a406b1df20834c7d16c7d97f5f1a263632ec5 [file] [log] [blame]
Neil Balchd5206fe2018-01-24 20:25:12 -08001package y2018.control_loops;
2
John Park33858a32018-09-28 23:05:48 -07003import "aos/controls/control_loops.q";
Neil Balchd5206fe2018-01-24 20:25:12 -08004import "frc971/control_loops/control_loops.q";
5
Sabina Davisfdd7a112018-02-04 16:16:23 -08006struct IntakeSideStatus {
Neil Balchd5206fe2018-01-24 20:25:12 -08007 // Is the subsystem zeroed?
8 bool zeroed;
9
Sabina Davisfdd7a112018-02-04 16:16:23 -080010 // The state of the subsystem, if applicable.
Neil Balchd5206fe2018-01-24 20:25:12 -080011 int32_t state;
12
13 // If true, we have aborted.
14 bool estopped;
15
Sabina Davis8d20ca82018-02-19 13:17:45 -080016 // Estimated position of the spring.
17 float spring_position;
18 // Estimated velocity of the spring in units/second.
19 float spring_velocity;
20
Sabina Davisfdd7a112018-02-04 16:16:23 -080021 // Estimated position of the joint.
Sabina Davis8d20ca82018-02-19 13:17:45 -080022 float motor_position;
Sabina Davisfdd7a112018-02-04 16:16:23 -080023 // Estimated velocity of the joint in units/second.
Sabina Davis8d20ca82018-02-19 13:17:45 -080024 float motor_velocity;
Neil Balchd5206fe2018-01-24 20:25:12 -080025
Sabina Davisfdd7a112018-02-04 16:16:23 -080026 // Goal position of the joint.
27 float goal_position;
28 // Goal velocity of the joint in units/second.
29 float goal_velocity;
Neil Balchd5206fe2018-01-24 20:25:12 -080030
31 // The calculated velocity with delta x/delta t
32 float calculated_velocity;
33
Sabina Davis8d20ca82018-02-19 13:17:45 -080034 // The voltage given last cycle;
35 float delayed_voltage;
36
Neil Balchd5206fe2018-01-24 20:25:12 -080037 // State of the estimator.
Austin Schuh72db9a12019-01-21 18:02:51 -080038 .frc971.PotAndAbsoluteEncoderEstimatorState estimator_state;
Neil Balchd5206fe2018-01-24 20:25:12 -080039};
40
41struct IntakeGoal {
Sabina Davis8d20ca82018-02-19 13:17:45 -080042 double roller_voltage;
Neil Balchd5206fe2018-01-24 20:25:12 -080043
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 Davisfdd7a112018-02-04 16:16:23 -080047 double left_intake_angle;
48 double right_intake_angle;
Neil Balchd5206fe2018-01-24 20:25:12 -080049};
50
Austin Schuh2a3e0632018-02-19 16:24:49 -080051struct IntakeElasticSensors {
Sabina Davisfdd7a112018-02-04 16:16:23 -080052 // Position of the motor end of the series elastic in radians.
Austin Schuh2a3e0632018-02-19 16:24:49 -080053 .frc971.PotAndAbsolutePosition motor_position;
Neil Balchd5206fe2018-01-24 20:25:12 -080054
Sabina Davisfdd7a112018-02-04 16:16:23 -080055 // Displacement of the spring in radians.
56 double spring_angle;
Austin Schuh2a3e0632018-02-19 16:24:49 -080057
58 // False if the beam break sensor isn't triggered, true if the beam breaker is
59 // triggered.
60 bool beam_break;
Neil Balchd5206fe2018-01-24 20:25:12 -080061};
62
Sabina Davisfdd7a112018-02-04 16:16:23 -080063struct ArmStatus {
Sabina Davisfdd7a112018-02-04 16:16:23 -080064 // State of the estimators.
Austin Schuh72db9a12019-01-21 18:02:51 -080065 .frc971.PotAndAbsoluteEncoderEstimatorState proximal_estimator_state;
66 .frc971.PotAndAbsoluteEncoderEstimatorState distal_estimator_state;
Austin Schuhcb091712018-02-21 20:01:55 -080067
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 Schuh96341532018-03-09 21:17:24 -080098 uint32_t grab_state;
99
Austin Schuhcb091712018-02-21 20:01:55 -0800100 // The number of times the LQR solver failed.
101 uint32_t failed_solutions;
Sabina Davisfdd7a112018-02-04 16:16:23 -0800102};
103
Neil Balchd5206fe2018-01-24 20:25:12 -0800104struct ArmPosition {
105 // Values of the encoder and potentiometer at the base of the proximal
106 // (connected to drivebase) arm in radians.
Sabina Davisfdd7a112018-02-04 16:16:23 -0800107 .frc971.PotAndAbsolutePosition proximal;
Neil Balchd5206fe2018-01-24 20:25:12 -0800108
109 // Values of the encoder and potentiometer at the base of the distal
110 // (connected to proximal) arm in radians.
Sabina Davisfdd7a112018-02-04 16:16:23 -0800111 .frc971.PotAndAbsolutePosition distal;
Neil Balchd5206fe2018-01-24 20:25:12 -0800112};
113
114struct 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
Austin Schuhd845c972019-06-29 21:20:05 -0700123// Published on ".y2018.control_loops.superstructure_queue"
Neil Balchd5206fe2018-01-24 20:25:12 -0800124queue_group SuperstructureQueue {
125 implements aos.control_loops.ControlLoop;
126
127 message Goal {
128 IntakeGoal intake;
Sabina Davisfdd7a112018-02-04 16:16:23 -0800129
130 // Used to identiy a position in the planned set of positions on the arm.
Austin Schuhcb091712018-02-21 20:01:55 -0800131 uint32_t arm_goal_position;
Austin Schuh96341532018-03-09 21:17:24 -0800132 // If true, start the grab box sequence.
133 bool grab_box;
Neil Balchd5206fe2018-01-24 20:25:12 -0800134
135 bool open_claw;
Neil Balchba9cbba2018-04-06 22:26:38 -0700136 bool close_claw;
Neil Balchd5206fe2018-01-24 20:25:12 -0800137
138 bool deploy_fork;
Austin Schuh17e484e2018-03-11 01:11:36 -0800139
140 bool hook_release;
141
142 double voltage_winch;
Neil Balchba9cbba2018-04-06 22:26:38 -0700143
Austin Schuhd76546a2018-07-08 16:05:14 -0700144 double open_threshold;
145
Neil Balchba9cbba2018-04-06 22:26:38 -0700146 bool disable_box_correct;
Austin Schuhd76546a2018-07-08 16:05:14 -0700147
148 bool trajectory_override;
Neil Balchd5206fe2018-01-24 20:25:12 -0800149 };
150
151 message Status {
152 // Are all the subsystems zeroed?
153 bool zeroed;
154
155 // If true, any of the subsystems have aborted.
156 bool estopped;
157
Sabina Davisfdd7a112018-02-04 16:16:23 -0800158 // Status of both intake sides.
159 IntakeSideStatus left_intake;
160 IntakeSideStatus right_intake;
Neil Balchd5206fe2018-01-24 20:25:12 -0800161
Sabina Davisfdd7a112018-02-04 16:16:23 -0800162 ArmStatus arm;
Neil Balchba9cbba2018-04-06 22:26:38 -0700163
164 double filtered_box_velocity;
165 uint32_t rotation_state;
Neil Balchd5206fe2018-01-24 20:25:12 -0800166 };
167
168 message Position {
Sabina Daviscfb872f2018-02-25 16:28:20 -0800169 // Values of the series elastic encoders on the left side of the robot from
170 // the rear perspective in radians.
171 IntakeElasticSensors left_intake;
172
173 // Values of the series elastic encoders on the right side of the robot from
174 // the rear perspective in radians.
175 IntakeElasticSensors right_intake;
176
Neil Balchd5206fe2018-01-24 20:25:12 -0800177 ArmPosition arm;
Sabina Davisfdd7a112018-02-04 16:16:23 -0800178
179 // Value of the beam breaker sensor. This value is true if the beam is
180 // broken, false if the beam isn't broken.
181 bool claw_beambreak_triggered;
Austin Schuh4ef51af2018-03-04 01:08:45 -0800182 // Value of the beambreak sensor detecting when the box has hit the frame
183 // cutout.
184 bool box_back_beambreak_triggered;
Austin Schuh8e5950d2018-03-21 20:29:40 -0700185
186 // Distance to the box in meters.
187 double box_distance;
Neil Balchd5206fe2018-01-24 20:25:12 -0800188 };
189
190 message Output {
Sabina Daviscfb872f2018-02-25 16:28:20 -0800191 // Voltage sent to the parts on the left side of the intake.
192 IntakeVoltage left_intake;
193
194 // Voltage sent to the parts on the right side of the intake.
195 IntakeVoltage right_intake;
Neil Balchd5206fe2018-01-24 20:25:12 -0800196
Neil Balchd5206fe2018-01-24 20:25:12 -0800197 // Voltage sent to the motors on the proximal joint of the arm.
198 double voltage_proximal;
199
200 // Voltage sent to the motors on the distal joint of the arm.
201 double voltage_distal;
202
Austin Schuh17e484e2018-03-11 01:11:36 -0800203 // Voltage sent to the hanger. Positive pulls the robot up.
204 double voltage_winch;
205
Neil Balchd5206fe2018-01-24 20:25:12 -0800206 // Clamped (when true) or unclamped (when false) status sent to the
207 // pneumatic claw on the arm.
Austin Schuh2a3e0632018-02-19 16:24:49 -0800208 bool claw_grabbed;
209
210 // If true, release the arm brakes.
211 bool release_arm_brake;
212 // If true, release the hook
213 bool hook_release;
214 // If true, release the forks
215 bool forks_release;
Neil Balchd5206fe2018-01-24 20:25:12 -0800216 };
217
218 queue Goal goal;
219 queue Output output;
220 queue Status status;
221 queue Position position;
222};