blob: a6c0396cc9343a2b9540fa9f236f820d343a0231 [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"
11#include "aos/mutex/mutex.h"
12#include "aos/network/team_number.h"
13#include "glog/logging.h"
milind-u051c7002023-02-20 16:28:18 -080014#include "y2023/control_loops/superstructure/roll/integral_roll_plant.h"
15#include "y2023/control_loops/superstructure/wrist/integral_wrist_plant.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080016
17namespace y2023 {
18namespace constants {
19
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;
51 wrist->subsystem_params.zeroing_profile_params = {0.5, 3.0};
Austin Schuh6dc925b2023-02-24 16:23:32 -080052 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:
Austin Schuh3a8e7e02023-04-15 00:42:38 -070086 arm_proximal->zeroing.measured_absolute_position = 0.146982006490838;
Austin Schuh13615bc2023-02-25 17:19:53 -080087 arm_proximal->potentiometer_offset =
88 0.931355973012855 + 8.6743197253382 - 0.101200335326309 -
Austin Schuh1e8e8742023-03-22 20:26:04 -070089 0.0820901660993467 - 0.0703733798337964 - 0.0294645384848748 -
James Kuszmaul6c90f052023-04-08 17:54:47 -070090 0.577156175549626 - 0.000944609125286267;
milind-u37385182023-02-20 15:07:28 -080091
Austin Schuh3a8e7e02023-04-15 00:42:38 -070092 arm_distal->zeroing.measured_absolute_position = 0.187578439107614;
Austin Schuh6d59ffb2023-02-23 21:44:04 -080093 arm_distal->potentiometer_offset =
94 0.436664933370656 + 0.49457213779426 + 6.78213223139724 -
95 0.0220711555235029 - 0.0162945074111813 + 0.00630344935527365 -
Austin Schuhe062be02023-03-04 21:12:07 -080096 0.0164398318919943 - 0.145833494945215 + 0.234878799868491 +
Maxwell Hendersonce816122023-03-27 20:12:38 -070097 0.125924230298394 + 0.147136306208754 - 0.69167546169753 -
Austin Schuhe2cf0672023-04-09 22:19:18 -070098 0.308761538844425 + 0.610386472488493 + 0.08384162885249 +
Austin Schuh3a8e7e02023-04-15 00:42:38 -070099 0.0262274735196811 + 0.5153995156153 - 0.4485275474911;
Maxwell Hendersonce816122023-03-27 20:12:38 -0700100
101 arm_distal->zeroing.one_revolution_distance =
102 M_PI * 2.0 * constants::Values::kDistalEncoderRatio();
milind-u051c7002023-02-20 16:28:18 -0800103
James Kuszmaul6c90f052023-04-08 17:54:47 -0700104 roll_joint->zeroing.measured_absolute_position = 0.419144048980465;
Austin Schuh7dcc49b2023-02-21 17:35:10 -0800105 roll_joint->potentiometer_offset =
Austin Schuh29d025c2023-03-03 21:41:04 -0800106 -(3.87038557084874 - 0.0241774522172967 + 0.0711345168020632 -
107 0.866186131631967 - 0.0256788357596952 + 0.18101759154572017 -
108 0.0208958996127179 - 0.186395903925026 + 0.45801689548395 -
109 0.5935210745062 + 0.166256655718334 - 0.12591438680483 +
110 0.11972765117321 - 0.318724743041507) +
Maxwell Hendersonce816122023-03-27 20:12:38 -0700111 0.0201047336425017 - 1.0173426655158 - 0.186085272847293 -
James Kuszmaul6c90f052023-04-08 17:54:47 -0700112 0.0317706563397807 - 2.6357823523782 + 0.871932806570122;
milind-u051c7002023-02-20 16:28:18 -0800113
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800114 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
Austin Schuh3a8e7e02023-04-15 00:42:38 -0700115 0.868820879549023;
milind-u051c7002023-02-20 16:28:18 -0800116
Maxwell Hendersonad312342023-01-10 12:07:47 -0800117 break;
118
119 case kPracticeTeamNumber:
Austin Schuh2d15c352023-04-14 23:44:41 -0700120 arm_proximal->zeroing.measured_absolute_position = 0.911194143585562;
Henry Speiser30b570b2023-02-26 12:10:21 -0800121 arm_proximal->potentiometer_offset =
Austin Schuh95b677b2023-03-25 15:30:37 -0700122 10.5178592988554 + 0.0944609125285876 - 0.00826532984625095 +
Austin Schuh2d15c352023-04-14 23:44:41 -0700123 0.167359305216504 + 0.135144500925909 - 0.214909475332252;
milind-u37385182023-02-20 15:07:28 -0800124
Austin Schuh2d15c352023-04-14 23:44:41 -0700125 arm_distal->zeroing.measured_absolute_position = 0.295329750530428;
Austin Schuh3c6e2532023-03-02 21:26:35 -0800126 arm_distal->potentiometer_offset =
127 7.673132586937 - 0.0799284644472573 - 0.0323574039310657 +
Maxwell Hendersonce816122023-03-27 20:12:38 -0700128 0.0143810684138064 + 0.00945555248207735 + 0.452446388633863 +
Austin Schuh2d15c352023-04-14 23:44:41 -0700129 0.0194863477007102 + 0.235993332670562 + 0.00138417783482921 -
130 1.29562640607084;
Maxwell Hendersonce816122023-03-27 20:12:38 -0700131
132 arm_distal->zeroing.one_revolution_distance =
133 M_PI * 2.0 * constants::Values::kDistalEncoderRatio() *
James Kuszmaul6c90f052023-04-08 17:54:47 -0700134 //3.11964893168338 / 3.148;
135 (3.12725165289659 + 0.002) / 3.1485739705977704;
milind-u051c7002023-02-20 16:28:18 -0800136
Austin Schuh0a58a902023-04-09 14:16:15 -0700137 roll_joint->zeroing.measured_absolute_position = 1.79390317510529;
Austin Schuh3c6e2532023-03-02 21:26:35 -0800138 roll_joint->potentiometer_offset =
139 0.624713611895747 + 3.10458504917251 - 0.0966407797407789 +
Austin Schuh1e8e8742023-03-22 20:26:04 -0700140 0.0257708772364788 - 0.0395076737853459 - 6.87914956118006 -
James Kuszmaul6c90f052023-04-08 17:54:47 -0700141 0.097581301615046 + 3.3424421683095 - 3.97605190912604 +
142 0.709274294168941;
milind-u051c7002023-02-20 16:28:18 -0800143
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800144 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
Austin Schuh2d15c352023-04-14 23:44:41 -0700145 2.97717660361257;
Austin Schuhe5248cd2023-03-05 12:46:16 -0800146
Maxwell Hendersonad312342023-01-10 12:07:47 -0800147 break;
148
149 case kCodingRobotTeamNumber:
milind-u37385182023-02-20 15:07:28 -0800150 arm_proximal->zeroing.measured_absolute_position = 0.0;
151 arm_proximal->potentiometer_offset = 0.0;
152
153 arm_distal->zeroing.measured_absolute_position = 0.0;
154 arm_distal->potentiometer_offset = 0.0;
milind-u051c7002023-02-20 16:28:18 -0800155
milind-u18a901d2023-02-17 21:51:55 -0800156 roll_joint->zeroing.measured_absolute_position = 0.0;
milind-u051c7002023-02-20 16:28:18 -0800157 roll_joint->potentiometer_offset = 0.0;
158
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800159 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
160 0.0;
milind-u051c7002023-02-20 16:28:18 -0800161
Maxwell Hendersonad312342023-01-10 12:07:47 -0800162 break;
163
164 default:
165 LOG(FATAL) << "unknown team: " << team;
milind-u051c7002023-02-20 16:28:18 -0800166
167 // TODO(milind): add pot range checks once we add ranges
Maxwell Hendersonad312342023-01-10 12:07:47 -0800168 }
169
170 return r;
171}
172
173Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); }
174
175} // namespace constants
176} // namespace y2023