Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 1 | #include "y2018/constants.h" |
| 2 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 3 | #include <cinttypes> |
| 4 | #include <cmath> |
| 5 | #include <cstdint> |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 6 | #include <map> |
| 7 | |
| 8 | #if __has_feature(address_sanitizer) |
| 9 | #include "sanitizer/lsan_interface.h" |
| 10 | #endif |
| 11 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 12 | #include "absl/log/check.h" |
| 13 | #include "absl/log/log.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 14 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 15 | #include "aos/network/team_number.h" |
Brian Silverman | 1463c09 | 2020-10-30 17:28:24 -0700 | [diff] [blame] | 16 | #include "aos/stl_mutex/stl_mutex.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 17 | #include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
| 18 | #include "y2018/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h" |
| 19 | |
| 20 | #ifndef M_PI |
| 21 | #define M_PI 3.14159265358979323846 |
| 22 | #endif |
| 23 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 24 | namespace y2018::constants { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 25 | namespace { |
| 26 | |
| 27 | const uint16_t kCompTeamNumber = 971; |
| 28 | const uint16_t kPracticeTeamNumber = 9971; |
| 29 | |
| 30 | const Values *DoGetValuesForTeam(uint16_t team) { |
| 31 | Values *const r = new Values(); |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 32 | Values::IntakeSide *const left_intake = &r->left_intake; |
| 33 | Values::IntakeSide *const right_intake = &r->right_intake; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 34 | Values::Proximal *const arm_proximal = &r->arm_proximal; |
| 35 | Values::Distal *const arm_distal = &r->arm_distal; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 36 | |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 37 | left_intake->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 38 | left_intake->zeroing.one_revolution_distance = |
| 39 | M_PI * 2.0 * constants::Values::kIntakeMotorEncoderRatio(); |
| 40 | left_intake->zeroing.zeroing_threshold = 0.0005; |
| 41 | left_intake->zeroing.moving_buffer_size = 20; |
| 42 | left_intake->zeroing.allowable_encoder_error = 1.9; |
| 43 | |
| 44 | *right_intake = *left_intake; |
| 45 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 46 | arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 47 | arm_proximal->zeroing.one_revolution_distance = |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 48 | M_PI * 2.0 * constants::Values::kProximalEncoderRatio(); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 49 | arm_proximal->zeroing.zeroing_threshold = 0.0005; |
| 50 | arm_proximal->zeroing.moving_buffer_size = 20; |
| 51 | arm_proximal->zeroing.allowable_encoder_error = 0.9; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 52 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 53 | arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 54 | arm_distal->zeroing.one_revolution_distance = |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 55 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 56 | arm_distal->zeroing.zeroing_threshold = 0.0005; |
| 57 | arm_distal->zeroing.moving_buffer_size = 20; |
| 58 | arm_distal->zeroing.allowable_encoder_error = 0.9; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 59 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame] | 60 | constexpr double kDistalZeroingPosition = |
| 61 | M_PI * 3.0 / 2.0 + (28.5 / 180.0) * M_PI; |
| 62 | // 5.209807817203074 |
| 63 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 64 | switch (team) { |
| 65 | // A set of constants for tests. |
| 66 | case 1: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 67 | r->vision_name = "test"; |
| 68 | r->vision_error = -0.030; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 69 | |
| 70 | left_intake->zeroing.measured_absolute_position = 0.0; |
| 71 | left_intake->potentiometer_offset = 0.0; |
| 72 | left_intake->spring_offset = 0.0; |
| 73 | |
| 74 | right_intake->zeroing.measured_absolute_position = 0.0; |
| 75 | right_intake->potentiometer_offset = 0.0; |
| 76 | right_intake->spring_offset = 0.0; |
| 77 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 78 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 79 | arm_proximal->potentiometer_offset = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 80 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 81 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 82 | arm_distal->potentiometer_offset = 0.0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 83 | break; |
| 84 | |
| 85 | case kCompTeamNumber: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 86 | r->vision_name = "competition"; |
| 87 | r->vision_error = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 88 | |
Sabina Davis | 9426504 | 2018-11-03 19:42:07 -0700 | [diff] [blame] | 89 | left_intake->zeroing.measured_absolute_position = 0.219024; |
| 90 | left_intake->potentiometer_offset = -5.45258 + 1.299206 - 0.525603; |
Austin Schuh | ec310a4 | 2018-05-30 20:46:48 -0700 | [diff] [blame] | 91 | left_intake->spring_offset = -0.25 - 0.009 + 0.029 - 0.025; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 92 | |
Austin Schuh | 9356ccb | 2018-04-04 20:12:31 -0700 | [diff] [blame] | 93 | right_intake->zeroing.measured_absolute_position = 0.37022 - 0.04; |
| 94 | right_intake->potentiometer_offset = 3.739919 + 1.087098 + 0.825; |
Austin Schuh | ec310a4 | 2018-05-30 20:46:48 -0700 | [diff] [blame] | 95 | right_intake->spring_offset = 0.25 + 0.015 - 0.025; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 96 | |
Austin Schuh | ef978fc | 2018-03-21 20:38:06 -0700 | [diff] [blame] | 97 | arm_proximal->zeroing.measured_absolute_position = |
Austin Schuh | ec310a4 | 2018-05-30 20:46:48 -0700 | [diff] [blame] | 98 | 0.067941 + 1.047 - 0.116 + 0.06 - 0.004 + 0.009 + 0.0938; |
Austin Schuh | 9356ccb | 2018-04-04 20:12:31 -0700 | [diff] [blame] | 99 | arm_proximal->potentiometer_offset = |
Austin Schuh | ec310a4 | 2018-05-30 20:46:48 -0700 | [diff] [blame] | 100 | 1.047 - 3.653298 + -0.078 + 0.9455 + 0.265 - 0.36; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 101 | |
Austin Schuh | ef978fc | 2018-03-21 20:38:06 -0700 | [diff] [blame] | 102 | arm_distal->zeroing.measured_absolute_position = |
Austin Schuh | ec310a4 | 2018-05-30 20:46:48 -0700 | [diff] [blame] | 103 | -0.870445 + 5.209807817203074 + 0.118 - 0.004 + 0.407 - 0.53; |
Brian Silverman | 1463c09 | 2020-10-30 17:28:24 -0700 | [diff] [blame] | 104 | arm_distal->potentiometer_offset = |
| 105 | 5.209807817203074 + 1.250476 + 0.110 + 0.52; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 106 | break; |
| 107 | |
| 108 | case kPracticeTeamNumber: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 109 | r->vision_name = "practice"; |
| 110 | r->vision_error = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 111 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame] | 112 | left_intake->zeroing.measured_absolute_position = 0.031709; |
| 113 | left_intake->potentiometer_offset = -10.55 - 3.621232 + 4.996959; |
| 114 | left_intake->spring_offset = -0.249 - 0.002; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 115 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame] | 116 | right_intake->zeroing.measured_absolute_position = 0.351376; |
| 117 | right_intake->potentiometer_offset = 9.59 + 1.530320 - 3.620648; |
Austin Schuh | 9356ccb | 2018-04-04 20:12:31 -0700 | [diff] [blame] | 118 | right_intake->spring_offset = 0.255 + 0.008 - 0.09; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 119 | |
Brian Silverman | 1463c09 | 2020-10-30 17:28:24 -0700 | [diff] [blame] | 120 | arm_proximal->zeroing.measured_absolute_position = |
| 121 | -0.253183 + 1.0652774488034022 + 0.009566448803402405; |
Austin Schuh | 0306536 | 2018-08-18 21:29:23 -0700 | [diff] [blame] | 122 | arm_proximal->potentiometer_offset = -1.242 - 0.03 - 0.1 - 1.0652; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 123 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame] | 124 | arm_distal->zeroing.measured_absolute_position = |
Brian Silverman | 1463c09 | 2020-10-30 17:28:24 -0700 | [diff] [blame] | 125 | 1.102987 - kDistalZeroingPosition + 0.12 + 0.0095 + |
| 126 | 0.22300918279692628; |
| 127 | arm_distal->potentiometer_offset = 2.772210 + M_PI + 0.434 - 0.12 + 1.25 - |
| 128 | 0.226 + 0.862067 - 0.121925182796926; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 129 | break; |
| 130 | |
| 131 | default: |
Brian Silverman | f4d329c | 2021-11-04 19:32:10 -0700 | [diff] [blame] | 132 | LOG(FATAL) << "unknown team: " << team; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | return r; |
| 136 | } |
| 137 | |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 138 | const Values &DoGetValues() { |
Austin Schuh | a8de4a6 | 2018-09-03 18:04:28 -0700 | [diff] [blame] | 139 | const uint16_t team = ::aos::network::GetTeamNumber(); |
Brian Silverman | f4d329c | 2021-11-04 19:32:10 -0700 | [diff] [blame] | 140 | LOG(INFO) << "creating a Constants for team: " << team; |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 141 | return GetValuesForTeam(team); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | } // namespace |
| 145 | |
Brian Silverman | 8d72707 | 2018-03-10 19:45:25 -0800 | [diff] [blame] | 146 | const Values &GetValues() { |
| 147 | static const Values r = DoGetValues(); |
| 148 | return r; |
| 149 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 150 | |
| 151 | const Values &GetValuesForTeam(uint16_t team_number) { |
Brian Silverman | 1463c09 | 2020-10-30 17:28:24 -0700 | [diff] [blame] | 152 | static aos::stl_mutex mutex; |
| 153 | std::unique_lock<aos::stl_mutex> locker(mutex); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 154 | |
| 155 | static ::std::map<uint16_t, const Values *> values; |
| 156 | |
| 157 | if (values.count(team_number) == 0) { |
| 158 | values[team_number] = DoGetValuesForTeam(team_number); |
| 159 | #if __has_feature(address_sanitizer) |
| 160 | __lsan_ignore_object(values[team_number]); |
| 161 | #endif |
| 162 | } |
| 163 | return *values[team_number]; |
| 164 | } |
| 165 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 166 | } // namespace y2018::constants |