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