Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 1 | #ifndef Y2019_CONSTANTS_H_ |
| 2 | #define Y2019_CONSTANTS_H_ |
| 3 | |
James Kuszmaul | 22c5ab3 | 2019-02-09 14:45:58 -0800 | [diff] [blame] | 4 | #include <array> |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 5 | #include <math.h> |
Sabina Davis | 1b84afa | 2019-02-09 01:20:21 -0800 | [diff] [blame] | 6 | #include <stdint.h> |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 7 | |
| 8 | #include "frc971/constants.h" |
James Kuszmaul | f4ede20 | 2020-02-14 08:47:40 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/camera.h" |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 10 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 11 | #include "y2019/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 12 | #include "y2019/control_loops/superstructure/elevator/elevator_plant.h" |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 13 | #include "y2019/control_loops/superstructure/intake/intake_plant.h" |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 14 | #include "y2019/control_loops/superstructure/stilts/stilts_plant.h" |
| 15 | #include "y2019/control_loops/superstructure/wrist/wrist_plant.h" |
James Kuszmaul | 22c5ab3 | 2019-02-09 14:45:58 -0800 | [diff] [blame] | 16 | #include "frc971/control_loops/pose.h" |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 17 | |
| 18 | namespace y2019 { |
| 19 | namespace constants { |
| 20 | |
| 21 | // Has all of our "constants", except the ones that come from other places. The |
| 22 | // ones which change between robots are put together with a workable way to |
| 23 | // retrieve the values for the current robot. |
| 24 | |
| 25 | // Everything is in SI units (volts, radians, meters, seconds, etc). |
| 26 | // Some of these values are related to the conversion between raw values |
| 27 | // (encoder counts, voltage, etc) to scaled units (radians, meters, etc). |
| 28 | // |
| 29 | // All ratios are from the encoder shaft to the output units. |
| 30 | |
James Kuszmaul | 22c5ab3 | 2019-02-09 14:45:58 -0800 | [diff] [blame] | 31 | |
| 32 | class Field { |
| 33 | public: |
| 34 | typedef ::frc971::control_loops::TypedPose<double> Pose; |
James Kuszmaul | f4ede20 | 2020-02-14 08:47:40 -0800 | [diff] [blame] | 35 | typedef ::frc971::control_loops::TypedTarget<double> Target; |
James Kuszmaul | 22c5ab3 | 2019-02-09 14:45:58 -0800 | [diff] [blame] | 36 | typedef ::frc971::control_loops::TypedLineSegment<double> Obstacle; |
| 37 | |
| 38 | static constexpr size_t kNumTargets = 32; |
| 39 | static constexpr size_t kNumObstacles = 10; |
| 40 | |
| 41 | Field(); |
| 42 | |
| 43 | ::std::array<Target, kNumTargets> targets() const { return targets_; } |
| 44 | ::std::array<Obstacle, kNumObstacles> obstacles() const { return obstacles_; } |
| 45 | |
| 46 | private: |
| 47 | // All target locations are defined as being at the center of the target, |
| 48 | // except for the height, for which we use the top of the target. |
| 49 | ::std::array<Target, kNumTargets> targets_; |
| 50 | // Obstacle locations are approximate, as we are just trying to roughly |
| 51 | // approximate what will block our view when on the field. |
| 52 | // If anything, we should err on the side of making obstacles too small so |
| 53 | // that if there is any error in our position, we don't assume that it must |
| 54 | // be hidden behind a target when it really is not. |
| 55 | ::std::array<Obstacle, kNumObstacles> obstacles_; |
| 56 | }; |
| 57 | |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 58 | struct Values { |
| 59 | static const int kZeroingSampleSize = 200; |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 60 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 61 | // Drivetrain Constants |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 62 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 63 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 64 | return kDrivetrainCyclesPerRevolution() * 4; |
| 65 | } |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 66 | static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); } |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 67 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 68 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 69 | control_loops::drivetrain::kHighOutputRatio / |
| 70 | constants::Values::kDrivetrainEncoderRatio() * |
| 71 | kDrivetrainEncoderCountsPerRevolution(); |
| 72 | } |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 73 | |
| 74 | // Elevator |
| 75 | static constexpr double kElevatorEncoderCountsPerRevolution() { |
| 76 | return 4096.0; |
| 77 | } |
| 78 | |
| 79 | static constexpr double kElevatorEncoderRatio() { |
| 80 | return (1.0) * control_loops::superstructure::elevator::kRadius; |
| 81 | } |
| 82 | |
| 83 | static constexpr double kMaxElevatorEncoderPulsesPerSecond() { |
| 84 | return control_loops::superstructure::elevator::kFreeSpeed * |
| 85 | control_loops::superstructure::elevator::kOutputRatio / |
| 86 | kElevatorEncoderRatio() / (2.0 * M_PI) * |
| 87 | kElevatorEncoderCountsPerRevolution(); |
| 88 | } |
| 89 | |
| 90 | static constexpr double kElevatorPotRatio() { |
| 91 | return (1.0) * control_loops::superstructure::elevator::kRadius; |
| 92 | } |
| 93 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 94 | static constexpr ::frc971::constants::Range kElevatorRange() { |
| 95 | return ::frc971::constants::Range{ |
Austin Schuh | dc9050b | 2019-02-22 20:45:12 -0800 | [diff] [blame] | 96 | -0.02, // Bottom Hard |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 97 | 1.62, // Top Hard |
| 98 | 0.01, // Bottom Soft |
| 99 | 1.59 // Top Soft |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 100 | }; |
| 101 | } |
| 102 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 103 | // Intake |
| 104 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
| 105 | |
| 106 | static constexpr double kIntakeEncoderRatio() { return (18.0 / 38.0); } |
| 107 | |
| 108 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
| 109 | return control_loops::superstructure::intake::kFreeSpeed * |
| 110 | control_loops::superstructure::intake::kOutputRatio / |
| 111 | kIntakeEncoderRatio() / (2.0 * M_PI) * |
| 112 | kIntakeEncoderCountsPerRevolution(); |
| 113 | } |
| 114 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 115 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 116 | return ::frc971::constants::Range{ |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 117 | -1.30, // Back Hard |
| 118 | 1.35, // Front Hard |
| 119 | -1.25, // Back Soft |
| 120 | 1.30 // Front Soft |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 121 | }; |
| 122 | } |
| 123 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 124 | // Wrist |
| 125 | static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; } |
| 126 | |
| 127 | static constexpr double kWristEncoderRatio() { |
| 128 | return (20.0 / 100.0) * (24.0 / 84.0); |
| 129 | } |
| 130 | |
| 131 | static constexpr double kMaxWristEncoderPulsesPerSecond() { |
| 132 | return control_loops::superstructure::wrist::kFreeSpeed * |
| 133 | control_loops::superstructure::wrist::kOutputRatio / |
| 134 | kWristEncoderRatio() / (2.0 * M_PI) * |
| 135 | kWristEncoderCountsPerRevolution(); |
| 136 | } |
| 137 | |
| 138 | static constexpr double kWristPotRatio() { return (24.0) / (84.0); } |
| 139 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 140 | static constexpr ::frc971::constants::Range kWristRange() { |
| 141 | return ::frc971::constants::Range{ |
| 142 | -3.14, // Back Hard |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 143 | 3.14, // Front Hard |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 144 | -2.97, // Back Soft |
| 145 | 2.41 // Front Soft |
| 146 | }; |
| 147 | } |
| 148 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 149 | // Stilts |
| 150 | static constexpr double kStiltsEncoderCountsPerRevolution() { return 4096.0; } |
| 151 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 152 | // Stilts Constants |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 153 | static constexpr double kStiltsEncoderRatio() { |
| 154 | return (1.0 /* Gear ratio */) * |
| 155 | control_loops::superstructure::stilts::kRadius; |
| 156 | } |
| 157 | |
| 158 | static constexpr double kMaxStiltsEncoderPulsesPerSecond() { |
| 159 | return control_loops::superstructure::stilts::kFreeSpeed * |
| 160 | control_loops::superstructure::stilts::kOutputRatio / |
| 161 | kStiltsEncoderRatio() / (2.0 * M_PI) * |
| 162 | kStiltsEncoderCountsPerRevolution(); |
| 163 | } |
| 164 | |
| 165 | static constexpr double kStiltsPotRatio() { |
| 166 | return (1.0 /* Gear ratio */) * |
| 167 | control_loops::superstructure::stilts::kRadius; |
| 168 | } |
| 169 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 170 | static constexpr ::frc971::constants::Range kStiltsRange() { |
| 171 | return ::frc971::constants::Range{ |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 172 | -0.01, // Top Hard |
| 173 | 0.72, // Bottom Hard |
| 174 | 0.00, // Top Soft |
| 175 | 0.71 // Bottom Soft |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 176 | }; |
| 177 | } |
| 178 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 179 | struct PotAndAbsConstants { |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 180 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 181 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 182 | subsystem_params; |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 183 | double potentiometer_offset; |
| 184 | }; |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 185 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 186 | PotAndAbsConstants elevator; |
| 187 | PotAndAbsConstants wrist; |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 188 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 189 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
| 190 | intake; |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 191 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 192 | PotAndAbsConstants stilts; |
James Kuszmaul | 09f564a | 2019-02-18 17:37:09 -0800 | [diff] [blame] | 193 | |
| 194 | struct CameraCalibration { |
James Kuszmaul | 09f564a | 2019-02-18 17:37:09 -0800 | [diff] [blame] | 195 | // Pose of the camera relative to the robot. |
| 196 | ::frc971::control_loops::TypedPose<double> pose; |
| 197 | // Field of view, in radians. This is total horizontal FOV, from left |
| 198 | // edge to right edge of the camera image. |
| 199 | double fov; |
| 200 | }; |
| 201 | |
| 202 | static constexpr size_t kNumCameras = 5; |
| 203 | ::std::array<CameraCalibration, kNumCameras> cameras; |
James Kuszmaul | f4ede20 | 2020-02-14 08:47:40 -0800 | [diff] [blame] | 204 | frc971::control_loops::TypedCamera<Field::kNumTargets, Field::kNumObstacles, |
| 205 | double>::NoiseParameters |
| 206 | camera_noise_parameters; |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 210 | // returns a reference to it. |
| 211 | const Values &GetValues(); |
| 212 | |
| 213 | // Creates Values instances for each team number it is called with and returns |
| 214 | // them. |
| 215 | const Values &GetValuesForTeam(uint16_t team_number); |
| 216 | |
| 217 | } // namespace constants |
| 218 | } // namespace y2019 |
| 219 | |
| 220 | #endif // Y2019_CONSTANTS_H_ |