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