Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #include "y2023/constants.h" |
| 2 | |
| 3 | #include <cinttypes> |
| 4 | #include <map> |
| 5 | |
| 6 | #if __has_feature(address_sanitizer) |
| 7 | #include "sanitizer/lsan_interface.h" |
| 8 | #endif |
| 9 | |
| 10 | #include "absl/base/call_once.h" |
| 11 | #include "aos/mutex/mutex.h" |
| 12 | #include "aos/network/team_number.h" |
| 13 | #include "glog/logging.h" |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 14 | #include "y2023/control_loops/superstructure/roll/integral_roll_plant.h" |
| 15 | #include "y2023/control_loops/superstructure/wrist/integral_wrist_plant.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 16 | |
| 17 | namespace y2023 { |
| 18 | namespace constants { |
| 19 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 20 | Values MakeValues(uint16_t team) { |
| 21 | LOG(INFO) << "creating a Constants for team: " << team; |
| 22 | |
| 23 | Values r; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 24 | auto *const arm_proximal = &r.arm_proximal; |
| 25 | auto *const arm_distal = &r.arm_distal; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 26 | auto *const wrist = &r.wrist; |
| 27 | auto *const roll_joint = &r.roll_joint; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 28 | r.wrist_flipped = true; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 29 | |
| 30 | arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 31 | arm_proximal->zeroing.one_revolution_distance = |
| 32 | M_PI * 2.0 * constants::Values::kProximalEncoderRatio(); |
| 33 | arm_proximal->zeroing.zeroing_threshold = 0.0005; |
| 34 | arm_proximal->zeroing.moving_buffer_size = 20; |
| 35 | arm_proximal->zeroing.allowable_encoder_error = 0.9; |
| 36 | |
| 37 | arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 38 | arm_distal->zeroing.zeroing_threshold = 0.0005; |
| 39 | arm_distal->zeroing.moving_buffer_size = 20; |
| 40 | arm_distal->zeroing.allowable_encoder_error = 0.9; |
| 41 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 42 | roll_joint->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 43 | roll_joint->zeroing.one_revolution_distance = |
Austin Schuh | 1a3b817 | 2023-02-22 20:38:33 -0800 | [diff] [blame] | 44 | M_PI * 2.0 * constants::Values::kRollJointEncoderRatio(); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 45 | roll_joint->zeroing.zeroing_threshold = 0.0005; |
| 46 | roll_joint->zeroing.moving_buffer_size = 20; |
| 47 | roll_joint->zeroing.allowable_encoder_error = 0.9; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 48 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 49 | wrist->subsystem_params.zeroing_voltage = 3.0; |
| 50 | wrist->subsystem_params.operating_voltage = 12.0; |
| 51 | wrist->subsystem_params.zeroing_profile_params = {0.5, 3.0}; |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 52 | wrist->subsystem_params.default_profile_params = {0.5, 5.0}; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 53 | wrist->subsystem_params.range = Values::kCompWristRange(); |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 54 | wrist->subsystem_params.make_integral_loop = |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 55 | control_loops::superstructure::wrist::MakeIntegralWristLoop; |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 56 | wrist->subsystem_params.zeroing_constants.average_filter_size = |
| 57 | Values::kZeroingSampleSize; |
| 58 | wrist->subsystem_params.zeroing_constants.one_revolution_distance = |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 59 | M_PI * 2.0 * constants::Values::kCompWristEncoderRatio(); |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 60 | wrist->subsystem_params.zeroing_constants.zeroing_threshold = 0.0005; |
| 61 | wrist->subsystem_params.zeroing_constants.moving_buffer_size = 20; |
| 62 | wrist->subsystem_params.zeroing_constants.allowable_encoder_error = 0.9; |
| 63 | wrist->subsystem_params.zeroing_constants.middle_position = |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 64 | Values::kCompWristRange().middle(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 65 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 66 | switch (team) { |
| 67 | // A set of constants for tests. |
| 68 | case 1: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 69 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 70 | arm_proximal->potentiometer_offset = 0.0; |
| 71 | |
| 72 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 73 | arm_distal->potentiometer_offset = 0.0; |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 74 | arm_distal->zeroing.one_revolution_distance = |
| 75 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 76 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 77 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 78 | roll_joint->potentiometer_offset = 0.0; |
| 79 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 80 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 81 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 82 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 83 | break; |
| 84 | |
| 85 | case kCompTeamNumber: |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 86 | arm_proximal->zeroing.measured_absolute_position = 0.152273750996612; |
Austin Schuh | 13615bc | 2023-02-25 17:19:53 -0800 | [diff] [blame] | 87 | arm_proximal->potentiometer_offset = |
| 88 | 0.931355973012855 + 8.6743197253382 - 0.101200335326309 - |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 89 | 0.0820901660993467 - 0.0703733798337964 - 0.0294645384848748 - |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 90 | 0.577156175549626 - 0.000944609125286267; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 91 | |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 92 | arm_distal->zeroing.measured_absolute_position = 0.201204843551682; |
Austin Schuh | 6d59ffb | 2023-02-23 21:44:04 -0800 | [diff] [blame] | 93 | arm_distal->potentiometer_offset = |
| 94 | 0.436664933370656 + 0.49457213779426 + 6.78213223139724 - |
| 95 | 0.0220711555235029 - 0.0162945074111813 + 0.00630344935527365 - |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 96 | 0.0164398318919943 - 0.145833494945215 + 0.234878799868491 + |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 97 | 0.125924230298394 + 0.147136306208754 - 0.69167546169753 - |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 98 | 0.308761538844425 + 0.610386472488493 + 0.08384162885249 + 0.0262274735196811; |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 99 | |
| 100 | arm_distal->zeroing.one_revolution_distance = |
| 101 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 102 | |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 103 | roll_joint->zeroing.measured_absolute_position = 0.419144048980465; |
Austin Schuh | 7dcc49b | 2023-02-21 17:35:10 -0800 | [diff] [blame] | 104 | roll_joint->potentiometer_offset = |
Austin Schuh | 29d025c | 2023-03-03 21:41:04 -0800 | [diff] [blame] | 105 | -(3.87038557084874 - 0.0241774522172967 + 0.0711345168020632 - |
| 106 | 0.866186131631967 - 0.0256788357596952 + 0.18101759154572017 - |
| 107 | 0.0208958996127179 - 0.186395903925026 + 0.45801689548395 - |
| 108 | 0.5935210745062 + 0.166256655718334 - 0.12591438680483 + |
| 109 | 0.11972765117321 - 0.318724743041507) + |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 110 | 0.0201047336425017 - 1.0173426655158 - 0.186085272847293 - |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 111 | 0.0317706563397807 - 2.6357823523782 + 0.871932806570122; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 112 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 113 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 114 | 2.29036834725319; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 115 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 116 | break; |
| 117 | |
| 118 | case kPracticeTeamNumber: |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 119 | arm_proximal->zeroing.measured_absolute_position = 0.140348044909775; |
Henry Speiser | 30b570b | 2023-02-26 12:10:21 -0800 | [diff] [blame] | 120 | arm_proximal->potentiometer_offset = |
Austin Schuh | 95b677b | 2023-03-25 15:30:37 -0700 | [diff] [blame] | 121 | 10.5178592988554 + 0.0944609125285876 - 0.00826532984625095 + |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 122 | 0.167359305216504 + 0.135144500925909; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 123 | |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 124 | arm_distal->zeroing.measured_absolute_position = 0.860219239796068; |
Austin Schuh | 3c6e253 | 2023-03-02 21:26:35 -0800 | [diff] [blame] | 125 | arm_distal->potentiometer_offset = |
| 126 | 7.673132586937 - 0.0799284644472573 - 0.0323574039310657 + |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 127 | 0.0143810684138064 + 0.00945555248207735 + 0.452446388633863 + |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 128 | 0.0194863477007102 + 0.235993332670562 + 0.00138417783482921; |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 129 | |
| 130 | arm_distal->zeroing.one_revolution_distance = |
| 131 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio() * |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 132 | //3.11964893168338 / 3.148; |
| 133 | (3.12725165289659 + 0.002) / 3.1485739705977704; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 134 | |
Austin Schuh | 0a58a90 | 2023-04-09 14:16:15 -0700 | [diff] [blame] | 135 | roll_joint->zeroing.measured_absolute_position = 1.79390317510529; |
Austin Schuh | 3c6e253 | 2023-03-02 21:26:35 -0800 | [diff] [blame] | 136 | roll_joint->potentiometer_offset = |
| 137 | 0.624713611895747 + 3.10458504917251 - 0.0966407797407789 + |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 138 | 0.0257708772364788 - 0.0395076737853459 - 6.87914956118006 - |
James Kuszmaul | 6c90f05 | 2023-04-08 17:54:47 -0700 | [diff] [blame] | 139 | 0.097581301615046 + 3.3424421683095 - 3.97605190912604 + |
| 140 | 0.709274294168941; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 141 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 142 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
Austin Schuh | 0a58a90 | 2023-04-09 14:16:15 -0700 | [diff] [blame] | 143 | 4.68612810338484; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 144 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 145 | break; |
| 146 | |
| 147 | case kCodingRobotTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 148 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 149 | arm_proximal->potentiometer_offset = 0.0; |
| 150 | |
| 151 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 152 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 153 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 154 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 155 | roll_joint->potentiometer_offset = 0.0; |
| 156 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 157 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 158 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 159 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 160 | break; |
| 161 | |
| 162 | default: |
| 163 | LOG(FATAL) << "unknown team: " << team; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 164 | |
| 165 | // TODO(milind): add pot range checks once we add ranges |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | return r; |
| 169 | } |
| 170 | |
| 171 | Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); } |
| 172 | |
| 173 | } // namespace constants |
| 174 | } // namespace y2023 |