blob: 8cf90760e81bf43afac79f2cc855878bcdd6de5f [file] [log] [blame]
Comran Morshed9a9948c2016-01-16 15:58:04 +00001#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 y2014 {
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
42const 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};
44
45const 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};
47
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,
67 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
68 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
69 5.0, // drivetrain max speed
70
71 // ShooterLimits
72 {-0.00127, 0.298196, -0.0017, 0.305054, 0.0149098,
73 {-0.001778, 0.000762, 0, 0},
74 {-0.001778, 0.008906, 0, 0},
75 {0.006096, 0.026416, 0, 0},
76 shooter_zeroing_speed,
77 shooter_unload_speed
78 },
79 {0.5,
80 0.1,
81 0.1,
82 0.0,
83 1.57,
84 0.05,
85 1.5,
86 {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}},
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.01, // claw_unimportant_epsilon
89 0.9, // start_fine_tune_pos
90 4.0,
91 },
92 {0.07, 0.15}, // shooter_action
93 };
94 break;
95 case kCompTeamNumber:
96 return new Values{
97 kCompDrivetrainEncoderRatio,
98 kCompLowGearRatio,
99 kCompHighGearRatio,
100 kCompLeftDriveShifter,
101 kCompRightDriveShifter,
102 false,
103 kRobotWidth,
104 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
105 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
106 5.0, // drivetrain max speed
107
108 // ShooterLimits
109 {-0.001041, 0.296019, -0.001488, 0.302717, 0.0149098,
110 {-0.002, 0.000446, -0.002, 0.000446},
111 {-0.002, 0.009078, -0.002, 0.009078},
112 {0.003870, 0.026194, 0.003869, 0.026343},
113 shooter_zeroing_speed,
114 shooter_unload_speed
115 },
116 {0.800000,
117 0.400000,
118 0.000000,
119 -1.220821,
120 1.822142,
121 -0.849484,
122 1.42309,
123 // 0.0371
124 {-3.3284, 2.0917, -3.1661, 1.95,
125 {-3.4, -3.02 + kCompTopClawOffset, -3.4, -2.9876 + kCompTopClawOffset},
126 {-0.1433 + kCompTopClawOffset, 0.0670 + kCompTopClawOffset, -0.1460 + kCompTopClawOffset, 0.0648 + kCompTopClawOffset},
127 {1.9952 + kCompTopClawOffset, 2.2, 1.9898 + kCompTopClawOffset, 2.2}},
128 {-2.453460, 3.082960, -2.453460, 3.082960,
129 {-2.6, -2.185752, -2.6, -2.184843},
130 {-0.322249, -0.053177, -0.332248, -0.059086},
131 {2.892065, 3.2, 2.888429, 3.2}},
132 0.040000, // claw_unimportant_epsilon
133 -0.400000, // start_fine_tune_pos
134 4.000000,
135 },
136 //TODO(james): Get realer numbers for shooter_action.
137 {0.07, 0.15}, // shooter_action
138 };
139 break;
140 case kPracticeTeamNumber:
141 case kRoboRioTeamNumber:
142 return new Values{
143 kPracticeDrivetrainEncoderRatio,
144 kPracticeLowGearRatio,
145 kPracticeHighGearRatio,
146 kPracticeLeftDriveShifter,
147 kPracticeRightDriveShifter,
148 false,
149 kRobotWidth,
150 ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
151 ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
152 5.0, // drivetrain max speed
153
154 // ShooterLimits
155 {-0.001042, 0.294084, -0.001935, 0.303460, 0.0138401,
156 {-0.002, 0.000446, -0.002, 0.000446},
157 {-0.002, 0.009078, -0.002, 0.009078},
158 {0.003869, 0.026194, 0.003869, 0.026194},
159 shooter_zeroing_speed,
160 shooter_unload_speed
161 },
162 {0.400000 * 2.0,
163 0.200000 * 2.0,
164 0.000000 * 2.0,
165 -0.762218 * 2.0,
166 1.767146,
167 -0.849484,
168 1.42308,
169 {-3.364758, 2.086668, -3.166136, 1.95,
170 {-1.7 * 2.0, -1.544662 * 2.0 + 0.139081, -1.7 * 2.0, -1.547616 * 2.0 + 0.139081+ 0.013636},
171 {-0.115446 * 2.0, 0.030452 * 2.0, -0.120900 * 2.0, 0.023862 * 2.0},
172 {0.977884 * 2.0, 1.4 * 2.0, 0.963113 * 2.0, 1.4 * 2.0}},
173 {-2.451642, 3.107504, -2.273474, 2.750,
174 {-1.5 * 2.0, -1.027199 * 2.0, -1.5 * 2.0, -1.037880 * 2.0},
175 {-0.116355 * 2.0, 0.017726 * 2.0, -0.125673 * 2.0, 0.008636 * 2.0},
176 {2.894792 + 0.122719, 3.2, 2.887974 + 0.122719 - 0.029088, 3.2}},
177 0.040000, // claw_unimportant_epsilon
178 -0.400000, // start_fine_tune_pos
179 4.000000,
180 },
181 //TODO(james): Get realer numbers for shooter_action.
182 {0.07, 0.15}, // shooter_action
183 };
184 break;
185 default:
186 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
187 }
188}
189
190const Values *DoGetValues() {
191 uint16_t team = ::aos::network::GetTeamNumber();
192 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
193 return DoGetValuesForTeam(team);
194}
195
196} // namespace
197
198const Values &GetValues() {
199 static ::aos::Once<const Values> once(DoGetValues);
200 return *once.Get();
201}
202
203const Values &GetValuesForTeam(uint16_t team_number) {
204 static ::aos::Mutex mutex;
205 ::aos::MutexLocker locker(&mutex);
206
207 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
208 // race conditions.
209 static ::std::map<uint16_t, const Values *> values;
210
211 if (values.count(team_number) == 0) {
212 values[team_number] = DoGetValuesForTeam(team_number);
213#if __has_feature(address_sanitizer)
214 __lsan_ignore_object(values[team_number]);
215#endif
216 }
217 return *values[team_number];
218}
219
220} // namespace constants
221} // namespace y2014