Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 1 | package frc971.control_loops; |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 2 | |
| 3 | import "aos/common/controls/control_loops.q"; |
| 4 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 5 | // For logging information about what the code is doing with the shifters. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 6 | struct GearLogging { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 7 | // Which controller is being used. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 8 | int8_t controller_index; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 9 | |
| 10 | // Whether each loop for the drivetrain sides is the high-gear one. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 11 | bool left_loop_high; |
| 12 | bool right_loop_high; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 13 | |
| 14 | // The states of each drivetrain shifter. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 15 | int8_t left_state; |
| 16 | int8_t right_state; |
| 17 | }; |
| 18 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 19 | // For logging information about the state of the shifters. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 20 | struct CIMLogging { |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 21 | // Whether the code thinks each drivetrain side is currently in gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 22 | bool left_in_gear; |
| 23 | bool right_in_gear; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 24 | |
| 25 | // The angular velocities (in rad/s, positive forward) the code thinks motors |
| 26 | // on each side of the drivetrain are moving at. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 27 | double left_motor_speed; |
| 28 | double right_motor_speed; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 29 | |
| 30 | // The velocity estimates for each drivetrain side of the robot (in m/s, |
| 31 | // positive forward) that can be used for shifting. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 32 | double left_velocity; |
| 33 | double right_velocity; |
| 34 | }; |
| 35 | |
| 36 | queue_group DrivetrainQueue { |
| 37 | implements aos.control_loops.ControlLoop; |
| 38 | |
| 39 | message Goal { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 40 | // Position of the steering wheel (positive = turning left when going |
| 41 | // forwards). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 42 | double steering; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 43 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 44 | // Position of the throttle (positive forwards). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 45 | double throttle; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 46 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 47 | // True to shift into high, false to shift into low. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 48 | bool highgear; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 49 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 50 | // True to activate quickturn. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 51 | bool quickturn; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 52 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 53 | // True to have the closed-loop controller take over. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 54 | bool control_loop_driving; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 55 | |
| 56 | // Position goals for each drivetrain side (in meters) when the |
| 57 | // closed-loop controller is active. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 58 | double left_goal; |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 59 | double right_goal; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 60 | |
| 61 | // Velocity goal for each drivetrain side (in m/s) when the closed-loop |
| 62 | // controller is active. |
| 63 | double left_velocity_goal; |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 64 | double right_velocity_goal; |
| 65 | }; |
| 66 | |
| 67 | message Position { |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 68 | // Relative position of each drivetrain side (in meters). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 69 | double left_encoder; |
| 70 | double right_encoder; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 71 | |
| 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 Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 74 | double left_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 75 | double right_speed; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 76 | |
| 77 | // Position of each drivetrain shifter, scaled from 0.0 to 1.0 where smaller |
| 78 | // is towards low gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 79 | double left_shifter_position; |
| 80 | double right_shifter_position; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 81 | |
| 82 | // Raw analog voltages of each shifter hall effect for logging purposes. |
Austin Schuh | a0c1e15 | 2015-11-08 14:10:13 -0800 | [diff] [blame] | 83 | double low_left_hall; |
| 84 | double high_left_hall; |
| 85 | double low_right_hall; |
| 86 | double high_right_hall; |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | message Output { |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 90 | // Voltage to send to motor(s) on either side of the drivetrain. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 91 | double left_voltage; |
| 92 | double right_voltage; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 93 | |
| 94 | // Whether to set each shifter piston to high gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 95 | bool left_high; |
| 96 | bool right_high; |
| 97 | }; |
| 98 | |
| 99 | message Status { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 100 | // Estimated speed of the center of the robot in m/s (positive forwards). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 101 | double robot_speed; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 102 | |
| 103 | // Estimated relative position of each drivetrain side (in meters). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 104 | double filtered_left_position; |
| 105 | double filtered_right_position; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 106 | |
| 107 | // Estimated velocity of each drivetrain side (in m/s). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 108 | double filtered_left_velocity; |
| 109 | double filtered_right_velocity; |
| 110 | |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 111 | // The voltage we wanted to send to each drivetrain side last cycle. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 112 | double uncapped_left_voltage; |
| 113 | double uncapped_right_voltage; |
Comran Morshed | 0bf200a | 2016-02-19 15:19:32 +0000 | [diff] [blame] | 114 | |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame] | 115 | // The goal velocities for the polydrive controller. |
| 116 | double left_velocity_goal; |
| 117 | double right_velocity_goal; |
| 118 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 119 | // True if the output voltage was capped last cycle. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 120 | bool output_was_capped; |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | queue Goal goal; |
| 124 | queue Position position; |
| 125 | queue Output output; |
| 126 | queue Status status; |
| 127 | }; |
| 128 | |
| 129 | queue_group DrivetrainQueue drivetrain_queue; |