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" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 11 | #include "glog/logging.h" |
| 12 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 13 | #include "aos/mutex/mutex.h" |
| 14 | #include "aos/network/team_number.h" |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 15 | #include "y2023/control_loops/superstructure/roll/integral_roll_plant.h" |
| 16 | #include "y2023/control_loops/superstructure/wrist/integral_wrist_plant.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 17 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 18 | namespace y2023::constants { |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 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 roll_joint = &r.roll_joint; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 27 | r.wrist_flipped = true; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 28 | |
| 29 | arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 30 | arm_proximal->zeroing.one_revolution_distance = |
| 31 | M_PI * 2.0 * constants::Values::kProximalEncoderRatio(); |
| 32 | arm_proximal->zeroing.zeroing_threshold = 0.0005; |
| 33 | arm_proximal->zeroing.moving_buffer_size = 20; |
| 34 | arm_proximal->zeroing.allowable_encoder_error = 0.9; |
| 35 | |
| 36 | arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 37 | arm_distal->zeroing.zeroing_threshold = 0.0005; |
| 38 | arm_distal->zeroing.moving_buffer_size = 20; |
| 39 | arm_distal->zeroing.allowable_encoder_error = 0.9; |
| 40 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 41 | roll_joint->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 42 | roll_joint->zeroing.one_revolution_distance = |
Austin Schuh | 1a3b817 | 2023-02-22 20:38:33 -0800 | [diff] [blame] | 43 | M_PI * 2.0 * constants::Values::kRollJointEncoderRatio(); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 44 | roll_joint->zeroing.zeroing_threshold = 0.0005; |
| 45 | roll_joint->zeroing.moving_buffer_size = 20; |
| 46 | roll_joint->zeroing.allowable_encoder_error = 0.9; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 47 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 48 | switch (team) { |
| 49 | // A set of constants for tests. |
| 50 | case 1: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 51 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 52 | arm_proximal->potentiometer_offset = 0.0; |
| 53 | |
| 54 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 55 | arm_distal->potentiometer_offset = 0.0; |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 56 | arm_distal->zeroing.one_revolution_distance = |
| 57 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 58 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 59 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 60 | roll_joint->potentiometer_offset = 0.0; |
| 61 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 62 | break; |
| 63 | |
| 64 | case kCompTeamNumber: |
Maxwell Henderson | 55891ba | 2023-09-20 09:10:59 -0700 | [diff] [blame] | 65 | arm_proximal->zeroing.measured_absolute_position = 0.911747959388894; |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 66 | arm_proximal->potentiometer_offset = |
| 67 | 10.5178592988554 + 0.0944609125285876 - 0.00826532984625095 + |
Maxwell Henderson | 55891ba | 2023-09-20 09:10:59 -0700 | [diff] [blame] | 68 | 0.167359305216504 + 0.135144500925909 - 0.214909475332252 + |
| 69 | 0.0377032255050543; |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 70 | |
Maxwell Henderson | 61199c2 | 2023-09-24 10:57:14 -0700 | [diff] [blame] | 71 | arm_distal->zeroing.measured_absolute_position = 0.294291930885304; |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 72 | arm_distal->potentiometer_offset = |
| 73 | 7.673132586937 - 0.0799284644472573 - 0.0323574039310657 + |
| 74 | 0.0143810684138064 + 0.00945555248207735 + 0.452446388633863 + |
| 75 | 0.0194863477007102 + 0.235993332670562 + 0.00138417783482921 - |
Maxwell Henderson | 795388c | 2023-09-24 11:08:52 -0700 | [diff] [blame] | 76 | 1.29562640607084 - 0.390356125757262 - 0.267002511437832 - |
James Kuszmaul | 2334f57 | 2023-09-29 20:41:58 -0700 | [diff] [blame] | 77 | 0.611626839639182 + 2.55745730136924 + 0.503121678457021 + |
| 78 | 0.0440779746883177; |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 79 | |
| 80 | arm_distal->zeroing.one_revolution_distance = |
| 81 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio() * |
| 82 | (3.12725165289659 + 0.002) / 3.1485739705977704; |
| 83 | |
Maxwell Henderson | aad1b69 | 2023-09-23 11:31:54 -0700 | [diff] [blame] | 84 | roll_joint->zeroing.measured_absolute_position = 1.82824749141201; |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 85 | roll_joint->potentiometer_offset = |
| 86 | 0.624713611895747 + 3.10458504917251 - 0.0966407797407789 + |
| 87 | 0.0257708772364788 - 0.0395076737853459 - 6.87914956118006 - |
| 88 | 0.097581301615046 + 3.3424421683095 - 3.97605190912604 + |
Maxwell Henderson | 77f5ea7 | 2023-10-28 16:36:33 -0700 | [diff] [blame] | 89 | 0.709274294168941 - 0.0817908884966825 + 0.0420732537514303; |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 90 | |
Maxwell Henderson | 3e9cf14 | 2023-09-17 20:31:15 -0700 | [diff] [blame] | 91 | break; |
| 92 | |
| 93 | case kPracticeTeamNumber: |
Xander Yee | 2ea61f5 | 2023-11-10 21:38:53 -0800 | [diff] [blame] | 94 | arm_proximal->zeroing.measured_absolute_position = 0.585858300637312; |
Austin Schuh | 13615bc | 2023-02-25 17:19:53 -0800 | [diff] [blame] | 95 | arm_proximal->potentiometer_offset = |
| 96 | 0.931355973012855 + 8.6743197253382 - 0.101200335326309 - |
Austin Schuh | 1e8e874 | 2023-03-22 20:26:04 -0700 | [diff] [blame] | 97 | 0.0820901660993467 - 0.0703733798337964 - 0.0294645384848748 - |
Xander Yee | 2ea61f5 | 2023-11-10 21:38:53 -0800 | [diff] [blame] | 98 | 0.577156175549626 - 0.000944609125286267 + 2.725142829769231 - |
| 99 | 6.38385012428248; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 100 | |
Xander Yee | 2ea61f5 | 2023-11-10 21:38:53 -0800 | [diff] [blame] | 101 | arm_distal->zeroing.measured_absolute_position = 0.650190739752296; |
Austin Schuh | 6d59ffb | 2023-02-23 21:44:04 -0800 | [diff] [blame] | 102 | arm_distal->potentiometer_offset = |
| 103 | 0.436664933370656 + 0.49457213779426 + 6.78213223139724 - |
| 104 | 0.0220711555235029 - 0.0162945074111813 + 0.00630344935527365 - |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 105 | 0.0164398318919943 - 0.145833494945215 + 0.234878799868491 + |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 106 | 0.125924230298394 + 0.147136306208754 - 0.69167546169753 - |
Austin Schuh | e2cf067 | 2023-04-09 22:19:18 -0700 | [diff] [blame] | 107 | 0.308761538844425 + 0.610386472488493 + 0.08384162885249 + |
Maxwell Henderson | fd23cc3 | 2023-10-25 21:09:41 -0700 | [diff] [blame] | 108 | 0.0262274735196811 + 0.5153995156153 - 0.4485275474911 - |
Xander Yee | 2ea61f5 | 2023-11-10 21:38:53 -0800 | [diff] [blame] | 109 | 0.417143262506383 + 0.0808060249784878; |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 110 | |
| 111 | arm_distal->zeroing.one_revolution_distance = |
| 112 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 113 | |
Xander Yee | 2ea61f5 | 2023-11-10 21:38:53 -0800 | [diff] [blame] | 114 | roll_joint->zeroing.measured_absolute_position = 0.79919822250646; |
Austin Schuh | 7dcc49b | 2023-02-21 17:35:10 -0800 | [diff] [blame] | 115 | roll_joint->potentiometer_offset = |
Austin Schuh | 29d025c | 2023-03-03 21:41:04 -0800 | [diff] [blame] | 116 | -(3.87038557084874 - 0.0241774522172967 + 0.0711345168020632 - |
| 117 | 0.866186131631967 - 0.0256788357596952 + 0.18101759154572017 - |
| 118 | 0.0208958996127179 - 0.186395903925026 + 0.45801689548395 - |
| 119 | 0.5935210745062 + 0.166256655718334 - 0.12591438680483 + |
| 120 | 0.11972765117321 - 0.318724743041507) + |
Maxwell Henderson | ce81612 | 2023-03-27 20:12:38 -0700 | [diff] [blame] | 121 | 0.0201047336425017 - 1.0173426655158 - 0.186085272847293 - |
Austin Schuh | 67f5cd1 | 2023-04-21 05:38:50 -0700 | [diff] [blame] | 122 | 0.0317706563397807 - 2.6357823523782 + 0.871932806570122 + |
Xander Yee | 2ea61f5 | 2023-11-10 21:38:53 -0800 | [diff] [blame] | 123 | 1.09682107821155 - 0.193945964842277 + 0.811834321668829 - |
| 124 | 0.913134567575683; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 125 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 126 | break; |
| 127 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 128 | case kCodingRobotTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 129 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 130 | arm_proximal->potentiometer_offset = 0.0; |
| 131 | |
| 132 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 133 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 134 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 135 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 136 | roll_joint->potentiometer_offset = 0.0; |
| 137 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 138 | break; |
| 139 | |
| 140 | default: |
| 141 | LOG(FATAL) << "unknown team: " << team; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 142 | |
| 143 | // TODO(milind): add pot range checks once we add ranges |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return r; |
| 147 | } |
| 148 | |
| 149 | Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); } |
| 150 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 151 | } // namespace y2023::constants |