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" |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame^] | 13 | #include "y2020/control_loops/superstructure/control_panel/control_panel_plant.h" |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 14 | #include "y2020/control_loops/superstructure/hood/hood_plant.h" |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 15 | #include "y2020/control_loops/superstructure/intake/intake_plant.h" |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 16 | #include "y2020/control_loops/superstructure/turret/turret_plant.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 17 | |
| 18 | namespace y2020 { |
| 19 | namespace constants { |
| 20 | |
| 21 | struct Values { |
| 22 | static const int kZeroingSampleSize = 200; |
| 23 | |
| 24 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 25 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 26 | return kDrivetrainCyclesPerRevolution() * 4; |
| 27 | } |
| 28 | static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); } |
| 29 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 30 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 31 | control_loops::drivetrain::kHighOutputRatio / |
| 32 | constants::Values::kDrivetrainEncoderRatio() * |
| 33 | kDrivetrainEncoderCountsPerRevolution(); |
| 34 | } |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 35 | |
| 36 | // Hood |
| 37 | static constexpr double kHoodEncoderCountsPerRevolution() { return 4096.0; } |
| 38 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 39 | // TODO(sabina): Update constants |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 40 | static constexpr double kHoodEncoderRatio() { return 1.0; } |
| 41 | |
| 42 | static constexpr double kMaxHoodEncoderPulsesPerSecond() { |
| 43 | return control_loops::superstructure::hood::kFreeSpeed * |
| 44 | control_loops::superstructure::hood::kOutputRatio / |
| 45 | kHoodEncoderRatio() / (2.0 * M_PI) * |
| 46 | kHoodEncoderCountsPerRevolution(); |
| 47 | } |
| 48 | |
| 49 | static constexpr ::frc971::constants::Range kHoodRange() { |
| 50 | return ::frc971::constants::Range{ |
| 51 | 0.00, // Back Hard |
| 52 | 0.79, // Front Hard |
| 53 | 0.14, // Back Soft |
| 54 | 0.78 // Front Soft |
| 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() { |
| 68 | return control_loops::superstructure::intake::kFreeSpeed * |
| 69 | control_loops::superstructure::intake::kOutputRatio / |
| 70 | kIntakeEncoderRatio() / (2.0 * M_PI) * |
| 71 | kIntakeEncoderCountsPerRevolution(); |
| 72 | } |
| 73 | |
| 74 | // TODO(sabina): update range |
| 75 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 76 | return ::frc971::constants::Range{ |
| 77 | -1, // Back Hard |
| 78 | 1, // Front Hard |
| 79 | -0.95, // Back Soft |
| 80 | 0.95 // Front Soft |
| 81 | }; |
| 82 | } |
| 83 | |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 84 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 85 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 86 | intake; |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 87 | |
| 88 | // Turret |
| 89 | static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; } |
| 90 | |
| 91 | static constexpr double kTurretEncoderRatio() { |
| 92 | return 1.0; // TODO (Kai): Get Gear Ratios when ready |
| 93 | } |
| 94 | |
| 95 | static constexpr double kMaxTurretEncoderPulsesPerSecond() { |
| 96 | return control_loops::superstructure::turret::kFreeSpeed * |
| 97 | control_loops::superstructure::turret::kOutputRatio / |
| 98 | kTurretEncoderRatio() / (2.0 * M_PI) * |
| 99 | kTurretEncoderCountsPerRevolution(); |
| 100 | } |
| 101 | |
| 102 | // TODO(austin): Figure out the actual constant here. |
| 103 | static constexpr double kTurretPotRatio() { return 1.0; } |
| 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() { |
| 135 | return control_loops::superstructure::control_panel::kFreeSpeed * |
| 136 | control_loops::superstructure::control_panel::kOutputRatio / |
| 137 | kControlPanelEncoderRatio() / (2.0 * M_PI) * |
| 138 | kControlPanelEncoderCountsPerRevolution(); |
| 139 | } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 143 | // returns a reference to it. |
| 144 | const Values &GetValues(); |
| 145 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 146 | // Creates Values instances for each team number it is called with and |
| 147 | // returns them. |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 148 | const Values &GetValuesForTeam(uint16_t team_number); |
| 149 | |
| 150 | } // namespace constants |
| 151 | } // namespace y2020 |
| 152 | |
| 153 | #endif // y2020_CONSTANTS_H_ |