Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 1 | #ifndef y2020_CONSTANTS_H_ |
| 2 | #define y2020_CONSTANTS_H_ |
| 3 | |
| 4 | #include <math.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #include <array> |
| 8 | |
| 9 | #include "frc971/constants.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 10 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
| 11 | #include "y2020/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 12 | #include "y2020/control_loops/superstructure/accelerator/accelerator_plant.h" |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 13 | #include "y2020/control_loops/superstructure/control_panel/control_panel_plant.h" |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 14 | #include "y2020/control_loops/superstructure/finisher/finisher_plant.h" |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 15 | #include "y2020/control_loops/superstructure/hood/hood_plant.h" |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 16 | #include "y2020/control_loops/superstructure/intake/intake_plant.h" |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 17 | #include "y2020/control_loops/superstructure/turret/turret_plant.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 18 | |
| 19 | namespace y2020 { |
| 20 | namespace constants { |
| 21 | |
| 22 | struct Values { |
Austin Schuh | 83873c3 | 2020-02-22 14:58:39 -0800 | [diff] [blame] | 23 | static const uint16_t kCodingRobotTeamNumber = 7971; |
| 24 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 25 | static const int kZeroingSampleSize = 200; |
| 26 | |
| 27 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 28 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 29 | return kDrivetrainCyclesPerRevolution() * 4; |
| 30 | } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 31 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 32 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 33 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 34 | control_loops::drivetrain::kHighGearRatio / |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 35 | constants::Values::kDrivetrainEncoderRatio() * |
| 36 | kDrivetrainEncoderCountsPerRevolution(); |
| 37 | } |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 38 | |
| 39 | // Hood |
| 40 | static constexpr double kHoodEncoderCountsPerRevolution() { return 4096.0; } |
| 41 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 42 | static constexpr double kHoodEncoderRatio() { |
| 43 | // TODO: This math is not quite right |
| 44 | // 10.211 in of travel gets you 1 radian on the output |
| 45 | const double radians_per_in_travel = 1.0 / 10.211; |
| 46 | |
Austin Schuh | 72a878d | 2021-03-06 20:16:06 -0800 | [diff] [blame] | 47 | // one turn on the leadscrew gets you 0.5 in travel |
| 48 | const double in_travel_per_radian = 0.5 / (2.0 * M_PI); |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 49 | |
| 50 | // units reduce; radians on the encoder * this number = radians on the hood |
Austin Schuh | 72a878d | 2021-03-06 20:16:06 -0800 | [diff] [blame] | 51 | return in_travel_per_radian * radians_per_in_travel; |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static constexpr double kHoodSingleTurnEncoderRatio() { return 8.0 / 72.0; } |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 55 | |
| 56 | static constexpr double kMaxHoodEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 57 | return control_loops::superstructure::hood::kFreeSpeed / (2.0 * M_PI) * |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 58 | control_loops::superstructure::hood::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 59 | kHoodEncoderRatio() * kHoodEncoderCountsPerRevolution(); |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static constexpr ::frc971::constants::Range kHoodRange() { |
| 63 | return ::frc971::constants::Range{ |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 64 | -0.01, // Back Hard |
| 65 | 0.65, // Front Hard |
| 66 | 0.00, // Back Soft |
| 67 | 0.63 // Front Soft |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 68 | }; |
| 69 | } |
| 70 | |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 71 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 72 | ::frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator> |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 73 | hood; |
| 74 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 75 | // Intake |
| 76 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
| 77 | |
| 78 | static constexpr double kIntakeEncoderRatio() { return (16.0 / 32.0); } |
| 79 | |
| 80 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 81 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 82 | control_loops::superstructure::intake::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 83 | kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution(); |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 86 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 87 | return ::frc971::constants::Range{ |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 88 | -1.05, // Back Hard |
| 89 | 1.44, // Front Hard |
| 90 | -0.89, // Back Soft |
| 91 | 1.26 // Front Soft |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 92 | }; |
| 93 | } |
| 94 | |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 95 | static constexpr double kIntakeZero() { return -57 * M_PI / 180.0; } |
| 96 | |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 97 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 98 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 99 | intake; |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 100 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 101 | static constexpr double kIntakeRollerSupplyCurrentLimit() { return 30.0; } |
| 102 | static constexpr double kIntakeRollerStatorCurrentLimit() { return 40.0; } |
| 103 | |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 104 | static constexpr double kFeederSupplyCurrentLimit() { return 30.0; } |
| 105 | static constexpr double kFeederStatorCurrentLimit() { return 40.0; } |
| 106 | |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 107 | // Turret |
| 108 | static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; } |
| 109 | |
| 110 | static constexpr double kTurretEncoderRatio() { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 111 | return (26.0 / 150.0) * (130.0 / 26.0); |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static constexpr double kMaxTurretEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 115 | return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) * |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 116 | control_loops::superstructure::turret::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 117 | kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution(); |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 120 | static constexpr double kTurretPotRatio() { return (26.0 / 150.0); } |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 121 | |
| 122 | static constexpr ::frc971::constants::Range kTurretRange() { |
| 123 | return ::frc971::constants::Range{ |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 124 | -4.6, // Back Hard |
| 125 | 4.85, // Front Hard |
| 126 | -4.3, // Back Soft |
| 127 | 4.7123 // Front Soft |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 128 | }; |
| 129 | } |
| 130 | |
| 131 | struct PotAndAbsEncoderConstants { |
| 132 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 133 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 134 | subsystem_params; |
| 135 | double potentiometer_offset; |
| 136 | }; |
| 137 | |
| 138 | PotAndAbsEncoderConstants turret; |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 139 | |
| 140 | // Control Panel |
| 141 | |
| 142 | // Mag encoder |
| 143 | static constexpr double kControlPanelEncoderCountsPerRevolution() { |
| 144 | return 4096.0; |
| 145 | } |
| 146 | |
| 147 | // Ratio is encoder to output |
| 148 | static constexpr double kControlPanelEncoderRatio() { return (56.0 / 28.0); } |
| 149 | |
| 150 | static constexpr double kMaxControlPanelEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 151 | return control_loops::superstructure::control_panel::kFreeSpeed / |
| 152 | (2.0 * M_PI) * |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 153 | control_loops::superstructure::control_panel::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 154 | kControlPanelEncoderRatio() * |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 155 | kControlPanelEncoderCountsPerRevolution(); |
| 156 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 157 | |
| 158 | // Shooter |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 159 | static constexpr double kFinisherEncoderCountsPerRevolution() { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 160 | return 2048.0; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 161 | } |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 162 | static constexpr double kFinisherEncoderRatio() { return 36.0 / 40.0; } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 163 | |
| 164 | static constexpr double kMaxFinisherEncoderPulsesPerSecond() { |
| 165 | return control_loops::superstructure::finisher::kFreeSpeed / (2.0 * M_PI) * |
| 166 | control_loops::superstructure::finisher::kOutputRatio / |
| 167 | kFinisherEncoderRatio() * kFinisherEncoderCountsPerRevolution(); |
| 168 | } |
| 169 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 170 | static constexpr double kAcceleratorEncoderCountsPerRevolution() { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 171 | return 2048.0; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 172 | } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 173 | static constexpr double kAcceleratorEncoderRatio() { |
| 174 | return (1.2 * 1.2 * 1.2) * (30.0 / 40.0); |
| 175 | } |
| 176 | |
| 177 | static constexpr double kMaxAcceleratorEncoderPulsesPerSecond() { |
| 178 | return control_loops::superstructure::accelerator::kFreeSpeed / |
| 179 | (2.0 * M_PI) * |
| 180 | control_loops::superstructure::accelerator::kOutputRatio / |
| 181 | kAcceleratorEncoderRatio() * |
| 182 | kAcceleratorEncoderCountsPerRevolution(); |
| 183 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 184 | |
| 185 | // Climber |
| 186 | static constexpr double kClimberSupplyCurrentLimit() { return 60.0; } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 190 | // returns a reference to it. |
| 191 | const Values &GetValues(); |
| 192 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 193 | // Creates Values instances for each team number it is called with and |
| 194 | // returns them. |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 195 | const Values &GetValuesForTeam(uint16_t team_number); |
| 196 | |
| 197 | } // namespace constants |
| 198 | } // namespace y2020 |
| 199 | |
| 200 | #endif // y2020_CONSTANTS_H_ |