Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 1 | #ifndef Y2017_CONSTANTS_H_ |
| 2 | #define Y2017_CONSTANTS_H_ |
| 3 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 4 | #include <cmath> |
| 5 | #include <cstdint> |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 6 | |
| 7 | #include "frc971/constants.h" |
Philipp Schrader | 9a83336 | 2017-04-09 22:56:16 +0000 | [diff] [blame] | 8 | #include "frc971/shooter_interpolation/interpolation.h" |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 9 | #include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 10 | #include "y2017/control_loops/superstructure/column/column_plant.h" |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 11 | #include "y2017/control_loops/superstructure/hood/hood_plant.h" |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 12 | #include "y2017/control_loops/superstructure/intake/intake_plant.h" |
| 13 | #include "y2017/control_loops/superstructure/shooter/shooter_plant.h" |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 14 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 15 | namespace y2017::constants { |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 16 | |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 17 | // Has all of our "constants", except the ones that come from other places. The |
| 18 | // ones which change between robots are put together with a workable way to |
| 19 | // retrieve the values for the current robot. |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 20 | |
| 21 | // Everything is in SI units (volts, radians, meters, seconds, etc). |
| 22 | // Some of these values are related to the conversion between raw values |
| 23 | // (encoder counts, voltage, etc) to scaled units (radians, meters, etc). |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 24 | // |
| 25 | // All ratios are from the encoder shaft to the output units. |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 26 | |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 27 | struct Values { |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 28 | struct Intake { |
| 29 | double pot_offset; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 30 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 31 | }; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 32 | |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 33 | struct Hood { |
| 34 | double pot_offset; |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 35 | ::frc971::constants::EncoderPlusIndexZeroingConstants zeroing; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 36 | }; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 37 | |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 38 | struct Column { |
| 39 | ::frc971::constants::HallEffectZeroingConstants indexer_zeroing; |
| 40 | ::frc971::constants::HallEffectZeroingConstants turret_zeroing; |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 41 | // The max absolute value of the turret angle that we need to get to to be |
| 42 | // classified as zeroed. Otherwise, we may be ambiguous on which wrap we |
| 43 | // are on. |
| 44 | double turret_zeroed_distance; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 47 | static const int kZeroingSampleSize = 200; |
| 48 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 49 | static constexpr double kDrivetrainCyclesPerRevolution = 256; |
| 50 | static constexpr double kDrivetrainEncoderCountsPerRevolution = |
| 51 | kDrivetrainCyclesPerRevolution * 4; |
| 52 | static constexpr double kDrivetrainEncoderRatio = |
| 53 | 1.0 * control_loops::drivetrain::kWheelRadius; |
| 54 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond = |
| 55 | control_loops::drivetrain::kFreeSpeed * |
| 56 | control_loops::drivetrain::kHighOutputRatio / |
| 57 | constants::Values::kDrivetrainEncoderRatio * |
| 58 | kDrivetrainEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 59 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 60 | static constexpr double kShooterEncoderCountsPerRevolution = 2048 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 61 | static constexpr double kShooterEncoderRatio = 32.0 / 48.0; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 62 | static constexpr double kMaxShooterEncoderPulsesPerSecond = |
| 63 | control_loops::superstructure::shooter::kFreeSpeed * |
| 64 | control_loops::superstructure::shooter::kOutputRatio / |
| 65 | constants::Values::kShooterEncoderRatio * |
| 66 | kShooterEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 67 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 68 | static constexpr double kIntakeEncoderCountsPerRevolution = 1024 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 69 | static constexpr double kIntakeEncoderRatio = |
| 70 | (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254; |
| 71 | static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254; |
| 72 | static constexpr double kIntakeEncoderIndexDifference = |
| 73 | 2.0 * M_PI * kIntakeEncoderRatio; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 74 | static constexpr double kMaxIntakeEncoderPulsesPerSecond = |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 75 | control_loops::superstructure::intake::kFreeSpeed * |
| 76 | control_loops::superstructure::intake::kOutputRatio / |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 77 | constants::Values::kIntakeEncoderRatio * |
| 78 | kIntakeEncoderCountsPerRevolution; |
Austin Schuh | 53a2c45 | 2017-03-22 21:18:20 -0700 | [diff] [blame] | 79 | static constexpr ::frc971::constants::Range kIntakeRange{-0.01, 0.250, 0.01, |
| 80 | 0.235}; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 81 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 82 | static constexpr double kHoodEncoderCountsPerRevolution = 2048 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 83 | static constexpr double kHoodEncoderRatio = 20.0 / 345.0; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 84 | static constexpr double kHoodEncoderIndexDifference = |
| 85 | 2.0 * M_PI * kHoodEncoderRatio; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 86 | static constexpr double kMaxHoodEncoderPulsesPerSecond = |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 87 | control_loops::superstructure::hood::kFreeSpeed * |
| 88 | control_loops::superstructure::hood::kOutputRatio / |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 89 | constants::Values::kHoodEncoderRatio * kHoodEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 90 | static constexpr ::frc971::constants::Range kHoodRange{ |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 91 | -0.39 * M_PI / 180.0 - 0.01, 37.11 * M_PI / 180.0, |
| 92 | (-0.39 + 1.0) * M_PI / 180.0, (37.11 - 1.0) * M_PI / 180.0}; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 93 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 94 | static constexpr double kTurretEncoderCountsPerRevolution = 256 * 4; |
| 95 | static constexpr double kTurretEncoderRatio = 11.0 / 94.0; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 96 | static constexpr double kMaxTurretEncoderPulsesPerSecond = |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 97 | control_loops::superstructure::column::kTurretFreeSpeed * |
| 98 | control_loops::superstructure::column::kTurretOutputRatio / |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 99 | constants::Values::kTurretEncoderRatio * |
| 100 | kTurretEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 101 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 102 | static constexpr double kIndexerEncoderCountsPerRevolution = 256 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 103 | static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0); |
| 104 | static constexpr double kIndexerEncoderIndexDifference = |
| 105 | 2.0 * M_PI * kIndexerEncoderRatio; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 106 | static constexpr double kMaxIndexerEncoderPulsesPerSecond = |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 107 | control_loops::superstructure::column::kIndexerFreeSpeed * |
| 108 | control_loops::superstructure::column::kIndexerOutputRatio / |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 109 | constants::Values::kIndexerEncoderRatio * |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 110 | kIndexerEncoderCountsPerRevolution; |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 111 | static constexpr ::frc971::constants::Range kTurretRange{ |
| 112 | -460.0 / 2.0 * M_PI / 180.0, 460.0 / 2.0 * M_PI / 180.0, |
| 113 | -450.0 / 2.0 * M_PI / 180.0, 450.0 / 2.0 * M_PI / 180.0}; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 114 | |
| 115 | double drivetrain_max_speed; |
| 116 | |
| 117 | Intake intake; |
| 118 | |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 119 | Column column; |
| 120 | |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 121 | Hood hood; |
| 122 | |
Diana Vandenberg | 223703d | 2017-01-28 17:39:53 -0800 | [diff] [blame] | 123 | double down_error; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 124 | const char *vision_name; |
Austin Schuh | 25db126 | 2017-04-05 19:39:55 -0700 | [diff] [blame] | 125 | |
| 126 | double vision_error; |
Philipp Schrader | 9a83336 | 2017-04-09 22:56:16 +0000 | [diff] [blame] | 127 | |
Parker Schuh | 94d5679 | 2017-04-13 20:32:50 -0700 | [diff] [blame] | 128 | struct ShotParams { |
| 129 | double angle; |
| 130 | double power; |
| 131 | double indexer_velocity; |
| 132 | |
| 133 | static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2); |
| 134 | }; |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 138 | // returns a reference to it. |
| 139 | const Values &GetValues(); |
| 140 | |
| 141 | // Creates Values instances for each team number it is called with and returns |
| 142 | // them. |
| 143 | const Values &GetValuesForTeam(uint16_t team_number); |
| 144 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 145 | } // namespace y2017::constants |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 146 | |
| 147 | #endif // Y2017_CONSTANTS_H_ |