blob: ec987433388ae4ef9be140cb4e20a1f285f03700 [file] [log] [blame]
Brian Silverman431500a2013-10-28 19:50:15 -07001#include "frc971/constants.h"
2
3#include <math.h>
4#include <stdint.h>
5#include <inttypes.h>
6
Brian Silverman0a151c92014-05-02 15:28:44 -07007#include <map>
8
9#if __has_feature(address_sanitizer)
10#include "sanitizer/lsan_interface.h"
11#endif
12
Brian Silverman431500a2013-10-28 19:50:15 -070013#include "aos/common/logging/logging.h"
14#include "aos/common/once.h"
15#include "aos/common/network/team_number.h"
Brian Silverman0a151c92014-05-02 15:28:44 -070016#include "aos/common/mutex.h"
Brian Silverman431500a2013-10-28 19:50:15 -070017
Brian Silverman2c590c32013-11-04 18:08:54 -080018#include "frc971/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
Brian Silverman2c590c32013-11-04 18:08:54 -080019#include "frc971/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Brian Silverman2c590c32013-11-04 18:08:54 -080020
Brian Silverman431500a2013-10-28 19:50:15 -070021#ifndef M_PI
22#define M_PI 3.14159265358979323846
23#endif
24
25namespace frc971 {
26namespace constants {
27namespace {
28
Brian Silvermane5db0c62014-03-13 15:53:18 -070029const uint16_t kCompTeamNumber = 971;
Brian Silvermana20703b2014-03-20 14:29:37 -070030const uint16_t kPracticeTeamNumber = 9971;
Comran Morshed79bd3db2015-02-07 14:51:13 +000031
32// ///// Drivetrain Constants
Brian Silvermane5db0c62014-03-13 15:53:18 -070033
Daniel Pettia7827412015-02-13 20:55:57 -080034// These three constants were set by Daniel on 2/13/15.
Austin Schuh58baa352015-02-20 22:08:26 -080035const double kDrivetrainEncoderRatio = 20.0 / 50.0;
Daniel Pettia7827412015-02-13 20:55:57 -080036const double kLowGearRatio = kDrivetrainEncoderRatio * 20.0 / 50.0;
37const double kHighGearRatio = kLowGearRatio;
Brian Silverman1a6590d2013-11-04 14:46:46 -080038
Brian Silvermane5db0c62014-03-13 15:53:18 -070039const ShifterHallEffect kCompRightDriveShifter{555, 657, 660, 560, 0.2, 0.7};
40const ShifterHallEffect kCompLeftDriveShifter{555, 660, 644, 552, 0.2, 0.7};
Brian Silverman6eb51f12013-11-02 14:39:01 -070041
Daniel Pettiee4fa802015-02-17 10:39:27 -080042const ShifterHallEffect kPracticeRightDriveShifter{2.95, 3.95, 3.95,
43 2.95, 0.2, 0.7};
44const ShifterHallEffect kPracticeLeftDriveShifter{2.95, 4.2, 3.95,
45 3.0, 0.2, 0.7};
Austin Schuhd8b2a242015-02-22 21:46:53 -080046const double kToteHeight = 0.3;
Brian Silvermane5db0c62014-03-13 15:53:18 -070047
Daniel Pettia7827412015-02-13 20:55:57 -080048// Set by Daniel on 2/13/15.
49// Distance from the center of the left wheel to the center of the right wheel.
50const double kRobotWidth = 37.806 /*inches*/ * 0.0254;
Brian Silverman6eb51f12013-11-02 14:39:01 -070051
Comran Morshed79bd3db2015-02-07 14:51:13 +000052// ///// Superstructure Constants
53
Comran Morshed79bd3db2015-02-07 14:51:13 +000054// Elevator gearbox pulley output constants.
55const int kElevatorGearboxOutputPulleyTeeth = 32; // 32 teeth
56const double kElevatorGearboxOutputPitch = 0.005; // 5 mm/tooth
Daniel Pettia7827412015-02-13 20:55:57 -080057const double kElevatorGearboxOutputRadianDistance =
58 kElevatorGearboxOutputPulleyTeeth * kElevatorGearboxOutputPitch /
59 (2.0 * M_PI);
Comran Morshed79bd3db2015-02-07 14:51:13 +000060
Daniel Pettie1bb13e2015-02-17 13:59:15 -080061const double kArmZeroingHeight = 0.2;
62
Brian Silverman10b8f4c2015-03-21 23:44:46 -070063const double kMaxAllowedLeftRightArmDifference = 0.12; // radians
64const double kMaxAllowedLeftRightElevatorDifference = 0.04; // meters
Austin Schuh703b8d42015-02-01 14:56:34 -080065
Benjamin Fredricksona74b0bd2015-03-07 00:32:52 -080066const Values::ClawGeometry kClawGeometry{
67 // Horizontal distance from the center of the grabber to the end.
68 0.5 * 18.0 * 0.0254,
69 // Vertical distance from the arm rotation center to the bottom of
70 // the
71 // grabber. Distance measured with arm vertical (theta = 0).
72 5.1 * 0.0254,
73 // Vertical separation of the claw and arm rotation centers with the
74 // elevator at 0.0 and the arm angle set to zero.
75 10.5 * 0.0254,
76 // Horizontal separation of the claw and arm rotation centers with
77 // the
78 // elevator at 0.0 and the arm angle set to zero.
79 6.5 * 0.0254,
80 // Distance between the center of the claw to the top of the claw.
81 // 2.75 inches would work most of the time. Using 3.5 inches because
82 // of the
83 // pnumatics fitting on the piston.
84 3.5 * 0.0254,
85 // The grabber is safe at any height if it is behind this location.
86 // The location of the grabber is used here and not the location of
87 // the end
88 // of the grabber. The grabber location is (0, 0) when the elevator
89 // is at 0
90 // and the arm angle is 0.
91 (18.0 - 0.3) * 0.0254,
92 // The grabber is safe at any x if it is above this location.
93 // The location of the grabber is used here and not the location of
94 // the end
95 // of the grabber. The grabber location is (0, 0) when the elevator
96 // is at 0
97 // and the arm angle is 0.
98 // The "-5.4" is the location of the bottom of the grabber when
99 // the elevator is at the bottom (-0.3 inches) and arm angle is 0.
100 -8.0 * 0.0254,
101};
102
Daniel Pettia7827412015-02-13 20:55:57 -0800103// Gearing ratios of the pots and encoders for the elevator and arm.
104// Ratio is output shaft rotations per encoder/pot rotation
105// Checked by Daniel on 2/13/15.
106const double kArmEncoderRatio = 18.0 / 48.0 * 16.0 / 72.0;
107const double kArmPotRatio = 48.0 / 48.0 * 16.0 / 72.0;
108const double kElevatorEncoderRatio = 14.0 / 84.0;
109const double kElevatorPotRatio = 1.0;
110const double kClawEncoderRatio = 18.0 / 72.0;
111const double kClawPotRatio = 18.0 / 72.0;
112
Comran Morshed79bd3db2015-02-07 14:51:13 +0000113// Number of radians between each index pulse on the arm.
Daniel Pettiee4fa802015-02-17 10:39:27 -0800114const double kArmEncoderIndexDifference = 2.0 * M_PI * kArmEncoderRatio;
Daniel Pettia7827412015-02-13 20:55:57 -0800115// Number of meters between each index pulse on the elevator.
Comran Morshed79bd3db2015-02-07 14:51:13 +0000116const double kElevatorEncoderIndexDifference =
Daniel Pettiee4fa802015-02-17 10:39:27 -0800117 kElevatorEncoderRatio * 2.0 * M_PI * // radians
Daniel Pettia7827412015-02-13 20:55:57 -0800118 kElevatorGearboxOutputRadianDistance;
119// Number of radians between index pulses on the claw.
Comran Morshed79bd3db2015-02-07 14:51:13 +0000120const double kClawEncoderIndexDifference = 2.0 * M_PI * kClawEncoderRatio;
121
Austin Schuh44cd5802015-03-01 00:06:09 -0800122const int kZeroingSampleSize = 200;
Brian Silvermanedcfd2d2014-04-03 13:04:16 -0700123
Philipp Schrader085bf012015-03-15 01:43:11 +0000124// The length of the arm.
125const double kArmLength = 0.7366;
126
Daniel Petti9cf68c82015-02-14 14:57:17 -0800127// TODO(danielp): All these values might need to change.
128const double kClawPistonSwitchTime = 0.4;
129const double kClawZeroingRange = 0.3;
130
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000131const Values *DoGetValuesForTeam(uint16_t team) {
Brian Silverman431500a2013-10-28 19:50:15 -0700132 switch (team) {
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800133 case 1: // for tests
134 return new Values{
Daniel Pettia7827412015-02-13 20:55:57 -0800135 kDrivetrainEncoderRatio,
136 kArmEncoderRatio,
137 kArmPotRatio,
138 kElevatorEncoderRatio,
139 kElevatorPotRatio,
140 kElevatorGearboxOutputRadianDistance,
141 kClawEncoderRatio,
142 kClawPotRatio,
Daniel Pettidfc90ba2015-02-17 21:42:15 -0800143 kToteHeight,
Daniel Pettia7827412015-02-13 20:55:57 -0800144 kLowGearRatio,
145 kHighGearRatio,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800146 kCompLeftDriveShifter,
147 kCompRightDriveShifter,
Austin Schuh11726212014-03-02 14:01:02 -0800148 false,
Brian Silvermanad9e0002014-04-13 14:55:57 -0700149 0.5,
Austin Schuha25a0412014-03-09 00:50:04 -0800150 control_loops::MakeVelocityDrivetrainLoop,
151 control_loops::MakeDrivetrainLoop,
Comran Morshed79bd3db2015-02-07 14:51:13 +0000152 0.02, // drivetrain done delta
153 5.0, // drivetrain max speed
154
Comran Morshed79bd3db2015-02-07 14:51:13 +0000155 // Motion ranges: hard_lower_limit, hard_upper_limit,
156 // soft_lower_limit, soft_upper_limit
Daniel Pettiee4fa802015-02-17 10:39:27 -0800157 {// Claw values, in radians.
158 // 0 is level with the ground.
159 // Positive moves in the direction of positive encoder values.
Brian Silverman24e37ad2015-02-18 01:58:08 -0500160 {-0.05, M_PI / 2.0 + 0.1, 0.0, M_PI / 2.0},
Daniel Pettia7827412015-02-13 20:55:57 -0800161
Daniel Pettiee4fa802015-02-17 10:39:27 -0800162 // Zeroing constants for wrist.
Adam Snaider3cd11c52015-02-16 02:16:09 +0000163 {kZeroingSampleSize, kClawEncoderIndexDifference, 0.9, 0.3},
Daniel Petti9cf68c82015-02-14 14:57:17 -0800164
Brian Silverman24e37ad2015-02-18 01:58:08 -0500165 6.308141,
Daniel Pettiee4fa802015-02-17 10:39:27 -0800166 kClawPistonSwitchTime,
167 kClawZeroingRange},
Comran Morshed79bd3db2015-02-07 14:51:13 +0000168
Daniel Pettiee4fa802015-02-17 10:39:27 -0800169 {// Elevator values, in meters.
Brian Silverman24e37ad2015-02-18 01:58:08 -0500170 // 0 is the portion of the elevator carriage that Spencer removed
171 // lining up with the bolt.
172 // Positive is up.
Austin Schuh813b9af2015-03-08 18:46:58 -0700173 {-0.005, 0.689000, 0.010000, 0.680000},
Comran Morshed79bd3db2015-02-07 14:51:13 +0000174
Daniel Pettiee4fa802015-02-17 10:39:27 -0800175 // Arm values, in radians.
176 // 0 is sticking straight out horizontally over the intake/front.
177 // Positive is rotating up and into the robot (towards the back).
Brian Silverman24e37ad2015-02-18 01:58:08 -0500178 {-M_PI / 2 - 0.05, M_PI / 2 + 0.05, -M_PI / 2, M_PI / 2},
Daniel Pettia7827412015-02-13 20:55:57 -0800179
Daniel Pettiee4fa802015-02-17 10:39:27 -0800180 // Elevator zeroing constants: left, right.
Adam Snaider3cd11c52015-02-16 02:16:09 +0000181 {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.0, 0.3},
182 {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.0, 0.3},
Daniel Pettiee4fa802015-02-17 10:39:27 -0800183 // Arm zeroing constants: left, right.
Adam Snaider3cd11c52015-02-16 02:16:09 +0000184 {kZeroingSampleSize, kArmEncoderIndexDifference, 0.0, 0.3},
185 {kZeroingSampleSize, kArmEncoderIndexDifference, 0.0, 0.3},
Brian Silverman24e37ad2015-02-18 01:58:08 -0500186 0.7,
187 -0.08,
188 -3.5 - 0.01 - -0.02,
189 3.5 - 0.17 - -0.15,
Daniel Pettie1bb13e2015-02-17 13:59:15 -0800190
Daniel Pettiee4fa802015-02-17 10:39:27 -0800191 kArmZeroingHeight,
Philipp Schrader085bf012015-03-15 01:43:11 +0000192 kArmLength,
Austin Schuh703b8d42015-02-01 14:56:34 -0800193 },
Comran Morshed79bd3db2015-02-07 14:51:13 +0000194 // End "sensor" values.
Austin Schuh703b8d42015-02-01 14:56:34 -0800195
196 kMaxAllowedLeftRightArmDifference,
197 kMaxAllowedLeftRightElevatorDifference,
Benjamin Fredricksona74b0bd2015-03-07 00:32:52 -0800198 kClawGeometry,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800199 };
200 break;
Austin Schuh58baa352015-02-20 22:08:26 -0800201 case kPracticeTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -0800202 return new Values{
Daniel Pettia7827412015-02-13 20:55:57 -0800203 kDrivetrainEncoderRatio,
204 kArmEncoderRatio,
205 kArmPotRatio,
206 kElevatorEncoderRatio,
207 kElevatorPotRatio,
208 kElevatorGearboxOutputRadianDistance,
209 kClawEncoderRatio,
210 kClawPotRatio,
Daniel Pettidfc90ba2015-02-17 21:42:15 -0800211 kToteHeight,
Daniel Pettia7827412015-02-13 20:55:57 -0800212 kLowGearRatio,
213 kHighGearRatio,
Austin Schuh288c8c32014-02-16 17:20:17 -0800214 kCompLeftDriveShifter,
215 kCompRightDriveShifter,
Brian Silvermanedcfd2d2014-04-03 13:04:16 -0700216 false,
Brian Silvermanad9e0002014-04-13 14:55:57 -0700217 kRobotWidth,
Austin Schuha25a0412014-03-09 00:50:04 -0800218 control_loops::MakeVelocityDrivetrainLoop,
219 control_loops::MakeDrivetrainLoop,
Comran Morshed79bd3db2015-02-07 14:51:13 +0000220 0.02, // drivetrain done delta
221 5.0, // drivetrain max speed
222
Comran Morshed79bd3db2015-02-07 14:51:13 +0000223 // Motion ranges: hard_lower_limit, hard_upper_limit,
224 // soft_lower_limit, soft_upper_limit
225 // TODO(sensors): Get actual bounds before turning on robot.
Austin Schuh0b406bb2015-02-17 02:28:48 -0800226 {// Claw values, in radians.
227 // 0 is level with the ground.
228 // Positive moves in the direction of positive encoder values.
229 {-0.05, M_PI / 2.0 + 0.1, 0.0, M_PI / 2.0},
Daniel Pettia7827412015-02-13 20:55:57 -0800230
Austin Schuh0b406bb2015-02-17 02:28:48 -0800231 // Zeroing constants for wrist.
Adam Snaider3cd11c52015-02-16 02:16:09 +0000232 {kZeroingSampleSize, kClawEncoderIndexDifference, 0.9104180000000001,
233 0.3},
Daniel Petti9cf68c82015-02-14 14:57:17 -0800234
Austin Schuh0b406bb2015-02-17 02:28:48 -0800235 6.308141,
236 kClawPistonSwitchTime,
237 kClawZeroingRange},
Comran Morshed79bd3db2015-02-07 14:51:13 +0000238
Austin Schuh0b406bb2015-02-17 02:28:48 -0800239 {// Elevator values, in meters.
240 // 0 is the portion of the elevator carriage that Spencer removed
241 // lining up with the bolt.
242 // Positive is up.
Austin Schuh813b9af2015-03-08 18:46:58 -0700243 {-0.00500, 0.689000, 0.010000, 0.680000},
Comran Morshed79bd3db2015-02-07 14:51:13 +0000244
Austin Schuh0b406bb2015-02-17 02:28:48 -0800245 // Arm values, in radians.
246 // 0 is sticking straight out horizontally over the intake/front.
247 // Positive is rotating up and into the robot (towards the back).
248 {-M_PI / 2 - 0.05, M_PI / 2 + 0.05, -M_PI / 2, M_PI / 2},
Daniel Pettia7827412015-02-13 20:55:57 -0800249
Austin Schuh0b406bb2015-02-17 02:28:48 -0800250 // Elevator zeroing constants: left, right.
Austin Schuhf28bd6e2015-03-15 00:30:09 -0700251 {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.088984, 0.3},
252 {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.104557, 0.3},
Austin Schuh0b406bb2015-02-17 02:28:48 -0800253 // Arm zeroing constants: left, right.
Adam Snaider3cd11c52015-02-16 02:16:09 +0000254 {kZeroingSampleSize, kArmEncoderIndexDifference, -0.324437, 0.3},
255 {kZeroingSampleSize, kArmEncoderIndexDifference, -0.064683, 0.3},
Austin Schuhf28bd6e2015-03-15 00:30:09 -0700256 0.722230 - -0.000594 - -0.026183,
257 -0.081354 - -0.000374 - -0.024793,
Austin Schuh0b406bb2015-02-17 02:28:48 -0800258 -3.509611 - 0.007415 - -0.019081,
259 3.506927 - 0.170017 - -0.147970,
Daniel Pettiee4fa802015-02-17 10:39:27 -0800260
261 kArmZeroingHeight,
Philipp Schrader085bf012015-03-15 01:43:11 +0000262 kArmLength,
Austin Schuh703b8d42015-02-01 14:56:34 -0800263 },
Comran Morshed79bd3db2015-02-07 14:51:13 +0000264 // End "sensor" values.
Austin Schuh703b8d42015-02-01 14:56:34 -0800265
266 kMaxAllowedLeftRightArmDifference,
267 kMaxAllowedLeftRightElevatorDifference,
Benjamin Fredricksona74b0bd2015-03-07 00:32:52 -0800268 kClawGeometry,
Brian Silverman756f9ff2014-01-17 23:40:23 -0800269 };
Brian Silverman431500a2013-10-28 19:50:15 -0700270 break;
Austin Schuh58baa352015-02-20 22:08:26 -0800271 case kCompTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -0800272 return new Values{
Daniel Pettia7827412015-02-13 20:55:57 -0800273 kDrivetrainEncoderRatio,
274 kArmEncoderRatio,
275 kArmPotRatio,
276 kElevatorEncoderRatio,
277 kElevatorPotRatio,
278 kElevatorGearboxOutputRadianDistance,
279 kClawEncoderRatio,
280 kClawPotRatio,
Daniel Pettidfc90ba2015-02-17 21:42:15 -0800281 kToteHeight,
Daniel Pettia7827412015-02-13 20:55:57 -0800282 kLowGearRatio,
283 kHighGearRatio,
Austin Schuh288c8c32014-02-16 17:20:17 -0800284 kPracticeLeftDriveShifter,
285 kPracticeRightDriveShifter,
286 false,
Brian Silvermanad9e0002014-04-13 14:55:57 -0700287 kRobotWidth,
Austin Schuha25a0412014-03-09 00:50:04 -0800288 control_loops::MakeVelocityDrivetrainLoop,
289 control_loops::MakeDrivetrainLoop,
Comran Morshed79bd3db2015-02-07 14:51:13 +0000290 0.02, // drivetrain done delta
291 5.0, // drivetrain max speed
292
Comran Morshed79bd3db2015-02-07 14:51:13 +0000293 // Motion ranges: hard_lower_limit, hard_upper_limit,
294 // soft_lower_limit, soft_upper_limit
295 // TODO(sensors): Get actual bounds before turning on robot.
Austin Schuhbfb8b242015-02-16 15:45:22 -0800296 {// Claw values, in radians.
297 // 0 is level with the ground.
298 // Positive moves in the direction of positive encoder values.
299 {-0.05, M_PI / 2.0 + 0.1, 0.0, M_PI / 2.0},
Daniel Pettia7827412015-02-13 20:55:57 -0800300
Austin Schuhbfb8b242015-02-16 15:45:22 -0800301 // Zeroing constants for wrist.
302 // TODO(sensors): Get actual offsets for these.
Brian Silverman50fa41c2015-03-19 23:37:50 -0700303 {kZeroingSampleSize, kClawEncoderIndexDifference, 0.952602, 0.3},
304 6.1663463999999992 + 0.015241,
Daniel Petti9cf68c82015-02-14 14:57:17 -0800305
306 kClawPistonSwitchTime,
Daniel Pettiee4fa802015-02-17 10:39:27 -0800307 kClawZeroingRange},
Comran Morshed79bd3db2015-02-07 14:51:13 +0000308
Austin Schuhbfb8b242015-02-16 15:45:22 -0800309 {// Elevator values, in meters.
310 // 0 is at the top of the elevator frame.
311 // Positive is down towards the drivebase.
Austin Schuh813b9af2015-03-08 18:46:58 -0700312 {-0.00500, 0.689000, 0.010000, 0.680000},
Comran Morshed79bd3db2015-02-07 14:51:13 +0000313
Austin Schuhbfb8b242015-02-16 15:45:22 -0800314 // Arm values, in radians.
315 // 0 is sticking straight out horizontally over the intake/front.
316 // Positive is rotating up and into the robot (towards the back).
317 {-M_PI / 2 - 0.05, M_PI / 2 + 0.05, -M_PI / 2, M_PI / 2},
Daniel Pettia7827412015-02-13 20:55:57 -0800318
Austin Schuhbfb8b242015-02-16 15:45:22 -0800319 // Elevator zeroing constants: left, right.
Brian Silverman50fa41c2015-03-19 23:37:50 -0700320 // These are the encoder offsets.
Austin Schuhbfb8b242015-02-16 15:45:22 -0800321 // TODO(sensors): Get actual offsets for these.
Daniel Pettiee4fa802015-02-17 10:39:27 -0800322 {kZeroingSampleSize, kElevatorEncoderIndexDifference,
Brian Silverman50fa41c2015-03-19 23:37:50 -0700323 0.240286 - 0.007969 - 0.025, 0.3},
Daniel Pettiee4fa802015-02-17 10:39:27 -0800324 {kZeroingSampleSize, kElevatorEncoderIndexDifference,
Brian Silverman50fa41c2015-03-19 23:37:50 -0700325 0.234583 - 0.000143, 0.3},
Austin Schuhbfb8b242015-02-16 15:45:22 -0800326 // Arm zeroing constants: left, right.
Adam Snaider3cd11c52015-02-16 02:16:09 +0000327 {kZeroingSampleSize, kArmEncoderIndexDifference, 0.060592, 0.3},
328 {kZeroingSampleSize, kArmEncoderIndexDifference, 0.210155, 0.3},
Brian Silverman50fa41c2015-03-19 23:37:50 -0700329 // These are the potentiometer offsets.
330 0.72069366666666679 - 0.026008 - 0.024948 + 0.025,
331 -0.078959636363636357 - 0.024646 - 0.020260,
Austin Schuh58baa352015-02-20 22:08:26 -0800332 -3.509611 - 0.007415 - -0.019081 - 0.029393 - -0.013585,
333 3.506927 - 0.170017 - -0.147970 - 0.005045 - -0.026504,
Daniel Pettie1bb13e2015-02-17 13:59:15 -0800334
335 kArmZeroingHeight,
Philipp Schrader085bf012015-03-15 01:43:11 +0000336 kArmLength,
Austin Schuh703b8d42015-02-01 14:56:34 -0800337 },
Comran Morshed79bd3db2015-02-07 14:51:13 +0000338 // TODO(sensors): End "sensor" values.
Austin Schuh703b8d42015-02-01 14:56:34 -0800339
340 kMaxAllowedLeftRightArmDifference,
341 kMaxAllowedLeftRightElevatorDifference,
Benjamin Fredricksona74b0bd2015-03-07 00:32:52 -0800342 kClawGeometry,
Brian Silverman756f9ff2014-01-17 23:40:23 -0800343 };
Brian Silverman431500a2013-10-28 19:50:15 -0700344 break;
345 default:
346 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
347 }
348}
349
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000350const Values *DoGetValues() {
351 uint16_t team = ::aos::network::GetTeamNumber();
352 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
353 return DoGetValuesForTeam(team);
354}
355
Brian Silverman431500a2013-10-28 19:50:15 -0700356} // namespace
357
358const Values &GetValues() {
359 static ::aos::Once<const Values> once(DoGetValues);
360 return *once.Get();
361}
362
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000363const Values &GetValuesForTeam(uint16_t team_number) {
Brian Silverman0a151c92014-05-02 15:28:44 -0700364 static ::aos::Mutex mutex;
365 ::aos::MutexLocker locker(&mutex);
366
367 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
368 // race conditions.
369 static ::std::map<uint16_t, const Values *> values;
370
371 if (values.count(team_number) == 0) {
372 values[team_number] = DoGetValuesForTeam(team_number);
373#if __has_feature(address_sanitizer)
374 __lsan_ignore_object(values[team_number]);
375#endif
376 }
377 return *values[team_number];
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000378}
379
Brian Silverman431500a2013-10-28 19:50:15 -0700380} // namespace constants
381} // namespace frc971