Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 1 | package y2014_bot3.control_loops; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [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 the state of the shifters. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 6 | struct CIMLogging { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 7 | // Whether the code thinks the left side is currently in gear. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 8 | bool left_in_gear; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 9 | // Whether the code thinks the right side is currently in gear. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 10 | bool right_in_gear; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 11 | // The velocity in rad/s (positive forward) the code thinks the left motor |
| 12 | // is currently spinning at. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 13 | double left_motor_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 14 | // The velocity in rad/s (positive forward) the code thinks the right motor |
| 15 | // is currently spinning at. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 16 | double right_motor_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 17 | // The velocity estimate for the left side of the robot in m/s (positive |
| 18 | // forward) used for shifting. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 19 | double left_velocity; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 20 | // The velocity estimate for the right side of the robot in m/s (positive |
| 21 | // forward) used for shifting. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 22 | double right_velocity; |
| 23 | }; |
| 24 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 25 | queue_group DrivetrainQueue { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 26 | implements aos.control_loops.ControlLoop; |
| 27 | |
| 28 | message Goal { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 29 | // Position of the steering wheel (positive = turning left when going |
| 30 | // forwards). |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 31 | double steering; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 32 | // Position of the throttle (positive forwards). |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 33 | double throttle; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 34 | // True to shift into high, false to shift into low. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 35 | bool highgear; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 36 | // True to activate quickturn. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 37 | bool quickturn; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 38 | // True to have the closed-loop controller take over. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 39 | bool control_loop_driving; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 40 | // Position goal for the left side in meters when the closed-loop controller |
| 41 | // is active. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 42 | double left_goal; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 43 | // Velocity goal for the left side in m/s when the closed-loop controller |
| 44 | // is active. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 45 | double left_velocity_goal; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 46 | // Position goal for the right side in meters when the closed-loop |
| 47 | // controller is active. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 48 | double right_goal; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 49 | // Velocity goal for the right side in m/s when the closed-loop controller |
| 50 | // is active. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 51 | double right_velocity_goal; |
| 52 | }; |
| 53 | |
| 54 | message Position { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 55 | // Relative position of the left side in meters. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 56 | double left_encoder; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 57 | // Relative position of the right side in meters. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 58 | double right_encoder; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 59 | // The speed in m/s of the left side from the most recent encoder pulse, |
| 60 | // or 0 if there was no edge within the last 5ms. |
| 61 | double left_speed; |
| 62 | // The speed in m/s of the right side from the most recent encoder pulse, |
| 63 | // or 0 if there was no edge within the last 5ms. |
| 64 | double right_speed; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | message Output { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 68 | // Voltage to send to the left motor(s). |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 69 | double left_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 70 | // Voltage to send to the right motor(s). |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 71 | double right_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 72 | // True to set the left shifter piston for high gear. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 73 | bool left_high; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 74 | // True to set the right shifter piston for high gear. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 75 | bool right_high; |
| 76 | }; |
| 77 | |
| 78 | message Status { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 79 | // Estimated speed of the center of the robot in m/s (positive forwards). |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 80 | double robot_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 81 | // Estimated relative position of the left side in meters. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 82 | double filtered_left_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 83 | // Estimated relative position of the right side in meters. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 84 | double filtered_right_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 85 | // Estimated velocity of the left side in m/s. |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 86 | double filtered_left_velocity; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 87 | // Estimated velocity of the right side in m/s. |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 88 | double filtered_right_velocity; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 89 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 90 | // The voltage we wanted to send to the left side last cycle. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 91 | double uncapped_left_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 92 | // The voltage we wanted to send to the right side last cycle. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 93 | double uncapped_right_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 94 | // True if the output voltage was capped last cycle. |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 95 | bool output_was_capped; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | queue Goal goal; |
| 99 | queue Position position; |
| 100 | queue Output output; |
| 101 | queue Status status; |
| 102 | }; |
| 103 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 104 | queue_group DrivetrainQueue drivetrain_queue; |