blob: 24b1d38adc452157f386255a8e3cc41002091cef [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
Brian Silverman51091a02015-12-26 15:56:58 -08005// For logging information about what the code is doing with the shifters.
Brian Silverman17f503e2015-08-02 18:17:18 -07006struct GearLogging {
Brian Silverman51091a02015-12-26 15:56:58 -08007 // Which controller is being used.
Brian Silverman17f503e2015-08-02 18:17:18 -07008 int8_t controller_index;
Comran Morshed0bf200a2016-02-19 15:19:32 +00009
10 // Whether each loop for the drivetrain sides is the high-gear one.
Brian Silverman17f503e2015-08-02 18:17:18 -070011 bool left_loop_high;
12 bool right_loop_high;
Comran Morshed0bf200a2016-02-19 15:19:32 +000013
14 // The states of each drivetrain shifter.
Brian Silverman17f503e2015-08-02 18:17:18 -070015 int8_t left_state;
16 int8_t right_state;
17};
18
Brian Silverman51091a02015-12-26 15:56:58 -080019// For logging information about the state of the shifters.
Brian Silverman17f503e2015-08-02 18:17:18 -070020struct CIMLogging {
Comran Morshed0bf200a2016-02-19 15:19:32 +000021 // Whether the code thinks each drivetrain side is currently in gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070022 bool left_in_gear;
23 bool right_in_gear;
Comran Morshed0bf200a2016-02-19 15:19:32 +000024
25 // The angular velocities (in rad/s, positive forward) the code thinks motors
26 // on each side of the drivetrain are moving at.
Brian Silverman17f503e2015-08-02 18:17:18 -070027 double left_motor_speed;
28 double right_motor_speed;
Comran Morshed0bf200a2016-02-19 15:19:32 +000029
30 // The velocity estimates for each drivetrain side of the robot (in m/s,
31 // positive forward) that can be used for shifting.
Brian Silverman17f503e2015-08-02 18:17:18 -070032 double left_velocity;
33 double right_velocity;
34};
35
36queue_group DrivetrainQueue {
37 implements aos.control_loops.ControlLoop;
38
39 message Goal {
Brian Silverman51091a02015-12-26 15:56:58 -080040 // Position of the steering wheel (positive = turning left when going
41 // forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -070042 double steering;
Comran Morshed0bf200a2016-02-19 15:19:32 +000043
Brian Silverman51091a02015-12-26 15:56:58 -080044 // Position of the throttle (positive forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -070045 double throttle;
Comran Morshed0bf200a2016-02-19 15:19:32 +000046
Brian Silverman51091a02015-12-26 15:56:58 -080047 // True to shift into high, false to shift into low.
Brian Silverman17f503e2015-08-02 18:17:18 -070048 bool highgear;
Comran Morshed0bf200a2016-02-19 15:19:32 +000049
Brian Silverman51091a02015-12-26 15:56:58 -080050 // True to activate quickturn.
Brian Silverman17f503e2015-08-02 18:17:18 -070051 bool quickturn;
Comran Morshed0bf200a2016-02-19 15:19:32 +000052
Brian Silverman51091a02015-12-26 15:56:58 -080053 // True to have the closed-loop controller take over.
Brian Silverman17f503e2015-08-02 18:17:18 -070054 bool control_loop_driving;
Comran Morshed0bf200a2016-02-19 15:19:32 +000055
56 // Position goals for each drivetrain side (in meters) when the
57 // closed-loop controller is active.
Brian Silverman17f503e2015-08-02 18:17:18 -070058 double left_goal;
Brian Silverman17f503e2015-08-02 18:17:18 -070059 double right_goal;
Comran Morshed0bf200a2016-02-19 15:19:32 +000060
61 // Velocity goal for each drivetrain side (in m/s) when the closed-loop
62 // controller is active.
63 double left_velocity_goal;
Brian Silverman17f503e2015-08-02 18:17:18 -070064 double right_velocity_goal;
65 };
66
67 message Position {
Comran Morshed0bf200a2016-02-19 15:19:32 +000068 // Relative position of each drivetrain side (in meters).
Brian Silverman17f503e2015-08-02 18:17:18 -070069 double left_encoder;
70 double right_encoder;
Comran Morshed0bf200a2016-02-19 15:19:32 +000071
72 // The speed in m/s of each drivetrain side from the most recent encoder
73 // pulse, or 0 if there was no edge within the last 5ms.
Brian Silverman51091a02015-12-26 15:56:58 -080074 double left_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080075 double right_speed;
Comran Morshed0bf200a2016-02-19 15:19:32 +000076
77 // Position of each drivetrain shifter, scaled from 0.0 to 1.0 where smaller
78 // is towards low gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070079 double left_shifter_position;
80 double right_shifter_position;
Comran Morshed0bf200a2016-02-19 15:19:32 +000081
82 // Raw analog voltages of each shifter hall effect for logging purposes.
Austin Schuha0c1e152015-11-08 14:10:13 -080083 double low_left_hall;
84 double high_left_hall;
85 double low_right_hall;
86 double high_right_hall;
Brian Silverman17f503e2015-08-02 18:17:18 -070087 };
88
89 message Output {
Comran Morshed0bf200a2016-02-19 15:19:32 +000090 // Voltage to send to motor(s) on either side of the drivetrain.
Brian Silverman17f503e2015-08-02 18:17:18 -070091 double left_voltage;
92 double right_voltage;
Comran Morshed0bf200a2016-02-19 15:19:32 +000093
94 // Whether to set each shifter piston to high gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070095 bool left_high;
96 bool right_high;
97 };
98
99 message Status {
Brian Silverman51091a02015-12-26 15:56:58 -0800100 // Estimated speed of the center of the robot in m/s (positive forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -0700101 double robot_speed;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000102
103 // Estimated relative position of each drivetrain side (in meters).
Brian Silverman17f503e2015-08-02 18:17:18 -0700104 double filtered_left_position;
105 double filtered_right_position;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000106
107 // Estimated velocity of each drivetrain side (in m/s).
Brian Silverman17f503e2015-08-02 18:17:18 -0700108 double filtered_left_velocity;
109 double filtered_right_velocity;
110
Comran Morshed0bf200a2016-02-19 15:19:32 +0000111 // The voltage we wanted to send to each drivetrain side last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700112 double uncapped_left_voltage;
113 double uncapped_right_voltage;
Comran Morshed0bf200a2016-02-19 15:19:32 +0000114
Austin Schuh41565602016-02-28 20:10:49 -0800115 // The goal velocities for the polydrive controller.
116 double left_velocity_goal;
117 double right_velocity_goal;
118
Brian Silverman51091a02015-12-26 15:56:58 -0800119 // True if the output voltage was capped last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700120 bool output_was_capped;
Brian Silverman17f503e2015-08-02 18:17:18 -0700121 };
122
123 queue Goal goal;
124 queue Position position;
125 queue Output output;
126 queue Status status;
127};
128
129queue_group DrivetrainQueue drivetrain_queue;