blob: a2928a104a8305213e2addbd2bed8237c4da22f8 [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
13#include "aos/common/logging/logging.h"
14#include "aos/common/once.h"
15#include "aos/common/network/team_number.h"
16#include "aos/common/mutex.h"
17
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
25namespace frc971 {
26namespace 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
Austin Schuhe93d2202015-11-08 11:09:49 -080042const ShifterHallEffect kCompLeftDriveShifter{2.61, 2.33, 4.25, 3.28, 0.2, 0.7};
43const ShifterHallEffect kCompRightDriveShifter{2.94, 4.31, 4.32, 3.25, 0.2, 0.7};
Brian Silverman17f503e2015-08-02 18:17:18 -070044
Austin Schuhe93d2202015-11-08 11:09:49 -080045const ShifterHallEffect kPracticeLeftDriveShifter{2.80, 3.05, 4.15, 3.2, 0.2, 0.7};
46const ShifterHallEffect kPracticeRightDriveShifter{2.90, 3.75, 3.80, 2.98, 0.2, 0.7};
Brian Silverman17f503e2015-08-02 18:17:18 -070047
48const double kRobotWidth = 25.0 / 100.0 * 2.54;
49
50const 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,
66 0.5,
Austin Schuh0e997732015-11-08 15:14:53 -080067 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -080068 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman17f503e2015-08-02 18:17:18 -070069 0.02, // drivetrain done delta
70 5.0, // drivetrain max speed
71
72 // ShooterLimits
73 {-0.00127, 0.298196, -0.0017, 0.305054, 0.0149098,
74 {-0.001778, 0.000762, 0, 0},
75 {-0.001778, 0.008906, 0, 0},
76 {0.006096, 0.026416, 0, 0},
77 shooter_zeroing_speed,
78 shooter_unload_speed
79 },
80 {0.5,
81 0.1,
82 0.1,
83 0.0,
84 1.57,
85 0.05,
86 1.5,
87 {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}},
88 {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}},
89 0.01, // claw_unimportant_epsilon
90 0.9, // start_fine_tune_pos
91 4.0,
92 },
93 {0.07, 0.15}, // shooter_action
94 };
95 break;
96 case kCompTeamNumber:
97 return new Values{
98 kCompDrivetrainEncoderRatio,
99 kCompLowGearRatio,
100 kCompHighGearRatio,
101 kCompLeftDriveShifter,
102 kCompRightDriveShifter,
103 false,
104 kRobotWidth,
Austin Schuh0e997732015-11-08 15:14:53 -0800105 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -0800106 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman17f503e2015-08-02 18:17:18 -0700107 0.02, // drivetrain done delta
108 5.0, // drivetrain max speed
109
110 // ShooterLimits
111 {-0.001041, 0.296019, -0.001488, 0.302717, 0.0149098,
112 {-0.002, 0.000446, -0.002, 0.000446},
113 {-0.002, 0.009078, -0.002, 0.009078},
114 {0.003870, 0.026194, 0.003869, 0.026343},
115 shooter_zeroing_speed,
116 shooter_unload_speed
117 },
118 {0.800000,
119 0.400000,
120 0.000000,
121 -1.220821,
122 1.822142,
123 -0.849484,
124 1.42309,
125 // 0.0371
126 {-3.3284, 2.0917, -3.1661, 1.95,
127 {-3.4, -3.02 + kCompTopClawOffset, -3.4, -2.9876 + kCompTopClawOffset},
128 {-0.1433 + kCompTopClawOffset, 0.0670 + kCompTopClawOffset, -0.1460 + kCompTopClawOffset, 0.0648 + kCompTopClawOffset},
129 {1.9952 + kCompTopClawOffset, 2.2, 1.9898 + kCompTopClawOffset, 2.2}},
130 {-2.453460, 3.082960, -2.453460, 3.082960,
131 {-2.6, -2.185752, -2.6, -2.184843},
132 {-0.322249, -0.053177, -0.332248, -0.059086},
133 {2.892065, 3.2, 2.888429, 3.2}},
134 0.040000, // claw_unimportant_epsilon
135 -0.400000, // start_fine_tune_pos
136 4.000000,
137 },
138 //TODO(james): Get realer numbers for shooter_action.
139 {0.07, 0.15}, // shooter_action
140 };
141 break;
142 case kPracticeTeamNumber:
143 case kRoboRioTeamNumber:
144 return new Values{
145 kPracticeDrivetrainEncoderRatio,
146 kPracticeLowGearRatio,
147 kPracticeHighGearRatio,
148 kPracticeLeftDriveShifter,
149 kPracticeRightDriveShifter,
150 false,
151 kRobotWidth,
Austin Schuh0e997732015-11-08 15:14:53 -0800152 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
Austin Schuh572ff402015-11-08 12:17:50 -0800153 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
Brian Silverman17f503e2015-08-02 18:17:18 -0700154 0.02, // drivetrain done delta
155 5.0, // drivetrain max speed
156
157 // ShooterLimits
158 {-0.001042, 0.294084, -0.001935, 0.303460, 0.0138401,
159 {-0.002, 0.000446, -0.002, 0.000446},
160 {-0.002, 0.009078, -0.002, 0.009078},
161 {0.003869, 0.026194, 0.003869, 0.026194},
162 shooter_zeroing_speed,
163 shooter_unload_speed
164 },
165 {0.400000 * 2.0,
166 0.200000 * 2.0,
167 0.000000 * 2.0,
168 -0.762218 * 2.0,
169 1.767146,
170 -0.849484,
171 1.42308,
172 {-3.364758, 2.086668, -3.166136, 1.95,
Austin Schuha96bbae2015-10-08 06:40:59 +0000173 {-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 -0700174 {-0.115446 * 2.0, 0.030452 * 2.0, -0.120900 * 2.0, 0.023862 * 2.0},
175 {0.977884 * 2.0, 1.4 * 2.0, 0.963113 * 2.0, 1.4 * 2.0}},
Brian Silverman17f503e2015-08-02 18:17:18 -0700176 {-2.451642, 3.107504, -2.273474, 2.750,
Brian Silvermance1a3432015-08-29 19:27:35 -0700177 {-1.5 * 2.0, -1.027199 * 2.0, -1.5 * 2.0, -1.037880 * 2.0},
178 {-0.116355 * 2.0, 0.017726 * 2.0, -0.125673 * 2.0, 0.008636 * 2.0},
Austin Schuha96bbae2015-10-08 06:40:59 +0000179 {2.894792 + 0.122719, 3.2, 2.887974 + 0.122719 - 0.029088, 3.2}},
Brian Silverman17f503e2015-08-02 18:17:18 -0700180 0.040000, // claw_unimportant_epsilon
181 -0.400000, // start_fine_tune_pos
182 4.000000,
183 },
184 //TODO(james): Get realer numbers for shooter_action.
185 {0.07, 0.15}, // shooter_action
186 };
187 break;
188 default:
189 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
190 }
191}
192
193const Values *DoGetValues() {
194 uint16_t team = ::aos::network::GetTeamNumber();
195 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
196 return DoGetValuesForTeam(team);
197}
198
199} // namespace
200
201const Values &GetValues() {
202 static ::aos::Once<const Values> once(DoGetValues);
203 return *once.Get();
204}
205
206const Values &GetValuesForTeam(uint16_t team_number) {
207 static ::aos::Mutex mutex;
208 ::aos::MutexLocker locker(&mutex);
209
210 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
211 // race conditions.
212 static ::std::map<uint16_t, const Values *> values;
213
214 if (values.count(team_number) == 0) {
215 values[team_number] = DoGetValuesForTeam(team_number);
216#if __has_feature(address_sanitizer)
217 __lsan_ignore_object(values[team_number]);
218#endif
219 }
220 return *values[team_number];
221}
222
223} // namespace constants
224} // namespace frc971