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