blob: 3ef64bfe8cd23f21e0fa2b367e2288d129f25a6b [file] [log] [blame]
Comran Morshed5323ecb2015-12-26 20:50:55 +00001package frc971.control_loops;
Brian Silverman17f503e2015-08-02 18:17:18 -07002
3import "aos/common/controls/control_loops.q";
4
Austin Schuh093535c2016-03-05 23:21:00 -08005// Parameters for the motion profiles.
6struct ProfileParameters {
7 // Maximum velocity for the profile.
8 float max_velocity;
9 // Maximum acceleration for the profile.
10 float max_acceleration;
11};
12
Brian Silverman51091a02015-12-26 15:56:58 -080013// For logging information about what the code is doing with the shifters.
Brian Silverman17f503e2015-08-02 18:17:18 -070014struct GearLogging {
Brian Silverman51091a02015-12-26 15:56:58 -080015 // Which controller is being used.
Brian Silverman17f503e2015-08-02 18:17:18 -070016 int8_t controller_index;
Comran Morshed0bf200a2016-02-19 15:19:32 +000017
18 // Whether each loop for the drivetrain sides is the high-gear one.
Brian Silverman17f503e2015-08-02 18:17:18 -070019 bool left_loop_high;
20 bool right_loop_high;
Comran Morshed0bf200a2016-02-19 15:19:32 +000021
22 // The states of each drivetrain shifter.
Brian Silverman17f503e2015-08-02 18:17:18 -070023 int8_t left_state;
24 int8_t right_state;
25};
26
Brian Silverman51091a02015-12-26 15:56:58 -080027// For logging information about the state of the shifters.
Brian Silverman17f503e2015-08-02 18:17:18 -070028struct CIMLogging {
Comran Morshed0bf200a2016-02-19 15:19:32 +000029 // Whether the code thinks each drivetrain side is currently in gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070030 bool left_in_gear;
31 bool right_in_gear;
Comran Morshed0bf200a2016-02-19 15:19:32 +000032
33 // The angular velocities (in rad/s, positive forward) the code thinks motors
34 // on each side of the drivetrain are moving at.
Brian Silverman17f503e2015-08-02 18:17:18 -070035 double left_motor_speed;
36 double right_motor_speed;
Comran Morshed0bf200a2016-02-19 15:19:32 +000037
38 // The velocity estimates for each drivetrain side of the robot (in m/s,
39 // positive forward) that can be used for shifting.
Brian Silverman17f503e2015-08-02 18:17:18 -070040 double left_velocity;
41 double right_velocity;
42};
43
44queue_group DrivetrainQueue {
45 implements aos.control_loops.ControlLoop;
46
47 message Goal {
Brian Silverman51091a02015-12-26 15:56:58 -080048 // Position of the steering wheel (positive = turning left when going
49 // forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -070050 double steering;
Comran Morshed0bf200a2016-02-19 15:19:32 +000051
Brian Silverman51091a02015-12-26 15:56:58 -080052 // Position of the throttle (positive forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -070053 double throttle;
Comran Morshed0bf200a2016-02-19 15:19:32 +000054
Brian Silverman51091a02015-12-26 15:56:58 -080055 // True to shift into high, false to shift into low.
Brian Silverman17f503e2015-08-02 18:17:18 -070056 bool highgear;
Comran Morshed0bf200a2016-02-19 15:19:32 +000057
Brian Silverman51091a02015-12-26 15:56:58 -080058 // True to activate quickturn.
Brian Silverman17f503e2015-08-02 18:17:18 -070059 bool quickturn;
Comran Morshed0bf200a2016-02-19 15:19:32 +000060
Brian Silverman51091a02015-12-26 15:56:58 -080061 // True to have the closed-loop controller take over.
Brian Silverman17f503e2015-08-02 18:17:18 -070062 bool control_loop_driving;
Comran Morshed0bf200a2016-02-19 15:19:32 +000063
64 // Position goals for each drivetrain side (in meters) when the
65 // closed-loop controller is active.
Brian Silverman17f503e2015-08-02 18:17:18 -070066 double left_goal;
Brian Silverman17f503e2015-08-02 18:17:18 -070067 double right_goal;
Comran Morshed0bf200a2016-02-19 15:19:32 +000068
69 // Velocity goal for each drivetrain side (in m/s) when the closed-loop
70 // controller is active.
71 double left_velocity_goal;
Brian Silverman17f503e2015-08-02 18:17:18 -070072 double right_velocity_goal;
Austin Schuh093535c2016-03-05 23:21:00 -080073
74 // Motion profile parameters.
75 // The control loop will profile if these are all non-zero.
76 ProfileParameters linear;
77 ProfileParameters angular;
Brian Silverman17f503e2015-08-02 18:17:18 -070078 };
79
80 message Position {
Comran Morshed0bf200a2016-02-19 15:19:32 +000081 // Relative position of each drivetrain side (in meters).
Brian Silverman17f503e2015-08-02 18:17:18 -070082 double left_encoder;
83 double right_encoder;
Comran Morshed0bf200a2016-02-19 15:19:32 +000084
85 // The speed in m/s of each drivetrain side from the most recent encoder
86 // pulse, or 0 if there was no edge within the last 5ms.
Brian Silverman51091a02015-12-26 15:56:58 -080087 double left_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080088 double right_speed;
Comran Morshed0bf200a2016-02-19 15:19:32 +000089
90 // Position of each drivetrain shifter, scaled from 0.0 to 1.0 where smaller
91 // is towards low gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070092 double left_shifter_position;
93 double right_shifter_position;
Comran Morshed0bf200a2016-02-19 15:19:32 +000094
95 // Raw analog voltages of each shifter hall effect for logging purposes.
Austin Schuha0c1e152015-11-08 14:10:13 -080096 double low_left_hall;
97 double high_left_hall;
98 double low_right_hall;
99 double high_right_hall;
Brian Silverman17f503e2015-08-02 18:17:18 -0700100 };
101
102 message Output {
Comran Morshed0bf200a2016-02-19 15:19:32 +0000103 // Voltage to send to motor(s) on either side of the drivetrain.
Brian Silverman17f503e2015-08-02 18:17:18 -0700104 double left_voltage;
105 double right_voltage;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000106
107 // Whether to set each shifter piston to high gear.
Brian Silverman17f503e2015-08-02 18:17:18 -0700108 bool left_high;
109 bool right_high;
110 };
111
112 message Status {
Brian Silverman51091a02015-12-26 15:56:58 -0800113 // Estimated speed of the center of the robot in m/s (positive forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -0700114 double robot_speed;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000115
116 // Estimated relative position of each drivetrain side (in meters).
Austin Schuh093535c2016-03-05 23:21:00 -0800117 double estimated_left_position;
118 double estimated_right_position;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000119
120 // Estimated velocity of each drivetrain side (in m/s).
Austin Schuh093535c2016-03-05 23:21:00 -0800121 double estimated_left_velocity;
122 double estimated_right_velocity;
Brian Silverman17f503e2015-08-02 18:17:18 -0700123
Comran Morshed0bf200a2016-02-19 15:19:32 +0000124 // The voltage we wanted to send to each drivetrain side last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700125 double uncapped_left_voltage;
126 double uncapped_right_voltage;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000127
Austin Schuh41565602016-02-28 20:10:49 -0800128 // The goal velocities for the polydrive controller.
129 double left_velocity_goal;
130 double right_velocity_goal;
131
Austin Schuh093535c2016-03-05 23:21:00 -0800132 // The voltage error for the left and right sides.
133 double left_voltage_error;
134 double right_voltage_error;
135
136 // The profiled goal states.
137 double profiled_left_position_goal;
138 double profiled_right_position_goal;
139 double profiled_left_velocity_goal;
140 double profiled_right_velocity_goal;
141
142 // The KF offset
143 double estimated_angular_velocity_error;
144 // The KF estimated heading.
145 double estimated_heading;
146 // The KF wheel estimated heading.
147 //double estimated_wheel_heading;
148
Brian Silverman51091a02015-12-26 15:56:58 -0800149 // True if the output voltage was capped last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700150 bool output_was_capped;
Brian Silverman17f503e2015-08-02 18:17:18 -0700151 };
152
153 queue Goal goal;
154 queue Position position;
155 queue Output output;
156 queue Status status;
157};
158
159queue_group DrivetrainQueue drivetrain_queue;