blob: 0154453a69971229d38dc92d0acb409da9498e4c [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#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 Schrader790cb542023-07-05 21:06:52 -070011#include "glog/logging.h"
12
Maxwell Hendersonad312342023-01-10 12:07:47 -080013#include "aos/mutex/mutex.h"
14#include "aos/network/team_number.h"
milind-u051c7002023-02-20 16:28:18 -080015#include "y2023/control_loops/superstructure/roll/integral_roll_plant.h"
16#include "y2023/control_loops/superstructure/wrist/integral_wrist_plant.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080017
Stephan Pleinesf63bde82024-01-13 15:59:33 -080018namespace y2023::constants {
Maxwell Hendersonad312342023-01-10 12:07:47 -080019
Maxwell Hendersonad312342023-01-10 12:07:47 -080020Values MakeValues(uint16_t team) {
21 LOG(INFO) << "creating a Constants for team: " << team;
22
23 Values r;
milind-u37385182023-02-20 15:07:28 -080024 auto *const arm_proximal = &r.arm_proximal;
25 auto *const arm_distal = &r.arm_distal;
milind-u051c7002023-02-20 16:28:18 -080026 auto *const wrist = &r.wrist;
27 auto *const roll_joint = &r.roll_joint;
Austin Schuhe5248cd2023-03-05 12:46:16 -080028 r.wrist_flipped = true;
milind-u37385182023-02-20 15:07:28 -080029
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-u37385182023-02-20 15:07:28 -080038 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-u18a901d2023-02-17 21:51:55 -080042 roll_joint->zeroing.average_filter_size = Values::kZeroingSampleSize;
43 roll_joint->zeroing.one_revolution_distance =
Austin Schuh1a3b8172023-02-22 20:38:33 -080044 M_PI * 2.0 * constants::Values::kRollJointEncoderRatio();
milind-u18a901d2023-02-17 21:51:55 -080045 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-u051c7002023-02-20 16:28:18 -080048
Maxwell Henderson8ca44562023-02-23 13:11:51 -080049 wrist->subsystem_params.zeroing_voltage = 3.0;
50 wrist->subsystem_params.operating_voltage = 12.0;
James Kuszmaul31c45352024-01-14 18:07:42 -080051 wrist->subsystem_params.zeroing_profile_params = {{}, 0.5, 3.0};
52 wrist->subsystem_params.default_profile_params = {{}, 0.5, 5.0};
Austin Schuhe5248cd2023-03-05 12:46:16 -080053 wrist->subsystem_params.range = Values::kCompWristRange();
Maxwell Henderson8ca44562023-02-23 13:11:51 -080054 wrist->subsystem_params.make_integral_loop =
milind-u051c7002023-02-20 16:28:18 -080055 control_loops::superstructure::wrist::MakeIntegralWristLoop;
Maxwell Henderson8ca44562023-02-23 13:11:51 -080056 wrist->subsystem_params.zeroing_constants.average_filter_size =
57 Values::kZeroingSampleSize;
58 wrist->subsystem_params.zeroing_constants.one_revolution_distance =
Austin Schuhe5248cd2023-03-05 12:46:16 -080059 M_PI * 2.0 * constants::Values::kCompWristEncoderRatio();
Maxwell Henderson8ca44562023-02-23 13:11:51 -080060 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 Schuhe5248cd2023-03-05 12:46:16 -080064 Values::kCompWristRange().middle();
milind-u051c7002023-02-20 16:28:18 -080065
Maxwell Hendersonad312342023-01-10 12:07:47 -080066 switch (team) {
67 // A set of constants for tests.
68 case 1:
milind-u37385182023-02-20 15:07:28 -080069 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 Hendersonce816122023-03-27 20:12:38 -070074 arm_distal->zeroing.one_revolution_distance =
75 M_PI * 2.0 * constants::Values::kDistalEncoderRatio();
milind-u051c7002023-02-20 16:28:18 -080076
milind-u18a901d2023-02-17 21:51:55 -080077 roll_joint->zeroing.measured_absolute_position = 0.0;
milind-u051c7002023-02-20 16:28:18 -080078 roll_joint->potentiometer_offset = 0.0;
79
Maxwell Henderson8ca44562023-02-23 13:11:51 -080080 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
81 0.0;
milind-u051c7002023-02-20 16:28:18 -080082
Maxwell Hendersonad312342023-01-10 12:07:47 -080083 break;
84
85 case kCompTeamNumber:
Maxwell Henderson55891ba2023-09-20 09:10:59 -070086 arm_proximal->zeroing.measured_absolute_position = 0.911747959388894;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -070087 arm_proximal->potentiometer_offset =
88 10.5178592988554 + 0.0944609125285876 - 0.00826532984625095 +
Maxwell Henderson55891ba2023-09-20 09:10:59 -070089 0.167359305216504 + 0.135144500925909 - 0.214909475332252 +
90 0.0377032255050543;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -070091
Maxwell Henderson61199c22023-09-24 10:57:14 -070092 arm_distal->zeroing.measured_absolute_position = 0.294291930885304;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -070093 arm_distal->potentiometer_offset =
94 7.673132586937 - 0.0799284644472573 - 0.0323574039310657 +
95 0.0143810684138064 + 0.00945555248207735 + 0.452446388633863 +
96 0.0194863477007102 + 0.235993332670562 + 0.00138417783482921 -
Maxwell Henderson795388c2023-09-24 11:08:52 -070097 1.29562640607084 - 0.390356125757262 - 0.267002511437832 -
James Kuszmaul2334f572023-09-29 20:41:58 -070098 0.611626839639182 + 2.55745730136924 + 0.503121678457021 +
99 0.0440779746883177;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -0700100
101 arm_distal->zeroing.one_revolution_distance =
102 M_PI * 2.0 * constants::Values::kDistalEncoderRatio() *
103 (3.12725165289659 + 0.002) / 3.1485739705977704;
104
Maxwell Hendersonaad1b692023-09-23 11:31:54 -0700105 roll_joint->zeroing.measured_absolute_position = 1.82824749141201;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -0700106 roll_joint->potentiometer_offset =
107 0.624713611895747 + 3.10458504917251 - 0.0966407797407789 +
108 0.0257708772364788 - 0.0395076737853459 - 6.87914956118006 -
109 0.097581301615046 + 3.3424421683095 - 3.97605190912604 +
Maxwell Henderson77f5ea72023-10-28 16:36:33 -0700110 0.709274294168941 - 0.0817908884966825 + 0.0420732537514303;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -0700111
112 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
Maxwell Henderson673677b2023-11-11 08:32:21 -0800113 0.616272675539221;
Maxwell Henderson3e9cf142023-09-17 20:31:15 -0700114
115 break;
116
117 case kPracticeTeamNumber:
Xander Yee2ea61f52023-11-10 21:38:53 -0800118 arm_proximal->zeroing.measured_absolute_position = 0.585858300637312;
Austin Schuh13615bc2023-02-25 17:19:53 -0800119 arm_proximal->potentiometer_offset =
120 0.931355973012855 + 8.6743197253382 - 0.101200335326309 -
Austin Schuh1e8e8742023-03-22 20:26:04 -0700121 0.0820901660993467 - 0.0703733798337964 - 0.0294645384848748 -
Xander Yee2ea61f52023-11-10 21:38:53 -0800122 0.577156175549626 - 0.000944609125286267 + 2.725142829769231 -
123 6.38385012428248;
milind-u37385182023-02-20 15:07:28 -0800124
Xander Yee2ea61f52023-11-10 21:38:53 -0800125 arm_distal->zeroing.measured_absolute_position = 0.650190739752296;
Austin Schuh6d59ffb2023-02-23 21:44:04 -0800126 arm_distal->potentiometer_offset =
127 0.436664933370656 + 0.49457213779426 + 6.78213223139724 -
128 0.0220711555235029 - 0.0162945074111813 + 0.00630344935527365 -
Austin Schuhe062be02023-03-04 21:12:07 -0800129 0.0164398318919943 - 0.145833494945215 + 0.234878799868491 +
Maxwell Hendersonce816122023-03-27 20:12:38 -0700130 0.125924230298394 + 0.147136306208754 - 0.69167546169753 -
Austin Schuhe2cf0672023-04-09 22:19:18 -0700131 0.308761538844425 + 0.610386472488493 + 0.08384162885249 +
Maxwell Hendersonfd23cc32023-10-25 21:09:41 -0700132 0.0262274735196811 + 0.5153995156153 - 0.4485275474911 -
Xander Yee2ea61f52023-11-10 21:38:53 -0800133 0.417143262506383 + 0.0808060249784878;
Maxwell Hendersonce816122023-03-27 20:12:38 -0700134
135 arm_distal->zeroing.one_revolution_distance =
136 M_PI * 2.0 * constants::Values::kDistalEncoderRatio();
milind-u051c7002023-02-20 16:28:18 -0800137
Xander Yee2ea61f52023-11-10 21:38:53 -0800138 roll_joint->zeroing.measured_absolute_position = 0.79919822250646;
Austin Schuh7dcc49b2023-02-21 17:35:10 -0800139 roll_joint->potentiometer_offset =
Austin Schuh29d025c2023-03-03 21:41:04 -0800140 -(3.87038557084874 - 0.0241774522172967 + 0.0711345168020632 -
141 0.866186131631967 - 0.0256788357596952 + 0.18101759154572017 -
142 0.0208958996127179 - 0.186395903925026 + 0.45801689548395 -
143 0.5935210745062 + 0.166256655718334 - 0.12591438680483 +
144 0.11972765117321 - 0.318724743041507) +
Maxwell Hendersonce816122023-03-27 20:12:38 -0700145 0.0201047336425017 - 1.0173426655158 - 0.186085272847293 -
Austin Schuh67f5cd12023-04-21 05:38:50 -0700146 0.0317706563397807 - 2.6357823523782 + 0.871932806570122 +
Xander Yee2ea61f52023-11-10 21:38:53 -0800147 1.09682107821155 - 0.193945964842277 + 0.811834321668829 -
148 0.913134567575683;
milind-u051c7002023-02-20 16:28:18 -0800149
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800150 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
Xander Yee2ea61f52023-11-10 21:38:53 -0800151 2.94344206522199;
milind-u051c7002023-02-20 16:28:18 -0800152
Maxwell Hendersonad312342023-01-10 12:07:47 -0800153 break;
154
Maxwell Hendersonad312342023-01-10 12:07:47 -0800155 case kCodingRobotTeamNumber:
milind-u37385182023-02-20 15:07:28 -0800156 arm_proximal->zeroing.measured_absolute_position = 0.0;
157 arm_proximal->potentiometer_offset = 0.0;
158
159 arm_distal->zeroing.measured_absolute_position = 0.0;
160 arm_distal->potentiometer_offset = 0.0;
milind-u051c7002023-02-20 16:28:18 -0800161
milind-u18a901d2023-02-17 21:51:55 -0800162 roll_joint->zeroing.measured_absolute_position = 0.0;
milind-u051c7002023-02-20 16:28:18 -0800163 roll_joint->potentiometer_offset = 0.0;
164
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800165 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
166 0.0;
milind-u051c7002023-02-20 16:28:18 -0800167
Maxwell Hendersonad312342023-01-10 12:07:47 -0800168 break;
169
170 default:
171 LOG(FATAL) << "unknown team: " << team;
milind-u051c7002023-02-20 16:28:18 -0800172
173 // TODO(milind): add pot range checks once we add ranges
Maxwell Hendersonad312342023-01-10 12:07:47 -0800174 }
175
176 return r;
177}
178
179Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); }
180
Stephan Pleinesf63bde82024-01-13 15:59:33 -0800181} // namespace y2023::constants