Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 1 | #ifndef Y2019_CONSTANTS_H_ |
| 2 | #define Y2019_CONSTANTS_H_ |
| 3 | |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 4 | #include <math.h> |
Sabina Davis | 1b84afa | 2019-02-09 01:20:21 -0800 | [diff] [blame] | 5 | #include <stdint.h> |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 6 | |
| 7 | #include "frc971/constants.h" |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 8 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 9 | #include "y2019/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 10 | #include "y2019/control_loops/superstructure/elevator/elevator_plant.h" |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 11 | #include "y2019/control_loops/superstructure/intake/intake_plant.h" |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 12 | #include "y2019/control_loops/superstructure/stilts/stilts_plant.h" |
| 13 | #include "y2019/control_loops/superstructure/wrist/wrist_plant.h" |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 14 | |
| 15 | namespace y2019 { |
| 16 | namespace constants { |
| 17 | |
| 18 | // Has all of our "constants", except the ones that come from other places. The |
| 19 | // ones which change between robots are put together with a workable way to |
| 20 | // retrieve the values for the current robot. |
| 21 | |
| 22 | // Everything is in SI units (volts, radians, meters, seconds, etc). |
| 23 | // Some of these values are related to the conversion between raw values |
| 24 | // (encoder counts, voltage, etc) to scaled units (radians, meters, etc). |
| 25 | // |
| 26 | // All ratios are from the encoder shaft to the output units. |
| 27 | |
| 28 | struct Values { |
| 29 | static const int kZeroingSampleSize = 200; |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 30 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 31 | // Drivetrain Constants |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 32 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 33 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 34 | return kDrivetrainCyclesPerRevolution() * 4; |
| 35 | } |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 36 | static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); } |
Sabina Davis | 7be49f3 | 2019-02-02 00:30:19 -0800 | [diff] [blame] | 37 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 38 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 39 | control_loops::drivetrain::kHighOutputRatio / |
| 40 | constants::Values::kDrivetrainEncoderRatio() * |
| 41 | kDrivetrainEncoderCountsPerRevolution(); |
| 42 | } |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 43 | |
| 44 | // Elevator |
| 45 | static constexpr double kElevatorEncoderCountsPerRevolution() { |
| 46 | return 4096.0; |
| 47 | } |
| 48 | |
| 49 | static constexpr double kElevatorEncoderRatio() { |
| 50 | return (1.0) * control_loops::superstructure::elevator::kRadius; |
| 51 | } |
| 52 | |
| 53 | static constexpr double kMaxElevatorEncoderPulsesPerSecond() { |
| 54 | return control_loops::superstructure::elevator::kFreeSpeed * |
| 55 | control_loops::superstructure::elevator::kOutputRatio / |
| 56 | kElevatorEncoderRatio() / (2.0 * M_PI) * |
| 57 | kElevatorEncoderCountsPerRevolution(); |
| 58 | } |
| 59 | |
| 60 | static constexpr double kElevatorPotRatio() { |
| 61 | return (1.0) * control_loops::superstructure::elevator::kRadius; |
| 62 | } |
| 63 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 64 | static constexpr ::frc971::constants::Range kElevatorRange() { |
| 65 | return ::frc971::constants::Range{ |
| 66 | 0.0, // Bottom Hard |
| 67 | 1.44, // Top Hard |
| 68 | 0.025, // Bottom Soft |
| 69 | 1.415 // Top Soft |
| 70 | }; |
| 71 | } |
| 72 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 73 | // Intake |
| 74 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
| 75 | |
| 76 | static constexpr double kIntakeEncoderRatio() { return (18.0 / 38.0); } |
| 77 | |
| 78 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
| 79 | return control_loops::superstructure::intake::kFreeSpeed * |
| 80 | control_loops::superstructure::intake::kOutputRatio / |
| 81 | kIntakeEncoderRatio() / (2.0 * M_PI) * |
| 82 | kIntakeEncoderCountsPerRevolution(); |
| 83 | } |
| 84 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 85 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 86 | return ::frc971::constants::Range{ |
| 87 | -1.15, // Back Hard |
| 88 | 1.36, // Front Hard |
| 89 | -1.14, // Back Soft |
| 90 | 1.22 // Front Soft |
| 91 | }; |
| 92 | } |
| 93 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 94 | // Wrist |
| 95 | static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; } |
| 96 | |
| 97 | static constexpr double kWristEncoderRatio() { |
| 98 | return (20.0 / 100.0) * (24.0 / 84.0); |
| 99 | } |
| 100 | |
| 101 | static constexpr double kMaxWristEncoderPulsesPerSecond() { |
| 102 | return control_loops::superstructure::wrist::kFreeSpeed * |
| 103 | control_loops::superstructure::wrist::kOutputRatio / |
| 104 | kWristEncoderRatio() / (2.0 * M_PI) * |
| 105 | kWristEncoderCountsPerRevolution(); |
| 106 | } |
| 107 | |
| 108 | static constexpr double kWristPotRatio() { return (24.0) / (84.0); } |
| 109 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 110 | static constexpr ::frc971::constants::Range kWristRange() { |
| 111 | return ::frc971::constants::Range{ |
| 112 | -3.14, // Back Hard |
| 113 | 2.58, // Front Hard |
| 114 | -2.97, // Back Soft |
| 115 | 2.41 // Front Soft |
| 116 | }; |
| 117 | } |
| 118 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 119 | // Stilts |
| 120 | static constexpr double kStiltsEncoderCountsPerRevolution() { return 4096.0; } |
| 121 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 122 | // Stilts Constants |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 123 | static constexpr double kStiltsEncoderRatio() { |
| 124 | return (1.0 /* Gear ratio */) * |
| 125 | control_loops::superstructure::stilts::kRadius; |
| 126 | } |
| 127 | |
| 128 | static constexpr double kMaxStiltsEncoderPulsesPerSecond() { |
| 129 | return control_loops::superstructure::stilts::kFreeSpeed * |
| 130 | control_loops::superstructure::stilts::kOutputRatio / |
| 131 | kStiltsEncoderRatio() / (2.0 * M_PI) * |
| 132 | kStiltsEncoderCountsPerRevolution(); |
| 133 | } |
| 134 | |
| 135 | static constexpr double kStiltsPotRatio() { |
| 136 | return (1.0 /* Gear ratio */) * |
| 137 | control_loops::superstructure::stilts::kRadius; |
| 138 | } |
| 139 | |
Austin Schuh | 7c473cb | 2019-02-10 14:49:19 -0800 | [diff] [blame] | 140 | static constexpr ::frc971::constants::Range kStiltsRange() { |
| 141 | return ::frc971::constants::Range{ |
| 142 | -0.026, // Top Hard |
| 143 | 0.693, // Bottom Hard |
| 144 | -0.02, // Top Soft |
| 145 | 0.673 // Bottom Soft |
| 146 | }; |
| 147 | } |
| 148 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 149 | struct PotAndAbsConstants { |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 150 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 151 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 152 | subsystem_params; |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 153 | double potentiometer_offset; |
| 154 | }; |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 155 | |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 156 | PotAndAbsConstants elevator; |
| 157 | PotAndAbsConstants wrist; |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 158 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 159 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
| 160 | intake; |
Alex Perry | 5fb5ff2 | 2019-02-09 21:53:17 -0800 | [diff] [blame] | 161 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame^] | 162 | PotAndAbsConstants stilts; |
Tyler Chatow | 37ecdcd | 2019-01-26 20:18:42 -0800 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber() and |
| 166 | // returns a reference to it. |
| 167 | const Values &GetValues(); |
| 168 | |
| 169 | // Creates Values instances for each team number it is called with and returns |
| 170 | // them. |
| 171 | const Values &GetValuesForTeam(uint16_t team_number); |
| 172 | |
| 173 | } // namespace constants |
| 174 | } // namespace y2019 |
| 175 | |
| 176 | #endif // Y2019_CONSTANTS_H_ |