Brian Silverman | b601d89 | 2015-12-20 18:24:38 -0500 | [diff] [blame] | 1 | package y2014.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; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 9 | // Whether the left loop is the high-gear one. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 10 | bool left_loop_high; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 11 | // Whether the right loop is the high-gear one. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 12 | bool right_loop_high; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 13 | // The state of the left shifter. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 14 | int8_t left_state; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 15 | // The state of the right shifter. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 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 { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 21 | // Whether the code thinks the left side is currently in gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 22 | bool left_in_gear; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 23 | // Whether the code thinks the right side is currently in gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 24 | bool right_in_gear; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 25 | // The velocity in rad/s (positive forward) the code thinks the left motor |
| 26 | // is currently spinning at. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 27 | double left_motor_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 28 | // The velocity in rad/s (positive forward) the code thinks the right motor |
| 29 | // is currently spinning at. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 30 | double right_motor_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 31 | // The velocity estimate for the left side of the robot in m/s (positive |
| 32 | // forward) used for shifting. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 33 | double left_velocity; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 34 | // The velocity estimate for the right side of the robot in m/s (positive |
| 35 | // forward) used for shifting. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 36 | double right_velocity; |
| 37 | }; |
| 38 | |
| 39 | queue_group DrivetrainQueue { |
| 40 | implements aos.control_loops.ControlLoop; |
| 41 | |
| 42 | message Goal { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 43 | // Position of the steering wheel (positive = turning left when going |
| 44 | // forwards). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 45 | double steering; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 46 | // Position of the throttle (positive forwards). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 47 | double throttle; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 48 | // True to shift into high, false to shift into low. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 49 | bool highgear; |
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; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 52 | // True to have the closed-loop controller take over. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 53 | bool control_loop_driving; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 54 | // Position goal for the left side in meters when the closed-loop controller |
| 55 | // is active. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 56 | double left_goal; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 57 | // Velocity goal for the left side in m/s when the closed-loop controller |
| 58 | // is active. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 59 | double left_velocity_goal; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 60 | // Position goal for the right side in meters when the closed-loop |
| 61 | // controller is active. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 62 | double right_goal; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 63 | // Velocity goal for the right side in m/s when the closed-loop controller |
| 64 | // is active. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 65 | double right_velocity_goal; |
| 66 | }; |
| 67 | |
| 68 | message Position { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 69 | // Relative position of the left side in meters. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 70 | double left_encoder; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 71 | // Relative position of the right side in meters. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 72 | double right_encoder; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 73 | // The speed in m/s of the left side from the most recent encoder pulse, |
| 74 | // or 0 if there was no edge within the last 5ms. |
| 75 | double left_speed; |
| 76 | // The speed in m/s of the right side from the most recent encoder pulse, |
| 77 | // or 0 if there was no edge within the last 5ms. |
| 78 | double right_speed; |
| 79 | // Position of the left shifter (smaller = towards low gear). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 80 | double left_shifter_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 81 | // Position of the right shifter (smaller = towards low gear). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 82 | double right_shifter_position; |
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 { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 90 | // Voltage to send to the left motor(s). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 91 | double left_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 92 | // Voltage to send to the right motor(s). |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 93 | double right_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 94 | // True to set the left shifter piston for high gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 95 | bool left_high; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 96 | // True to set the right shifter piston for high gear. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 97 | bool right_high; |
| 98 | }; |
| 99 | |
| 100 | message Status { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 101 | // 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] | 102 | double robot_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 103 | // Estimated relative position of the left side in meters. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 104 | double filtered_left_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 105 | // Estimated relative position of the right side in meters. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 106 | double filtered_right_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 107 | // Estimated velocity of the left side in m/s. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 108 | double filtered_left_velocity; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 109 | // Estimated velocity of the left side in m/s. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 110 | double filtered_right_velocity; |
| 111 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 112 | // The voltage we wanted to send to the left side last cycle. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 113 | double uncapped_left_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 114 | // The voltage we wanted to send to the right side last cycle. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 115 | double uncapped_right_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame^] | 116 | // True if the output voltage was capped last cycle. |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 117 | bool output_was_capped; |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | queue Goal goal; |
| 121 | queue Position position; |
| 122 | queue Output output; |
| 123 | queue Status status; |
| 124 | }; |
| 125 | |
| 126 | queue_group DrivetrainQueue drivetrain_queue; |