Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 1 | package y2015.control_loops.fridge; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 2 | |
| 3 | import "aos/common/controls/control_loops.q"; |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 4 | import "frc971/control_loops/control_loops.q"; |
| 5 | |
| 6 | // Represents states for all of the box-grabbing pistons. |
| 7 | // true is grabbed and false is retracted for all of them. |
| 8 | struct GrabberPistons { |
| 9 | bool top_front; |
| 10 | bool top_back; |
| 11 | bool bottom_front; |
| 12 | bool bottom_back; |
| 13 | }; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 14 | |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 15 | queue_group FridgeQueue { |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 16 | implements aos.control_loops.ControlLoop; |
| 17 | |
Daniel Petti | 4248d2e | 2015-02-21 10:37:04 -0800 | [diff] [blame] | 18 | // All angles are in radians with 0 sticking straight up. |
| 19 | // Rotating up and into the robot (towards the back |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 20 | // where boxes are placed) is positive. Positive output voltage moves all |
| 21 | // mechanisms in the direction with positive sensor values. |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 22 | |
Daniel Petti | 4248d2e | 2015-02-21 10:37:04 -0800 | [diff] [blame] | 23 | // Elevator heights are the vertical distance (in meters) from a defined zero. |
| 24 | // In this case, zero is where the portion of the carriage that Spencer |
| 25 | // removed lines up with the bolt. |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 26 | |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 27 | // X/Y positions are distances (in meters) the fridge is away from its origin |
| 28 | // position. Origin is considered at a height of zero and an angle of zero. |
| 29 | // Positive X positions are towards the front of the robot and negative X is |
| 30 | // towards the back of the robot (which is where we score). |
| 31 | // Y is positive going up and negative when it goes below the origin. |
| 32 | |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 33 | message Goal { |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 34 | // Profile type. |
| 35 | // Set to 0 for angle/height profiling. |
| 36 | // Set to 1 for x/y profiling. |
| 37 | int32_t profiling_type; |
| 38 | |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 39 | // Angle of the arm. |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 40 | double angle; |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 41 | // Height of the elevator. |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 42 | double height; |
| 43 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 44 | // Angular velocity of the arm. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 45 | float angular_velocity; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 46 | // Linear velocity of the elevator. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 47 | float velocity; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 48 | |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 49 | // Maximum arm profile angular velocity or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 50 | float max_angular_velocity; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 51 | // Maximum elevator profile velocity or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 52 | float max_velocity; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 53 | |
| 54 | // Maximum arm profile acceleration or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 55 | float max_angular_acceleration; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 56 | // Maximum elevator profile acceleration or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 57 | float max_acceleration; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 58 | |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 59 | // X position of the fridge. |
| 60 | double x; |
| 61 | // Y position of the fridge. |
| 62 | double y; |
| 63 | |
| 64 | // Velocity of the x position of the fridge. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 65 | float x_velocity; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 66 | // Velocity of the y position of the fridge. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 67 | float y_velocity; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 68 | |
| 69 | // Maximum x profile velocity or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 70 | float max_x_velocity; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 71 | // Maximum y profile velocity or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 72 | float max_y_velocity; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 73 | |
| 74 | // Maximum x profile acceleration or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 75 | float max_x_acceleration; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 76 | // Maximum y profile acceleration or 0 for the default. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 77 | float max_y_acceleration; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame] | 78 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 79 | // TODO(austin): Do I need acceleration here too? |
| 80 | |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 81 | GrabberPistons grabbers; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | message Position { |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 85 | .frc971.PotAndIndexPair arm; |
| 86 | .frc971.PotAndIndexPair elevator; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | message Status { |
| 90 | // Are both the arm and elevator zeroed? |
| 91 | bool zeroed; |
Daniel Petti | 4248d2e | 2015-02-21 10:37:04 -0800 | [diff] [blame] | 92 | |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 93 | // Estimated angle of the arm. |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 94 | double angle; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 95 | // Estimated angular velocity of the arm. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 96 | float angular_velocity; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 97 | // Estimated height of the elevator. |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 98 | double height; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 99 | // Estimated velocity of the elvator. |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 100 | float velocity; |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 101 | // state of the grabber pistons |
| 102 | GrabberPistons grabbers; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 103 | |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 104 | // Goal angle and velocity of the arm. |
Austin Schuh | 5e872c8 | 2015-02-17 22:59:08 -0800 | [diff] [blame] | 105 | double goal_angle; |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 106 | float goal_angular_velocity; |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 107 | // Goal height and velocity of the elevator. |
Austin Schuh | 5e872c8 | 2015-02-17 22:59:08 -0800 | [diff] [blame] | 108 | double goal_height; |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 109 | float goal_velocity; |
Austin Schuh | 5e872c8 | 2015-02-17 22:59:08 -0800 | [diff] [blame] | 110 | |
Philipp Schrader | 2a25b61 | 2015-03-28 23:49:06 +0000 | [diff] [blame] | 111 | // Estimated X/Y position of the fridge. |
| 112 | // These are translated directly from the height/angle statuses. |
| 113 | double x; |
| 114 | double y; |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 115 | float x_velocity; |
| 116 | float y_velocity; |
Philipp Schrader | 2a25b61 | 2015-03-28 23:49:06 +0000 | [diff] [blame] | 117 | |
| 118 | // X/Y goals of the fridge. |
| 119 | // These are translated directly from the height/angle goals. |
| 120 | double goal_x; |
| 121 | double goal_y; |
Brian Silverman | bb79971 | 2015-03-29 16:14:01 -0400 | [diff] [blame] | 122 | float goal_x_velocity; |
| 123 | float goal_y_velocity; |
Philipp Schrader | 2a25b61 | 2015-03-28 23:49:06 +0000 | [diff] [blame] | 124 | |
Austin Schuh | 5ae4efd | 2015-02-15 23:34:22 -0800 | [diff] [blame] | 125 | // If true, we have aborted. |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 126 | bool estopped; |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 127 | |
| 128 | // The internal state of the state machine. |
| 129 | int32_t state; |
Austin Schuh | 9e37c32 | 2015-02-16 15:47:49 -0800 | [diff] [blame] | 130 | |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 131 | .frc971.EstimatorState left_elevator_state; |
| 132 | .frc971.EstimatorState right_elevator_state; |
| 133 | .frc971.EstimatorState left_arm_state; |
| 134 | .frc971.EstimatorState right_arm_state; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | message Output { |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 138 | double left_arm; |
| 139 | double right_arm; |
| 140 | double left_elevator; |
| 141 | double right_elevator; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 142 | |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 143 | GrabberPistons grabbers; |
Daniel Petti | 663fef0 | 2015-01-22 21:43:00 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | queue Goal goal; |
| 147 | queue Position position; |
| 148 | queue Output output; |
| 149 | queue Status status; |
| 150 | }; |
Daniel Petti | 8bb86eb | 2015-01-26 17:09:58 -0800 | [diff] [blame] | 151 | |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 152 | queue_group FridgeQueue fridge_queue; |