Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 1 | #ifndef Y2017_CONSTANTS_H_ |
| 2 | #define Y2017_CONSTANTS_H_ |
| 3 | |
| 4 | #include <stdint.h> |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 5 | #include <math.h> |
| 6 | |
| 7 | #include "frc971/constants.h" |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 8 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 9 | #include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
| 10 | #include "y2017/control_loops/superstructure/shooter/shooter_plant.h" |
| 11 | #include "y2017/control_loops/superstructure/intake/intake_plant.h" |
| 12 | #include "y2017/control_loops/superstructure/turret/turret_plant.h" |
| 13 | #include "y2017/control_loops/superstructure/indexer/indexer_plant.h" |
| 14 | #include "y2017/control_loops/superstructure/hood/hood_plant.h" |
| 15 | |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 16 | namespace y2017 { |
| 17 | namespace constants { |
| 18 | |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 19 | // Has all of our "constants", except the ones that come from other places. The |
| 20 | // ones which change between robots are put together with a workable way to |
| 21 | // retrieve the values for the current robot. |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 22 | |
| 23 | // Everything is in SI units (volts, radians, meters, seconds, etc). |
| 24 | // Some of these values are related to the conversion between raw values |
| 25 | // (encoder counts, voltage, etc) to scaled units (radians, meters, etc). |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 26 | // |
| 27 | // All ratios are from the encoder shaft to the output units. |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 28 | |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 29 | struct Values { |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 30 | struct Intake { |
| 31 | double pot_offset; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 32 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 33 | }; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 34 | |
| 35 | struct Turret { |
| 36 | double pot_offset; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 37 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 38 | }; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 39 | |
| 40 | struct Hood { |
| 41 | double pot_offset; |
| 42 | ::frc971::constants::PotAndIndexPulseZeroingConstants zeroing; |
| 43 | }; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 44 | |
| 45 | static const int kZeroingSampleSize = 200; |
| 46 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 47 | static constexpr double kDrivetrainCyclesPerRevolution = 256; |
| 48 | static constexpr double kDrivetrainEncoderCountsPerRevolution = |
| 49 | kDrivetrainCyclesPerRevolution * 4; |
| 50 | static constexpr double kDrivetrainEncoderRatio = |
| 51 | 1.0 * control_loops::drivetrain::kWheelRadius; |
| 52 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond = |
| 53 | control_loops::drivetrain::kFreeSpeed * |
| 54 | control_loops::drivetrain::kHighOutputRatio / |
| 55 | constants::Values::kDrivetrainEncoderRatio * |
| 56 | kDrivetrainEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 57 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 58 | static constexpr double kShooterEncoderCountsPerRevolution = 2048 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 59 | static constexpr double kShooterEncoderRatio = 32.0 / 48.0; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 60 | static constexpr double kMaxShooterEncoderPulsesPerSecond = |
| 61 | control_loops::superstructure::shooter::kFreeSpeed * |
| 62 | control_loops::superstructure::shooter::kOutputRatio / |
| 63 | constants::Values::kShooterEncoderRatio * |
| 64 | kShooterEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 65 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 66 | static constexpr double kIntakeEncoderCountsPerRevolution = 1024 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 67 | static constexpr double kIntakeEncoderRatio = |
| 68 | (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254; |
| 69 | static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254; |
| 70 | static constexpr double kIntakeEncoderIndexDifference = |
| 71 | 2.0 * M_PI * kIntakeEncoderRatio; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 72 | static constexpr double kMaxIntakeEncoderPulsesPerSecond = |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame^] | 73 | control_loops::superstructure::intake::kFreeSpeed * |
| 74 | control_loops::superstructure::intake::kOutputRatio / |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 75 | constants::Values::kIntakeEncoderRatio * |
| 76 | kIntakeEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 77 | static constexpr ::frc971::constants::Range kIntakeRange{ |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 78 | -0.29878633 * 0.0254, 9.23012063 * 0.0254, (-0.29878633 + 0.125) * 0.0254, |
| 79 | (9.23012063 - 0.125) * 0.0254}; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 80 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 81 | static constexpr double kHoodEncoderCountsPerRevolution = 2048 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 82 | static constexpr double kHoodEncoderRatio = 20.0 / 345.0; |
| 83 | static constexpr double kHoodPotRatio = 20.0 / 345.0; |
| 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{ |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 91 | -0.39 * M_PI / 180.0, 37.11 * M_PI / 180.0, (-0.39 + 1.0) * M_PI / 180.0, |
| 92 | (37.11 - 1.0) * M_PI / 180.0}; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 93 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 94 | static constexpr double kTurretEncoderCountsPerRevolution = 1024 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 95 | static constexpr double kTurretEncoderRatio = 16.0 / 92.0; |
| 96 | static constexpr double kTurretPotRatio = 16.0 / 92.0; |
| 97 | static constexpr double kTurretEncoderIndexDifference = |
| 98 | 2.0 * M_PI * kTurretEncoderRatio; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 99 | static constexpr double kMaxTurretEncoderPulsesPerSecond = |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame^] | 100 | control_loops::superstructure::turret::kFreeSpeed * |
| 101 | control_loops::superstructure::turret::kOutputRatio / |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 102 | constants::Values::kTurretEncoderRatio * |
| 103 | kTurretEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 104 | static constexpr ::frc971::constants::Range kTurretRange{ |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 105 | -460.0 / 2.0 * M_PI / 180.0, 460.0 / 2.0 * M_PI / 180.0, |
| 106 | -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] | 107 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 108 | static constexpr double kMaxIndexerEncoderCountsPerRevolution = 256 * 4; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 109 | static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0); |
| 110 | static constexpr double kIndexerEncoderIndexDifference = |
| 111 | 2.0 * M_PI * kIndexerEncoderRatio; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 112 | static constexpr double kMaxIndexerEncoderPulsesPerSecond = |
| 113 | control_loops::superstructure::indexer::kFreeSpeed * |
| 114 | control_loops::superstructure::indexer::kOutputRatio / |
| 115 | constants::Values::kIndexerEncoderRatio * |
| 116 | kMaxIndexerEncoderCountsPerRevolution; |
Brian Silverman | db8498a | 2017-02-11 17:16:09 -0800 | [diff] [blame] | 117 | |
| 118 | double drivetrain_max_speed; |
| 119 | |
| 120 | Intake intake; |
| 121 | |
| 122 | Turret turret; |
| 123 | |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 124 | Hood hood; |
| 125 | |
Diana Vandenberg | 223703d | 2017-01-28 17:39:53 -0800 | [diff] [blame] | 126 | double down_error; |
Ed Jordan | 8683f43 | 2017-02-12 00:13:26 +0000 | [diff] [blame] | 127 | const char *vision_name; |
Tyler Chatow | 6107aba | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 131 | // returns a reference to it. |
| 132 | const Values &GetValues(); |
| 133 | |
| 134 | // Creates Values instances for each team number it is called with and returns |
| 135 | // them. |
| 136 | const Values &GetValuesForTeam(uint16_t team_number); |
| 137 | |
| 138 | } // namespace constants |
| 139 | } // namespace y2017 |
| 140 | |
| 141 | #endif // Y2017_CONSTANTS_H_ |