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