Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 1 | #ifndef Y2018_CONSTANTS_H_ |
| 2 | #define Y2018_CONSTANTS_H_ |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <math.h> |
| 6 | |
| 7 | #include "frc971/constants.h" |
| 8 | |
| 9 | #include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
| 10 | #include "y2018/control_loops/superstructure/arm/dynamics.h" |
| 11 | #include "y2018/control_loops/superstructure/intake/intake_plant.h" |
| 12 | |
| 13 | namespace y2018 { |
| 14 | namespace constants { |
| 15 | |
| 16 | // Has all of our "constants", except the ones that come from other places. The |
| 17 | // ones which change between robots are put together with a workable way to |
| 18 | // retrieve the values for the current robot. |
| 19 | |
| 20 | // Everything is in SI units (volts, radians, meters, seconds, etc). |
| 21 | // Some of these values are related to the conversion between raw values |
| 22 | // (encoder counts, voltage, etc) to scaled units (radians, meters, etc). |
| 23 | // |
| 24 | // All ratios are from the encoder shaft to the output units. |
| 25 | |
| 26 | struct Values { |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 27 | static constexpr size_t kZeroingSampleSize() { return 200; } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 28 | |
| 29 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 30 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 31 | return kDrivetrainCyclesPerRevolution() * 4; |
| 32 | } |
| 33 | static constexpr double kDrivetrainEncoderRatio() { |
| 34 | return (20.0 / 48.0) * (30.0 / 36.0); |
| 35 | } |
| 36 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 37 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 38 | control_loops::drivetrain::kHighOutputRatio / |
| 39 | constants::Values::kDrivetrainEncoderRatio() * |
| 40 | kDrivetrainEncoderCountsPerRevolution(); |
| 41 | } |
| 42 | |
Austin Schuh | 17dd089 | 2018-03-02 20:06:31 -0800 | [diff] [blame] | 43 | static constexpr double kDrivetrainShifterPotMaxVoltage() { return 3.63; } |
| 44 | static constexpr double kDrivetrainShifterPotMinVoltage() { return 1.94; } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 45 | |
| 46 | static constexpr double kProximalEncoderCountsPerRevolution() { return 4096.0; } |
| 47 | static constexpr double kProximalEncoderRatio() { |
| 48 | return (12.0 / 60.0) * (18.0 / 84.0); |
| 49 | } |
| 50 | static constexpr double kMaxProximalEncoderPulsesPerSecond() { |
| 51 | return control_loops::superstructure::arm::Dynamics::kFreeSpeed / |
| 52 | (2.0 * M_PI) / control_loops::superstructure::arm::Dynamics::kG1 / |
| 53 | kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
| 54 | } |
| 55 | static constexpr double kProximalPotRatio() { return (12.0 / 60.0); } |
| 56 | |
| 57 | static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; } |
| 58 | static constexpr double kDistalEncoderRatio() { return (12.0 / 60.0); } |
| 59 | static constexpr double kMaxDistalEncoderPulsesPerSecond() { |
| 60 | return control_loops::superstructure::arm::Dynamics::kFreeSpeed / |
| 61 | (2.0 * M_PI) / control_loops::superstructure::arm::Dynamics::kG2 / |
| 62 | kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
| 63 | } |
| 64 | static constexpr double kDistalPotRatio() { |
| 65 | return (12.0 / 60.0) * (36.0 / 40.0); |
| 66 | } |
| 67 | |
| 68 | static constexpr double kIntakeSpringRatio() { |
| 69 | return (10.0 * 0.080) / (2.0 * 1.5 * M_PI); |
| 70 | } |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 71 | static constexpr double kIntakeMotorEncoderCountsPerRevolution() { |
| 72 | return 4096.0; |
| 73 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 74 | static constexpr double kIntakeMotorEncoderRatio() { |
| 75 | return (18.0 / 68.0) * (18.0 / 50.0); |
| 76 | } |
| 77 | static constexpr double kIntakeMotorPotRatio() { return (14.0 / 68.0); } |
| 78 | static constexpr double kMaxIntakeMotorEncoderPulsesPerSecond() { |
| 79 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
| 80 | control_loops::superstructure::intake::kGearRatio / |
| 81 | kIntakeMotorEncoderRatio() * |
| 82 | kIntakeMotorEncoderCountsPerRevolution(); |
| 83 | } |
| 84 | |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 85 | static constexpr ::frc971::constants::Range kIntakeRange() { |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 86 | // TODO(austin) Sort this out. |
Austin Schuh | f88d3ac | 2018-03-05 00:26:36 -0800 | [diff] [blame] | 87 | return ::frc971::constants::Range{-3.7, (1.25 * M_PI), |
| 88 | -3.3, M_PI}; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | struct IntakeSide { |
| 92 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
| 93 | double potentiometer_offset; |
| 94 | double spring_offset; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 95 | }; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 96 | IntakeSide left_intake; |
| 97 | IntakeSide right_intake; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 98 | |
| 99 | struct Proximal { |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 100 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
| 101 | double potentiometer_offset; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 102 | }; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 103 | Proximal arm_proximal; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 104 | |
| 105 | struct Distal { |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 106 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
| 107 | double potentiometer_offset; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 108 | }; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 109 | Distal arm_distal; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 110 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 111 | const char *vision_name; |
| 112 | |
| 113 | double vision_error; |
| 114 | }; |
| 115 | |
| 116 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 117 | // returns a reference to it. |
| 118 | const Values &GetValues(); |
| 119 | |
| 120 | // Creates Values instances for each team number it is called with and returns |
| 121 | // them. |
| 122 | const Values &GetValuesForTeam(uint16_t team_number); |
| 123 | |
| 124 | } // namespace constants |
| 125 | } // namespace y2018 |
| 126 | |
| 127 | #endif // Y2018_CONSTANTS_H_ |