blob: e6951cc3bff63ab49225a8fb76aa028ff89f5a9b [file] [log] [blame]
Austin Schuh2a3e0632018-02-19 16:24:49 -08001#include "y2018/constants.h"
2
Tyler Chatowbf0609c2021-07-31 16:13:27 -07003#include <cinttypes>
4#include <cmath>
5#include <cstdint>
Austin Schuh2a3e0632018-02-19 16:24:49 -08006#include <map>
7
8#if __has_feature(address_sanitizer)
9#include "sanitizer/lsan_interface.h"
10#endif
11
John Park33858a32018-09-28 23:05:48 -070012#include "aos/logging/logging.h"
John Park33858a32018-09-28 23:05:48 -070013#include "aos/network/team_number.h"
Brian Silverman1463c092020-10-30 17:28:24 -070014#include "aos/stl_mutex/stl_mutex.h"
Austin Schuh2a3e0632018-02-19 16:24:49 -080015#include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
16#include "y2018/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
17
18#ifndef M_PI
19#define M_PI 3.14159265358979323846
20#endif
21
22namespace y2018 {
23namespace constants {
24namespace {
25
26const uint16_t kCompTeamNumber = 971;
27const uint16_t kPracticeTeamNumber = 9971;
28
29const Values *DoGetValuesForTeam(uint16_t team) {
30 Values *const r = new Values();
Sabina Davis8d20ca82018-02-19 13:17:45 -080031 Values::IntakeSide *const left_intake = &r->left_intake;
32 Values::IntakeSide *const right_intake = &r->right_intake;
Austin Schuhcb091712018-02-21 20:01:55 -080033 Values::Proximal *const arm_proximal = &r->arm_proximal;
34 Values::Distal *const arm_distal = &r->arm_distal;
Austin Schuh2a3e0632018-02-19 16:24:49 -080035
Sabina Davis8d20ca82018-02-19 13:17:45 -080036 left_intake->zeroing.average_filter_size = Values::kZeroingSampleSize();
37 left_intake->zeroing.one_revolution_distance =
38 M_PI * 2.0 * constants::Values::kIntakeMotorEncoderRatio();
39 left_intake->zeroing.zeroing_threshold = 0.0005;
40 left_intake->zeroing.moving_buffer_size = 20;
41 left_intake->zeroing.allowable_encoder_error = 1.9;
42
43 *right_intake = *left_intake;
44
Austin Schuhcb091712018-02-21 20:01:55 -080045 arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize();
46 arm_proximal->zeroing.one_revolution_distance =
Sabina Davis8d20ca82018-02-19 13:17:45 -080047 M_PI * 2.0 * constants::Values::kProximalEncoderRatio();
Austin Schuhcb091712018-02-21 20:01:55 -080048 arm_proximal->zeroing.zeroing_threshold = 0.0005;
49 arm_proximal->zeroing.moving_buffer_size = 20;
50 arm_proximal->zeroing.allowable_encoder_error = 0.9;
Sabina Davis8d20ca82018-02-19 13:17:45 -080051
Austin Schuhcb091712018-02-21 20:01:55 -080052 arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize();
53 arm_distal->zeroing.one_revolution_distance =
Sabina Davis8d20ca82018-02-19 13:17:45 -080054 M_PI * 2.0 * constants::Values::kDistalEncoderRatio();
Austin Schuhcb091712018-02-21 20:01:55 -080055 arm_distal->zeroing.zeroing_threshold = 0.0005;
56 arm_distal->zeroing.moving_buffer_size = 20;
57 arm_distal->zeroing.allowable_encoder_error = 0.9;
Sabina Davis8d20ca82018-02-19 13:17:45 -080058
Austin Schuh47d74942018-03-04 01:15:59 -080059 constexpr double kDistalZeroingPosition =
60 M_PI * 3.0 / 2.0 + (28.5 / 180.0) * M_PI;
61 // 5.209807817203074
62
Austin Schuh2a3e0632018-02-19 16:24:49 -080063 switch (team) {
64 // A set of constants for tests.
65 case 1:
Austin Schuh2a3e0632018-02-19 16:24:49 -080066 r->vision_name = "test";
67 r->vision_error = -0.030;
Sabina Davis8d20ca82018-02-19 13:17:45 -080068
69 left_intake->zeroing.measured_absolute_position = 0.0;
70 left_intake->potentiometer_offset = 0.0;
71 left_intake->spring_offset = 0.0;
72
73 right_intake->zeroing.measured_absolute_position = 0.0;
74 right_intake->potentiometer_offset = 0.0;
75 right_intake->spring_offset = 0.0;
76
Austin Schuhcb091712018-02-21 20:01:55 -080077 arm_proximal->zeroing.measured_absolute_position = 0.0;
78 arm_proximal->potentiometer_offset = 0.0;
Sabina Davis8d20ca82018-02-19 13:17:45 -080079
Austin Schuhcb091712018-02-21 20:01:55 -080080 arm_distal->zeroing.measured_absolute_position = 0.0;
81 arm_distal->potentiometer_offset = 0.0;
Austin Schuh2a3e0632018-02-19 16:24:49 -080082 break;
83
84 case kCompTeamNumber:
Austin Schuh2a3e0632018-02-19 16:24:49 -080085 r->vision_name = "competition";
86 r->vision_error = 0.0;
Sabina Davis8d20ca82018-02-19 13:17:45 -080087
Sabina Davis94265042018-11-03 19:42:07 -070088 left_intake->zeroing.measured_absolute_position = 0.219024;
89 left_intake->potentiometer_offset = -5.45258 + 1.299206 - 0.525603;
Austin Schuhec310a42018-05-30 20:46:48 -070090 left_intake->spring_offset = -0.25 - 0.009 + 0.029 - 0.025;
Sabina Davis8d20ca82018-02-19 13:17:45 -080091
Austin Schuh9356ccb2018-04-04 20:12:31 -070092 right_intake->zeroing.measured_absolute_position = 0.37022 - 0.04;
93 right_intake->potentiometer_offset = 3.739919 + 1.087098 + 0.825;
Austin Schuhec310a42018-05-30 20:46:48 -070094 right_intake->spring_offset = 0.25 + 0.015 - 0.025;
Sabina Davis8d20ca82018-02-19 13:17:45 -080095
Austin Schuhef978fc2018-03-21 20:38:06 -070096 arm_proximal->zeroing.measured_absolute_position =
Austin Schuhec310a42018-05-30 20:46:48 -070097 0.067941 + 1.047 - 0.116 + 0.06 - 0.004 + 0.009 + 0.0938;
Austin Schuh9356ccb2018-04-04 20:12:31 -070098 arm_proximal->potentiometer_offset =
Austin Schuhec310a42018-05-30 20:46:48 -070099 1.047 - 3.653298 + -0.078 + 0.9455 + 0.265 - 0.36;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800100
Austin Schuhef978fc2018-03-21 20:38:06 -0700101 arm_distal->zeroing.measured_absolute_position =
Austin Schuhec310a42018-05-30 20:46:48 -0700102 -0.870445 + 5.209807817203074 + 0.118 - 0.004 + 0.407 - 0.53;
Brian Silverman1463c092020-10-30 17:28:24 -0700103 arm_distal->potentiometer_offset =
104 5.209807817203074 + 1.250476 + 0.110 + 0.52;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800105 break;
106
107 case kPracticeTeamNumber:
Austin Schuh2a3e0632018-02-19 16:24:49 -0800108 r->vision_name = "practice";
109 r->vision_error = 0.0;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800110
Austin Schuh47d74942018-03-04 01:15:59 -0800111 left_intake->zeroing.measured_absolute_position = 0.031709;
112 left_intake->potentiometer_offset = -10.55 - 3.621232 + 4.996959;
113 left_intake->spring_offset = -0.249 - 0.002;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800114
Austin Schuh47d74942018-03-04 01:15:59 -0800115 right_intake->zeroing.measured_absolute_position = 0.351376;
116 right_intake->potentiometer_offset = 9.59 + 1.530320 - 3.620648;
Austin Schuh9356ccb2018-04-04 20:12:31 -0700117 right_intake->spring_offset = 0.255 + 0.008 - 0.09;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800118
Brian Silverman1463c092020-10-30 17:28:24 -0700119 arm_proximal->zeroing.measured_absolute_position =
120 -0.253183 + 1.0652774488034022 + 0.009566448803402405;
Austin Schuh03065362018-08-18 21:29:23 -0700121 arm_proximal->potentiometer_offset = -1.242 - 0.03 - 0.1 - 1.0652;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800122
Austin Schuh47d74942018-03-04 01:15:59 -0800123 arm_distal->zeroing.measured_absolute_position =
Brian Silverman1463c092020-10-30 17:28:24 -0700124 1.102987 - kDistalZeroingPosition + 0.12 + 0.0095 +
125 0.22300918279692628;
126 arm_distal->potentiometer_offset = 2.772210 + M_PI + 0.434 - 0.12 + 1.25 -
127 0.226 + 0.862067 - 0.121925182796926;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800128 break;
129
130 default:
Austin Schuhf257f3c2019-10-27 21:00:43 -0700131 AOS_LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
Austin Schuh2a3e0632018-02-19 16:24:49 -0800132 }
133
134 return r;
135}
136
Austin Schuh6829f762018-03-02 21:36:01 -0800137const Values &DoGetValues() {
Austin Schuha8de4a62018-09-03 18:04:28 -0700138 const uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700139 AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
Austin Schuh6829f762018-03-02 21:36:01 -0800140 return GetValuesForTeam(team);
Austin Schuh2a3e0632018-02-19 16:24:49 -0800141}
142
143} // namespace
144
Brian Silverman8d727072018-03-10 19:45:25 -0800145const Values &GetValues() {
146 static const Values r = DoGetValues();
147 return r;
148}
Austin Schuh2a3e0632018-02-19 16:24:49 -0800149
150const Values &GetValuesForTeam(uint16_t team_number) {
Brian Silverman1463c092020-10-30 17:28:24 -0700151 static aos::stl_mutex mutex;
152 std::unique_lock<aos::stl_mutex> locker(mutex);
Austin Schuh2a3e0632018-02-19 16:24:49 -0800153
154 static ::std::map<uint16_t, const Values *> values;
155
156 if (values.count(team_number) == 0) {
157 values[team_number] = DoGetValuesForTeam(team_number);
158#if __has_feature(address_sanitizer)
159 __lsan_ignore_object(values[team_number]);
160#endif
161 }
162 return *values[team_number];
163}
164
165} // namespace constants
166} // namespace y2018