blob: d63b61bc727cf16ec057e991a6fc139001677c36 [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:
James Kuszmaul6c90f052023-04-08 17:54:47 -070086 arm_proximal->zeroing.measured_absolute_position = 0.152273750996612;
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
James Kuszmaul6c90f052023-04-08 17:54:47 -070092 arm_distal->zeroing.measured_absolute_position = 0.201204843551682;
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 -
James Kuszmaul6c90f052023-04-08 17:54:47 -070098 0.308761538844425 + 0.610386472488493 + 0.08384162885249 + 0.0262274735196811;
Maxwell Hendersonce816122023-03-27 20:12:38 -070099
100 arm_distal->zeroing.one_revolution_distance =
101 M_PI * 2.0 * constants::Values::kDistalEncoderRatio();
milind-u051c7002023-02-20 16:28:18 -0800102
James Kuszmaul6c90f052023-04-08 17:54:47 -0700103 roll_joint->zeroing.measured_absolute_position = 0.419144048980465;
Austin Schuh7dcc49b2023-02-21 17:35:10 -0800104 roll_joint->potentiometer_offset =
Austin Schuh29d025c2023-03-03 21:41:04 -0800105 -(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 Hendersonce816122023-03-27 20:12:38 -0700110 0.0201047336425017 - 1.0173426655158 - 0.186085272847293 -
James Kuszmaul6c90f052023-04-08 17:54:47 -0700111 0.0317706563397807 - 2.6357823523782 + 0.871932806570122;
milind-u051c7002023-02-20 16:28:18 -0800112
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800113 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
James Kuszmaul6c90f052023-04-08 17:54:47 -0700114 2.29036834725319;
milind-u051c7002023-02-20 16:28:18 -0800115
Maxwell Hendersonad312342023-01-10 12:07:47 -0800116 break;
117
118 case kPracticeTeamNumber:
James Kuszmaul6c90f052023-04-08 17:54:47 -0700119 arm_proximal->zeroing.measured_absolute_position = 0.140348044909775;
Henry Speiser30b570b2023-02-26 12:10:21 -0800120 arm_proximal->potentiometer_offset =
Austin Schuh95b677b2023-03-25 15:30:37 -0700121 10.5178592988554 + 0.0944609125285876 - 0.00826532984625095 +
James Kuszmaul6c90f052023-04-08 17:54:47 -0700122 0.167359305216504 + 0.135144500925909;
milind-u37385182023-02-20 15:07:28 -0800123
James Kuszmaul6c90f052023-04-08 17:54:47 -0700124 arm_distal->zeroing.measured_absolute_position = 0.860219239796068;
Austin Schuh3c6e2532023-03-02 21:26:35 -0800125 arm_distal->potentiometer_offset =
126 7.673132586937 - 0.0799284644472573 - 0.0323574039310657 +
Maxwell Hendersonce816122023-03-27 20:12:38 -0700127 0.0143810684138064 + 0.00945555248207735 + 0.452446388633863 +
James Kuszmaul6c90f052023-04-08 17:54:47 -0700128 0.0194863477007102 + 0.235993332670562 + 0.00138417783482921;
Maxwell Hendersonce816122023-03-27 20:12:38 -0700129
130 arm_distal->zeroing.one_revolution_distance =
131 M_PI * 2.0 * constants::Values::kDistalEncoderRatio() *
James Kuszmaul6c90f052023-04-08 17:54:47 -0700132 //3.11964893168338 / 3.148;
133 (3.12725165289659 + 0.002) / 3.1485739705977704;
milind-u051c7002023-02-20 16:28:18 -0800134
Austin Schuh0a58a902023-04-09 14:16:15 -0700135 roll_joint->zeroing.measured_absolute_position = 1.79390317510529;
Austin Schuh3c6e2532023-03-02 21:26:35 -0800136 roll_joint->potentiometer_offset =
137 0.624713611895747 + 3.10458504917251 - 0.0966407797407789 +
Austin Schuh1e8e8742023-03-22 20:26:04 -0700138 0.0257708772364788 - 0.0395076737853459 - 6.87914956118006 -
James Kuszmaul6c90f052023-04-08 17:54:47 -0700139 0.097581301615046 + 3.3424421683095 - 3.97605190912604 +
140 0.709274294168941;
milind-u051c7002023-02-20 16:28:18 -0800141
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800142 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
Austin Schuh0a58a902023-04-09 14:16:15 -0700143 4.68612810338484;
Austin Schuhe5248cd2023-03-05 12:46:16 -0800144
Maxwell Hendersonad312342023-01-10 12:07:47 -0800145 break;
146
147 case kCodingRobotTeamNumber:
milind-u37385182023-02-20 15:07:28 -0800148 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-u051c7002023-02-20 16:28:18 -0800153
milind-u18a901d2023-02-17 21:51:55 -0800154 roll_joint->zeroing.measured_absolute_position = 0.0;
milind-u051c7002023-02-20 16:28:18 -0800155 roll_joint->potentiometer_offset = 0.0;
156
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800157 wrist->subsystem_params.zeroing_constants.measured_absolute_position =
158 0.0;
milind-u051c7002023-02-20 16:28:18 -0800159
Maxwell Hendersonad312342023-01-10 12:07:47 -0800160 break;
161
162 default:
163 LOG(FATAL) << "unknown team: " << team;
milind-u051c7002023-02-20 16:28:18 -0800164
165 // TODO(milind): add pot range checks once we add ranges
Maxwell Hendersonad312342023-01-10 12:07:47 -0800166 }
167
168 return r;
169}
170
171Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); }
172
173} // namespace constants
174} // namespace y2023