blob: d6a8e5d6565a9460d7851a35f9f8cb761bc00f36 [file] [log] [blame]
Brian Silverman17f503e2015-08-02 18:17:18 -07001#include "y2014/constants.h"
2
Tyler Chatowbf0609c2021-07-31 16:13:27 -07003#include <cinttypes>
4#include <cmath>
5#include <cstdint>
Brian Silverman17f503e2015-08-02 18:17:18 -07006#include <map>
7
8#if __has_feature(address_sanitizer)
9#include "sanitizer/lsan_interface.h"
10#endif
11
John Park54de36c2019-11-11 19:14:10 -080012#include "absl/base/call_once.h"
Brian Silverman1463c092020-10-30 17:28:24 -070013#include "aos/logging/logging.h"
14#include "aos/network/team_number.h"
15#include "aos/stl_mutex/stl_mutex.h"
Brian Silverman17f503e2015-08-02 18:17:18 -070016#include "y2014/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Brian Silverman1463c092020-10-30 17:28:24 -070017#include "y2014/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
Brian Silverman17f503e2015-08-02 18:17:18 -070018
19#ifndef M_PI
20#define M_PI 3.14159265358979323846
21#endif
22
Austin Schuh6197a182015-11-28 16:04:40 -080023namespace y2014 {
Brian Silverman17f503e2015-08-02 18:17:18 -070024namespace constants {
25namespace {
26
27const uint16_t kCompTeamNumber = 971;
28const uint16_t kPracticeTeamNumber = 9971;
29const uint16_t kRoboRioTeamNumber = 254;
30
31const double kCompDrivetrainEncoderRatio =
32 (18.0 / 50.0) /*output reduction*/ * (56.0 / 30.0) /*encoder gears*/;
33const double kCompLowGearRatio = 18.0 / 60.0 * 18.0 / 50.0;
34const double kCompHighGearRatio = 28.0 / 50.0 * 18.0 / 50.0;
35
36const double kPracticeDrivetrainEncoderRatio = kCompDrivetrainEncoderRatio;
37const double kPracticeLowGearRatio = kCompLowGearRatio;
38const double kPracticeHighGearRatio = kCompHighGearRatio;
39
Brian Silverman1463c092020-10-30 17:28:24 -070040const DualHallShifterHallEffect kCompLeftDriveShifter{
41 {2.33, 4.25, 0.2, 0.7}, 2.61, 3.28};
42const DualHallShifterHallEffect kCompRightDriveShifter{
43 {4.31, 4.32, 0.2, 0.7}, 2.94, 3.25};
Brian Silverman17f503e2015-08-02 18:17:18 -070044
Brian Silverman1463c092020-10-30 17:28:24 -070045const DualHallShifterHallEffect kPracticeLeftDriveShifter{
46 {3.05, 4.15, 0.2, 0.7}, 2.80, 3.2};
47const DualHallShifterHallEffect kPracticeRightDriveShifter{
48 {3.75, 3.80, 0.2, 0.7}, 2.90, 2.98};
Brian Silverman17f503e2015-08-02 18:17:18 -070049
Brian Silverman17f503e2015-08-02 18:17:18 -070050const double shooter_zeroing_speed = 0.05;
51const double shooter_unload_speed = 0.08;
52
53// Smaller (more negative) = opening.
54const double kCompTopClawOffset = -0.120;
55
56const Values *DoGetValuesForTeam(uint16_t team) {
57 switch (team) {
58 case 1: // for tests
59 return new Values{
60 kCompDrivetrainEncoderRatio,
61 kCompLowGearRatio,
62 kCompHighGearRatio,
63 kCompLeftDriveShifter,
64 kCompRightDriveShifter,
65 false,
Austin Schuh0e997732015-11-08 15:14:53 -080066 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -080067 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman1463c092020-10-30 17:28:24 -070068 5.0, // drivetrain max speed
Brian Silverman17f503e2015-08-02 18:17:18 -070069
70 // ShooterLimits
Brian Silverman1463c092020-10-30 17:28:24 -070071 {-0.00127,
72 0.298196,
73 -0.0017,
74 0.305054,
75 0.0149098,
Brian Silverman17f503e2015-08-02 18:17:18 -070076 {-0.001778, 0.000762, 0, 0},
77 {-0.001778, 0.008906, 0, 0},
78 {0.006096, 0.026416, 0, 0},
79 shooter_zeroing_speed,
Brian Silverman1463c092020-10-30 17:28:24 -070080 shooter_unload_speed},
81 {
82 0.5,
83 0.1,
84 0.1,
85 0.0,
86 1.57,
87 0.05,
88 1.5,
89 {0.0,
90 2.05,
91 0.02,
92 2.02,
93 {-0.1, 0.05, -0.1, 0.05},
94 {1.0, 1.1, 1.0, 1.1},
95 {2.0, 2.1, 2.0, 2.1}},
96 {0.0,
97 2.05,
98 0.02,
99 2.02,
100 {-0.1, 0.05, -0.1, 0.05},
101 {1.0, 1.1, 1.0, 1.1},
102 {2.0, 2.1, 2.0, 2.1}},
103 0.01, // claw_unimportant_epsilon
104 0.9, // start_fine_tune_pos
105 4.0,
Brian Silverman17f503e2015-08-02 18:17:18 -0700106 },
Brian Silverman1463c092020-10-30 17:28:24 -0700107 {0.07, 0.15}, // shooter_action
Brian Silverman17f503e2015-08-02 18:17:18 -0700108 };
109 break;
110 case kCompTeamNumber:
111 return new Values{
112 kCompDrivetrainEncoderRatio,
113 kCompLowGearRatio,
114 kCompHighGearRatio,
115 kCompLeftDriveShifter,
116 kCompRightDriveShifter,
117 false,
Austin Schuh0e997732015-11-08 15:14:53 -0800118 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -0800119 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman1463c092020-10-30 17:28:24 -0700120 5.0, // drivetrain max speed
Brian Silverman17f503e2015-08-02 18:17:18 -0700121
122 // ShooterLimits
Brian Silverman1463c092020-10-30 17:28:24 -0700123 {-0.001041,
124 0.296019,
125 -0.001488,
126 0.302717,
127 0.0149098,
Brian Silverman17f503e2015-08-02 18:17:18 -0700128 {-0.002, 0.000446, -0.002, 0.000446},
129 {-0.002, 0.009078, -0.002, 0.009078},
130 {0.003870, 0.026194, 0.003869, 0.026343},
131 shooter_zeroing_speed,
Brian Silverman1463c092020-10-30 17:28:24 -0700132 shooter_unload_speed},
133 {
134 0.800000,
135 0.400000,
136 0.000000,
137 -1.220821,
138 1.822142,
139 -0.849484,
140 1.42309,
141 // 0.0371
142 {-3.3284,
143 2.0917,
144 -3.1661,
145 1.95,
146 {-3.4, -3.02 + kCompTopClawOffset, -3.4,
147 -2.9876 + kCompTopClawOffset},
148 {-0.1433 + kCompTopClawOffset, 0.0670 + kCompTopClawOffset,
149 -0.1460 + kCompTopClawOffset, 0.0648 + kCompTopClawOffset},
150 {1.9952 + kCompTopClawOffset, 2.2, 1.9898 + kCompTopClawOffset,
151 2.2}},
152 {-2.453460,
153 3.082960,
154 -2.453460,
155 3.082960,
156 {-2.6, -2.185752, -2.6, -2.184843},
157 {-0.322249, -0.053177, -0.332248, -0.059086},
158 {2.892065, 3.2, 2.888429, 3.2}},
159 0.040000, // claw_unimportant_epsilon
160 -0.400000, // start_fine_tune_pos
161 4.000000,
Brian Silverman17f503e2015-08-02 18:17:18 -0700162 },
Brian Silverman1463c092020-10-30 17:28:24 -0700163 // TODO(james): Get realer numbers for shooter_action.
164 {0.07, 0.15}, // shooter_action
Brian Silverman17f503e2015-08-02 18:17:18 -0700165 };
166 break;
167 case kPracticeTeamNumber:
168 case kRoboRioTeamNumber:
169 return new Values{
170 kPracticeDrivetrainEncoderRatio,
171 kPracticeLowGearRatio,
172 kPracticeHighGearRatio,
173 kPracticeLeftDriveShifter,
174 kPracticeRightDriveShifter,
175 false,
Austin Schuh0e997732015-11-08 15:14:53 -0800176 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -0800177 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman1463c092020-10-30 17:28:24 -0700178 5.0, // drivetrain max speed
Brian Silverman17f503e2015-08-02 18:17:18 -0700179
180 // ShooterLimits
Brian Silverman1463c092020-10-30 17:28:24 -0700181 {-0.001042,
182 0.294084,
183 -0.001935,
184 0.303460,
185 0.0138401,
Brian Silverman17f503e2015-08-02 18:17:18 -0700186 {-0.002, 0.000446, -0.002, 0.000446},
Brian Silvermanba622de2017-08-05 19:27:17 -0700187 {-0.002 + 0.001, 0.009078 + 0.001, -0.002 + 0.001, 0.009078 + 0.001},
Brian Silverman1463c092020-10-30 17:28:24 -0700188 {0.003869 + 0.001, 0.026194 + 0.001, 0.003869 + 0.001,
189 0.026194 + 0.001},
Brian Silverman17f503e2015-08-02 18:17:18 -0700190 shooter_zeroing_speed,
Brian Silverman1463c092020-10-30 17:28:24 -0700191 shooter_unload_speed},
192 {
193 0.400000 * 2.0,
194 0.200000 * 2.0,
195 0.000000 * 2.0,
196 -0.762218 * 2.0,
197 1.767146,
198 -0.849484,
199 1.42308,
200 {-3.364758,
201 2.086668,
202 -3.166136,
203 1.95,
204 {-1.7 * 2.0, -1.544662 * 2.0 + 0.139081, -1.7 * 2.0,
205 -1.547616 * 2.0 + 0.139081 + 0.013636},
206 {-0.115446 * 2.0, 0.030452 * 2.0, -0.120900 * 2.0,
207 0.023862 * 2.0},
208 {0.977884 * 2.0, 1.4 * 2.0, 0.963113 * 2.0, 1.4 * 2.0}},
209 {-2.451642,
210 3.107504,
211 -2.273474,
212 2.750,
213 {-1.5 * 2.0, -1.027199 * 2.0, -1.5 * 2.0, -1.037880 * 2.0},
214 {-0.116355 * 2.0, 0.017726 * 2.0, -0.125673 * 2.0,
215 0.008636 * 2.0},
216 {2.894792 + 0.122719, 3.2, 2.887974 + 0.122719 - 0.029088, 3.2}},
217 0.040000, // claw_unimportant_epsilon
218 -0.400000, // start_fine_tune_pos
219 4.000000,
Brian Silverman17f503e2015-08-02 18:17:18 -0700220 },
Brian Silverman1463c092020-10-30 17:28:24 -0700221 // TODO(james): Get realer numbers for shooter_action.
222 {0.07, 0.15}, // shooter_action
Brian Silverman17f503e2015-08-02 18:17:18 -0700223 };
224 break;
225 default:
Austin Schuhf257f3c2019-10-27 21:00:43 -0700226 AOS_LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
Brian Silverman17f503e2015-08-02 18:17:18 -0700227 }
228}
229
John Park54de36c2019-11-11 19:14:10 -0800230void DoGetValues(const Values **result) {
Brian Silverman17f503e2015-08-02 18:17:18 -0700231 uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700232 AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
John Park54de36c2019-11-11 19:14:10 -0800233 *result = DoGetValuesForTeam(team);
234 return;
Brian Silverman17f503e2015-08-02 18:17:18 -0700235}
236
237} // namespace
238
239const Values &GetValues() {
John Park54de36c2019-11-11 19:14:10 -0800240 static absl::once_flag once;
241 static const Values *result;
242 absl::call_once(once, DoGetValues, &result);
243 return *result;
Brian Silverman17f503e2015-08-02 18:17:18 -0700244}
245
246const Values &GetValuesForTeam(uint16_t team_number) {
Brian Silverman1463c092020-10-30 17:28:24 -0700247 static aos::stl_mutex mutex;
248 std::unique_lock<aos::stl_mutex> locker(mutex);
Brian Silverman17f503e2015-08-02 18:17:18 -0700249
250 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
251 // race conditions.
252 static ::std::map<uint16_t, const Values *> values;
253
254 if (values.count(team_number) == 0) {
255 values[team_number] = DoGetValuesForTeam(team_number);
256#if __has_feature(address_sanitizer)
257 __lsan_ignore_object(values[team_number]);
258#endif
259 }
260 return *values[team_number];
261}
262
263} // namespace constants
Austin Schuh6197a182015-11-28 16:04:40 -0800264} // namespace y2014