blob: a1b8d2a3354280c6f0171e48c96da9045666bfa0 [file] [log] [blame]
Brian Silverman17f503e2015-08-02 18:17:18 -07001#include "y2014/constants.h"
2
3#include <math.h>
4#include <stdint.h>
5#include <inttypes.h>
6
7#include <map>
8
9#if __has_feature(address_sanitizer)
10#include "sanitizer/lsan_interface.h"
11#endif
12
John Park33858a32018-09-28 23:05:48 -070013#include "aos/logging/logging.h"
14#include "aos/mutex/mutex.h"
15#include "aos/network/team_number.h"
John Park54de36c2019-11-11 19:14:10 -080016#include "absl/base/call_once.h"
Brian Silverman17f503e2015-08-02 18:17:18 -070017
18#include "y2014/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
19#include "y2014/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
20
21#ifndef M_PI
22#define M_PI 3.14159265358979323846
23#endif
24
Austin Schuh6197a182015-11-28 16:04:40 -080025namespace y2014 {
Brian Silverman17f503e2015-08-02 18:17:18 -070026namespace constants {
27namespace {
28
29const uint16_t kCompTeamNumber = 971;
30const uint16_t kPracticeTeamNumber = 9971;
31const uint16_t kRoboRioTeamNumber = 254;
32
33const double kCompDrivetrainEncoderRatio =
34 (18.0 / 50.0) /*output reduction*/ * (56.0 / 30.0) /*encoder gears*/;
35const double kCompLowGearRatio = 18.0 / 60.0 * 18.0 / 50.0;
36const double kCompHighGearRatio = 28.0 / 50.0 * 18.0 / 50.0;
37
38const double kPracticeDrivetrainEncoderRatio = kCompDrivetrainEncoderRatio;
39const double kPracticeLowGearRatio = kCompLowGearRatio;
40const double kPracticeHighGearRatio = kCompHighGearRatio;
41
Sabina Davis415bb6c2017-10-16 23:30:52 -070042const DualHallShifterHallEffect kCompLeftDriveShifter{{2.33, 4.25, 0.2, 0.7}, 2.61, 3.28};
43const DualHallShifterHallEffect kCompRightDriveShifter{{4.31, 4.32, 0.2, 0.7}, 2.94, 3.25};
Brian Silverman17f503e2015-08-02 18:17:18 -070044
Sabina Davis415bb6c2017-10-16 23:30:52 -070045const DualHallShifterHallEffect kPracticeLeftDriveShifter{{3.05, 4.15, 0.2, 0.7}, 2.80, 3.2};
46const DualHallShifterHallEffect kPracticeRightDriveShifter{{3.75, 3.80, 0.2, 0.7}, 2.90, 2.98};
Brian Silverman17f503e2015-08-02 18:17:18 -070047
Brian Silverman17f503e2015-08-02 18:17:18 -070048const double shooter_zeroing_speed = 0.05;
49const double shooter_unload_speed = 0.08;
50
51// Smaller (more negative) = opening.
52const double kCompTopClawOffset = -0.120;
53
54const Values *DoGetValuesForTeam(uint16_t team) {
55 switch (team) {
56 case 1: // for tests
57 return new Values{
58 kCompDrivetrainEncoderRatio,
59 kCompLowGearRatio,
60 kCompHighGearRatio,
61 kCompLeftDriveShifter,
62 kCompRightDriveShifter,
63 false,
Austin Schuh0e997732015-11-08 15:14:53 -080064 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -080065 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman17f503e2015-08-02 18:17:18 -070066 5.0, // drivetrain max speed
67
68 // ShooterLimits
69 {-0.00127, 0.298196, -0.0017, 0.305054, 0.0149098,
70 {-0.001778, 0.000762, 0, 0},
71 {-0.001778, 0.008906, 0, 0},
72 {0.006096, 0.026416, 0, 0},
73 shooter_zeroing_speed,
74 shooter_unload_speed
75 },
76 {0.5,
77 0.1,
78 0.1,
79 0.0,
80 1.57,
81 0.05,
82 1.5,
83 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, -0.1, 0.05}, {1.0, 1.1, 1.0, 1.1}, {2.0, 2.1, 2.0, 2.1}},
84 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, -0.1, 0.05}, {1.0, 1.1, 1.0, 1.1}, {2.0, 2.1, 2.0, 2.1}},
85 0.01, // claw_unimportant_epsilon
86 0.9, // start_fine_tune_pos
87 4.0,
88 },
89 {0.07, 0.15}, // shooter_action
90 };
91 break;
92 case kCompTeamNumber:
93 return new Values{
94 kCompDrivetrainEncoderRatio,
95 kCompLowGearRatio,
96 kCompHighGearRatio,
97 kCompLeftDriveShifter,
98 kCompRightDriveShifter,
99 false,
Austin Schuh0e997732015-11-08 15:14:53 -0800100 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -0800101 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman17f503e2015-08-02 18:17:18 -0700102 5.0, // drivetrain max speed
103
104 // ShooterLimits
105 {-0.001041, 0.296019, -0.001488, 0.302717, 0.0149098,
106 {-0.002, 0.000446, -0.002, 0.000446},
107 {-0.002, 0.009078, -0.002, 0.009078},
108 {0.003870, 0.026194, 0.003869, 0.026343},
109 shooter_zeroing_speed,
110 shooter_unload_speed
111 },
112 {0.800000,
113 0.400000,
114 0.000000,
115 -1.220821,
116 1.822142,
117 -0.849484,
118 1.42309,
119 // 0.0371
120 {-3.3284, 2.0917, -3.1661, 1.95,
121 {-3.4, -3.02 + kCompTopClawOffset, -3.4, -2.9876 + kCompTopClawOffset},
122 {-0.1433 + kCompTopClawOffset, 0.0670 + kCompTopClawOffset, -0.1460 + kCompTopClawOffset, 0.0648 + kCompTopClawOffset},
123 {1.9952 + kCompTopClawOffset, 2.2, 1.9898 + kCompTopClawOffset, 2.2}},
124 {-2.453460, 3.082960, -2.453460, 3.082960,
125 {-2.6, -2.185752, -2.6, -2.184843},
126 {-0.322249, -0.053177, -0.332248, -0.059086},
127 {2.892065, 3.2, 2.888429, 3.2}},
128 0.040000, // claw_unimportant_epsilon
129 -0.400000, // start_fine_tune_pos
130 4.000000,
131 },
132 //TODO(james): Get realer numbers for shooter_action.
133 {0.07, 0.15}, // shooter_action
134 };
135 break;
136 case kPracticeTeamNumber:
137 case kRoboRioTeamNumber:
138 return new Values{
139 kPracticeDrivetrainEncoderRatio,
140 kPracticeLowGearRatio,
141 kPracticeHighGearRatio,
142 kPracticeLeftDriveShifter,
143 kPracticeRightDriveShifter,
144 false,
Austin Schuh0e997732015-11-08 15:14:53 -0800145 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -0800146 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman17f503e2015-08-02 18:17:18 -0700147 5.0, // drivetrain max speed
148
149 // ShooterLimits
150 {-0.001042, 0.294084, -0.001935, 0.303460, 0.0138401,
151 {-0.002, 0.000446, -0.002, 0.000446},
Brian Silvermanba622de2017-08-05 19:27:17 -0700152 {-0.002 + 0.001, 0.009078 + 0.001, -0.002 + 0.001, 0.009078 + 0.001},
153 {0.003869 + 0.001, 0.026194 + 0.001, 0.003869 + 0.001, 0.026194 + 0.001},
Brian Silverman17f503e2015-08-02 18:17:18 -0700154 shooter_zeroing_speed,
155 shooter_unload_speed
156 },
157 {0.400000 * 2.0,
158 0.200000 * 2.0,
159 0.000000 * 2.0,
160 -0.762218 * 2.0,
161 1.767146,
162 -0.849484,
163 1.42308,
164 {-3.364758, 2.086668, -3.166136, 1.95,
Austin Schuha96bbae2015-10-08 06:40:59 +0000165 {-1.7 * 2.0, -1.544662 * 2.0 + 0.139081, -1.7 * 2.0, -1.547616 * 2.0 + 0.139081+ 0.013636},
Brian Silvermance1a3432015-08-29 19:27:35 -0700166 {-0.115446 * 2.0, 0.030452 * 2.0, -0.120900 * 2.0, 0.023862 * 2.0},
167 {0.977884 * 2.0, 1.4 * 2.0, 0.963113 * 2.0, 1.4 * 2.0}},
Brian Silverman17f503e2015-08-02 18:17:18 -0700168 {-2.451642, 3.107504, -2.273474, 2.750,
Brian Silvermance1a3432015-08-29 19:27:35 -0700169 {-1.5 * 2.0, -1.027199 * 2.0, -1.5 * 2.0, -1.037880 * 2.0},
170 {-0.116355 * 2.0, 0.017726 * 2.0, -0.125673 * 2.0, 0.008636 * 2.0},
Austin Schuha96bbae2015-10-08 06:40:59 +0000171 {2.894792 + 0.122719, 3.2, 2.887974 + 0.122719 - 0.029088, 3.2}},
Brian Silverman17f503e2015-08-02 18:17:18 -0700172 0.040000, // claw_unimportant_epsilon
173 -0.400000, // start_fine_tune_pos
174 4.000000,
175 },
176 //TODO(james): Get realer numbers for shooter_action.
177 {0.07, 0.15}, // shooter_action
178 };
179 break;
180 default:
Austin Schuhf257f3c2019-10-27 21:00:43 -0700181 AOS_LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
Brian Silverman17f503e2015-08-02 18:17:18 -0700182 }
183}
184
John Park54de36c2019-11-11 19:14:10 -0800185void DoGetValues(const Values **result) {
Brian Silverman17f503e2015-08-02 18:17:18 -0700186 uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700187 AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
John Park54de36c2019-11-11 19:14:10 -0800188 *result = DoGetValuesForTeam(team);
189 return;
Brian Silverman17f503e2015-08-02 18:17:18 -0700190}
191
192} // namespace
193
194const Values &GetValues() {
John Park54de36c2019-11-11 19:14:10 -0800195 static absl::once_flag once;
196 static const Values *result;
197 absl::call_once(once, DoGetValues, &result);
198 return *result;
Brian Silverman17f503e2015-08-02 18:17:18 -0700199}
200
201const Values &GetValuesForTeam(uint16_t team_number) {
202 static ::aos::Mutex mutex;
203 ::aos::MutexLocker locker(&mutex);
204
205 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
206 // race conditions.
207 static ::std::map<uint16_t, const Values *> values;
208
209 if (values.count(team_number) == 0) {
210 values[team_number] = DoGetValuesForTeam(team_number);
211#if __has_feature(address_sanitizer)
212 __lsan_ignore_object(values[team_number]);
213#endif
214 }
215 return *values[team_number];
216}
217
218} // namespace constants
Austin Schuh6197a182015-11-28 16:04:40 -0800219} // namespace y2014