blob: 907b97f1fd24334eb8e315a1c84d0f72e0fbd608 [file] [log] [blame]
Austin Schuh2a3e0632018-02-19 16:24:49 -08001#include "y2018/constants.h"
2
3#include <inttypes.h>
4#include <math.h>
5#include <stdint.h>
6
7#include <map>
8
9#if __has_feature(address_sanitizer)
10#include "sanitizer/lsan_interface.h"
11#endif
12
13#include "aos/common/logging/logging.h"
14#include "aos/common/mutex.h"
15#include "aos/common/network/team_number.h"
16#include "aos/once.h"
17
18#include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
19#include "y2018/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
20
21#ifndef M_PI
22#define M_PI 3.14159265358979323846
23#endif
24
25namespace y2018 {
26namespace constants {
27namespace {
28
29const uint16_t kCompTeamNumber = 971;
30const uint16_t kPracticeTeamNumber = 9971;
31
32const Values *DoGetValuesForTeam(uint16_t team) {
33 Values *const r = new Values();
Sabina Davis8d20ca82018-02-19 13:17:45 -080034 Values::IntakeSide *const left_intake = &r->left_intake;
35 Values::IntakeSide *const right_intake = &r->right_intake;
Austin Schuhcb091712018-02-21 20:01:55 -080036 Values::Proximal *const arm_proximal = &r->arm_proximal;
37 Values::Distal *const arm_distal = &r->arm_distal;
Austin Schuh2a3e0632018-02-19 16:24:49 -080038
Sabina Davis8d20ca82018-02-19 13:17:45 -080039 left_intake->zeroing.average_filter_size = Values::kZeroingSampleSize();
40 left_intake->zeroing.one_revolution_distance =
41 M_PI * 2.0 * constants::Values::kIntakeMotorEncoderRatio();
42 left_intake->zeroing.zeroing_threshold = 0.0005;
43 left_intake->zeroing.moving_buffer_size = 20;
44 left_intake->zeroing.allowable_encoder_error = 1.9;
45
46 *right_intake = *left_intake;
47
Austin Schuhcb091712018-02-21 20:01:55 -080048 arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize();
49 arm_proximal->zeroing.one_revolution_distance =
Sabina Davis8d20ca82018-02-19 13:17:45 -080050 M_PI * 2.0 * constants::Values::kProximalEncoderRatio();
Austin Schuhcb091712018-02-21 20:01:55 -080051 arm_proximal->zeroing.zeroing_threshold = 0.0005;
52 arm_proximal->zeroing.moving_buffer_size = 20;
53 arm_proximal->zeroing.allowable_encoder_error = 0.9;
Sabina Davis8d20ca82018-02-19 13:17:45 -080054
Austin Schuhcb091712018-02-21 20:01:55 -080055 arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize();
56 arm_distal->zeroing.one_revolution_distance =
Sabina Davis8d20ca82018-02-19 13:17:45 -080057 M_PI * 2.0 * constants::Values::kDistalEncoderRatio();
Austin Schuhcb091712018-02-21 20:01:55 -080058 arm_distal->zeroing.zeroing_threshold = 0.0005;
59 arm_distal->zeroing.moving_buffer_size = 20;
60 arm_distal->zeroing.allowable_encoder_error = 0.9;
Sabina Davis8d20ca82018-02-19 13:17:45 -080061
Austin Schuh47d74942018-03-04 01:15:59 -080062 constexpr double kDistalZeroingPosition =
63 M_PI * 3.0 / 2.0 + (28.5 / 180.0) * M_PI;
64 // 5.209807817203074
65
Austin Schuh2a3e0632018-02-19 16:24:49 -080066 switch (team) {
67 // A set of constants for tests.
68 case 1:
Austin Schuh2a3e0632018-02-19 16:24:49 -080069 r->vision_name = "test";
70 r->vision_error = -0.030;
Sabina Davis8d20ca82018-02-19 13:17:45 -080071
72 left_intake->zeroing.measured_absolute_position = 0.0;
73 left_intake->potentiometer_offset = 0.0;
74 left_intake->spring_offset = 0.0;
75
76 right_intake->zeroing.measured_absolute_position = 0.0;
77 right_intake->potentiometer_offset = 0.0;
78 right_intake->spring_offset = 0.0;
79
Austin Schuhcb091712018-02-21 20:01:55 -080080 arm_proximal->zeroing.measured_absolute_position = 0.0;
81 arm_proximal->potentiometer_offset = 0.0;
Sabina Davis8d20ca82018-02-19 13:17:45 -080082
Austin Schuhcb091712018-02-21 20:01:55 -080083 arm_distal->zeroing.measured_absolute_position = 0.0;
84 arm_distal->potentiometer_offset = 0.0;
Austin Schuh2a3e0632018-02-19 16:24:49 -080085 break;
86
87 case kCompTeamNumber:
Austin Schuh2a3e0632018-02-19 16:24:49 -080088 r->vision_name = "competition";
89 r->vision_error = 0.0;
Sabina Davis8d20ca82018-02-19 13:17:45 -080090
Austin Schuhef978fc2018-03-21 20:38:06 -070091 left_intake->zeroing.measured_absolute_position = 0.213653;
92 left_intake->potentiometer_offset = -5.45258;
93 left_intake->spring_offset = -0.25;
Sabina Davis8d20ca82018-02-19 13:17:45 -080094
Austin Schuhef978fc2018-03-21 20:38:06 -070095 right_intake->zeroing.measured_absolute_position = 0.056773;
96 right_intake->potentiometer_offset = 3.739919;
97 right_intake->spring_offset = 0.25 - 0.014;
Sabina Davis8d20ca82018-02-19 13:17:45 -080098
Austin Schuhef978fc2018-03-21 20:38:06 -070099 arm_proximal->zeroing.measured_absolute_position =
100 0.067941 + 1.047 - 0.116 + 0.06 - 0.004;
101 arm_proximal->potentiometer_offset = 1.047 - 3.653298 + -0.078 + 0.9455;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800102
Austin Schuhef978fc2018-03-21 20:38:06 -0700103 arm_distal->zeroing.measured_absolute_position =
104 -0.870445 + 5.209807817203074 + 0.118 - 0.004;
105 arm_distal->potentiometer_offset = 5.209807817203074 + 1.250476;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800106 break;
107
108 case kPracticeTeamNumber:
Austin Schuh2a3e0632018-02-19 16:24:49 -0800109 r->vision_name = "practice";
110 r->vision_error = 0.0;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800111
Austin Schuh47d74942018-03-04 01:15:59 -0800112 left_intake->zeroing.measured_absolute_position = 0.031709;
113 left_intake->potentiometer_offset = -10.55 - 3.621232 + 4.996959;
114 left_intake->spring_offset = -0.249 - 0.002;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800115
Austin Schuh47d74942018-03-04 01:15:59 -0800116 right_intake->zeroing.measured_absolute_position = 0.351376;
117 right_intake->potentiometer_offset = 9.59 + 1.530320 - 3.620648;
118 right_intake->spring_offset = 0.255 + 0.008;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800119
Austin Schuhef978fc2018-03-21 20:38:06 -0700120 arm_proximal->zeroing.measured_absolute_position = 0.1877 + 0.02 + 0.1;
121 arm_proximal->potentiometer_offset = -1.242 - 0.03 - 0.1;
Sabina Davis8d20ca82018-02-19 13:17:45 -0800122
Austin Schuh47d74942018-03-04 01:15:59 -0800123 arm_distal->zeroing.measured_absolute_position =
Austin Schuhef978fc2018-03-21 20:38:06 -0700124 1.102987 - kDistalZeroingPosition + 0.12;
125 arm_distal->potentiometer_offset =
126 2.772210 + M_PI + 0.434 - 0.12 + 1.25 - 0.226;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800127 break;
128
129 default:
130 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
131 }
132
133 return r;
134}
135
Austin Schuh6829f762018-03-02 21:36:01 -0800136const Values &DoGetValues() {
Austin Schuh2a3e0632018-02-19 16:24:49 -0800137 uint16_t team = ::aos::network::GetTeamNumber();
138 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
Austin Schuh6829f762018-03-02 21:36:01 -0800139 return GetValuesForTeam(team);
Austin Schuh2a3e0632018-02-19 16:24:49 -0800140}
141
142} // namespace
143
Brian Silverman8d727072018-03-10 19:45:25 -0800144const Values &GetValues() {
145 static const Values r = DoGetValues();
146 return r;
147}
Austin Schuh2a3e0632018-02-19 16:24:49 -0800148
149const Values &GetValuesForTeam(uint16_t team_number) {
150 static ::aos::Mutex mutex;
151 ::aos::MutexLocker locker(&mutex);
152
153 static ::std::map<uint16_t, const Values *> values;
154
155 if (values.count(team_number) == 0) {
156 values[team_number] = DoGetValuesForTeam(team_number);
157#if __has_feature(address_sanitizer)
158 __lsan_ignore_object(values[team_number]);
159#endif
160 }
161 return *values[team_number];
162}
163
164} // namespace constants
165} // namespace y2018