brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | package frc971.control_loops; |
| 2 | |
Brian | a6553ed | 2014-04-02 21:26:46 -0700 | [diff] [blame] | 3 | import "aos/common/controls/control_loops.q"; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [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 | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 36 | double right_velocity; |
| 37 | }; |
| 38 | |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 39 | queue_group DrivetrainQueue { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 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 | b94069c | 2014-04-17 14:34:24 -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 | b94069c | 2014-04-17 14:34:24 -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 | 93335ae | 2015-01-26 20:43:39 -0500 | [diff] [blame] | 49 | //bool highgear; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 50 | // True to activate quickturn. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [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. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [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 | b94069c | 2014-04-17 14:34:24 -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 | b94069c | 2014-04-17 14:34:24 -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 | b94069c | 2014-04-17 14:34:24 -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 | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 65 | double right_velocity_goal; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 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. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [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. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [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 | 93335ae | 2015-01-26 20:43:39 -0500 | [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 | 93335ae | 2015-01-26 20:43:39 -0500 | [diff] [blame] | 82 | //double right_shifter_position; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | message Output { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 86 | // Voltage to send to the left motor(s). |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 87 | double left_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 88 | // Voltage to send to the right motor(s). |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 89 | double right_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 90 | // True to set the left shifter piston for high gear. |
Ben Fredrickson | 890c3fe | 2014-03-02 00:15:16 +0000 | [diff] [blame] | 91 | bool left_high; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 92 | // True to set the right shifter piston for high gear. |
Ben Fredrickson | 890c3fe | 2014-03-02 00:15:16 +0000 | [diff] [blame] | 93 | bool right_high; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | message Status { |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 97 | // Estimated speed of the center of the robot in m/s (positive forwards). |
Ben Fredrickson | 890c3fe | 2014-03-02 00:15:16 +0000 | [diff] [blame] | 98 | double robot_speed; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 99 | // Estimated relative position of the left side in meters. |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 100 | double estimated_left_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 101 | // Estimated relative position of the right side in meters. |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 102 | double estimated_right_position; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 103 | // Estimated velocity of the left side in m/s. |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 104 | double estimated_left_velocity; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 105 | // Estimated velocity of the right side in m/s. |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 106 | double estimated_right_velocity; |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 107 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 108 | // The voltage we wanted to send to the left side last cycle. |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 109 | double uncapped_left_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 110 | // The voltage we wanted to send to the right side last cycle. |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 111 | double uncapped_right_voltage; |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 112 | // True if the output voltage was capped last cycle. |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 113 | bool output_was_capped; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | queue Goal goal; |
| 117 | queue Position position; |
| 118 | queue Output output; |
| 119 | queue Status status; |
| 120 | }; |
| 121 | |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 122 | queue_group DrivetrainQueue drivetrain_queue; |