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; |
| 38 | arm_distal->zeroing.one_revolution_distance = |
| 39 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
| 40 | arm_distal->zeroing.zeroing_threshold = 0.0005; |
| 41 | arm_distal->zeroing.moving_buffer_size = 20; |
| 42 | arm_distal->zeroing.allowable_encoder_error = 0.9; |
| 43 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 44 | roll_joint->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 45 | roll_joint->zeroing.one_revolution_distance = |
Austin Schuh | 1a3b817 | 2023-02-22 20:38:33 -0800 | [diff] [blame] | 46 | M_PI * 2.0 * constants::Values::kRollJointEncoderRatio(); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 47 | roll_joint->zeroing.zeroing_threshold = 0.0005; |
| 48 | roll_joint->zeroing.moving_buffer_size = 20; |
| 49 | roll_joint->zeroing.allowable_encoder_error = 0.9; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 50 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 51 | wrist->subsystem_params.zeroing_voltage = 3.0; |
| 52 | wrist->subsystem_params.operating_voltage = 12.0; |
| 53 | wrist->subsystem_params.zeroing_profile_params = {0.5, 3.0}; |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 54 | wrist->subsystem_params.default_profile_params = {0.5, 5.0}; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 55 | wrist->subsystem_params.range = Values::kCompWristRange(); |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 56 | wrist->subsystem_params.make_integral_loop = |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 57 | control_loops::superstructure::wrist::MakeIntegralWristLoop; |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 58 | wrist->subsystem_params.zeroing_constants.average_filter_size = |
| 59 | Values::kZeroingSampleSize; |
| 60 | wrist->subsystem_params.zeroing_constants.one_revolution_distance = |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 61 | M_PI * 2.0 * constants::Values::kCompWristEncoderRatio(); |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 62 | wrist->subsystem_params.zeroing_constants.zeroing_threshold = 0.0005; |
| 63 | wrist->subsystem_params.zeroing_constants.moving_buffer_size = 20; |
| 64 | wrist->subsystem_params.zeroing_constants.allowable_encoder_error = 0.9; |
| 65 | wrist->subsystem_params.zeroing_constants.middle_position = |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 66 | Values::kCompWristRange().middle(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 67 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 68 | switch (team) { |
| 69 | // A set of constants for tests. |
| 70 | case 1: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 71 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 72 | arm_proximal->potentiometer_offset = 0.0; |
| 73 | |
| 74 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 75 | arm_distal->potentiometer_offset = 0.0; |
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: |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 86 | arm_proximal->zeroing.measured_absolute_position = 0.153241637089465; |
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 - |
| 90 | 0.577156175549626; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 91 | |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 92 | arm_distal->zeroing.measured_absolute_position = 0.119544808434349; |
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 + |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 97 | 0.125924230298394 + 0.147136306208754 - 0.69167546169753; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 98 | |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 99 | roll_joint->zeroing.measured_absolute_position = 0.62315534539819; |
Austin Schuh | 7dcc49b | 2023-02-21 17:35:10 -0800 | [diff] [blame] | 100 | roll_joint->potentiometer_offset = |
Austin Schuh | 29d025c | 2023-03-03 21:41:04 -0800 | [diff] [blame] | 101 | -(3.87038557084874 - 0.0241774522172967 + 0.0711345168020632 - |
| 102 | 0.866186131631967 - 0.0256788357596952 + 0.18101759154572017 - |
| 103 | 0.0208958996127179 - 0.186395903925026 + 0.45801689548395 - |
| 104 | 0.5935210745062 + 0.166256655718334 - 0.12591438680483 + |
| 105 | 0.11972765117321 - 0.318724743041507) + |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 106 | 0.0201047336425017 - 1.0173426655158 - 0.186085272847293 - 0.0317706563397807; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 107 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 108 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
Austin Schuh | 509a727 | 2023-03-24 21:39:31 -0700 | [diff] [blame^] | 109 | 2.27068625283861; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 110 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 111 | break; |
| 112 | |
| 113 | case kPracticeTeamNumber: |
Austin Schuh | 3c6e253 | 2023-03-02 21:26:35 -0800 | [diff] [blame] | 114 | arm_proximal->zeroing.measured_absolute_position = 0.261970010788946; |
Henry Speiser | 30b570b | 2023-02-26 12:10:21 -0800 | [diff] [blame] | 115 | arm_proximal->potentiometer_offset = |
Austin Schuh | 3c6e253 | 2023-03-02 21:26:35 -0800 | [diff] [blame] | 116 | 10.5178592988554 + 0.0944609125285876 - 0.00826532984625095; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 117 | |
Austin Schuh | 3c6e253 | 2023-03-02 21:26:35 -0800 | [diff] [blame] | 118 | arm_distal->zeroing.measured_absolute_position = 0.507166003869875; |
| 119 | arm_distal->potentiometer_offset = |
| 120 | 7.673132586937 - 0.0799284644472573 - 0.0323574039310657 + |
| 121 | 0.0143810684138064 + 0.00945555248207735; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 122 | |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 123 | roll_joint->zeroing.measured_absolute_position = 1.85482286175059; |
Austin Schuh | 3c6e253 | 2023-03-02 21:26:35 -0800 | [diff] [blame] | 124 | roll_joint->potentiometer_offset = |
| 125 | 0.624713611895747 + 3.10458504917251 - 0.0966407797407789 + |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 126 | 0.0257708772364788 - 0.0395076737853459 - 6.87914956118006 - |
| 127 | 0.097581301615046; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 128 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 129 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
James Kuszmaul | 1b4cd44 | 2023-03-11 15:46:28 -0800 | [diff] [blame] | 130 | 6.04062267812154; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 131 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 132 | break; |
| 133 | |
| 134 | case kCodingRobotTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 135 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 136 | arm_proximal->potentiometer_offset = 0.0; |
| 137 | |
| 138 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 139 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 140 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 141 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 142 | roll_joint->potentiometer_offset = 0.0; |
| 143 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 144 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 145 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 146 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 147 | break; |
| 148 | |
| 149 | default: |
| 150 | LOG(FATAL) << "unknown team: " << team; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 151 | |
| 152 | // TODO(milind): add pot range checks once we add ranges |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | return r; |
| 156 | } |
| 157 | |
| 158 | Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); } |
| 159 | |
| 160 | } // namespace constants |
| 161 | } // namespace y2023 |