blob: 42872b9001254d20c07a5dc6684ad7794e462255 [file] [log] [blame]
Austin Schuh2a3e0632018-02-19 16:24:49 -08001#include "y2018/constants.h"
2
3#include <inttypes.h>
4#include <math.h>
5#include <stdint.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/mutex.h"
15#include "aos/common/network/team_number.h"
16#include "aos/once.h"
17
18#include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
19#include "y2018/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
20
21#ifndef M_PI
22#define M_PI 3.14159265358979323846
23#endif
24
25namespace y2018 {
26namespace constants {
27namespace {
28
29const uint16_t kCompTeamNumber = 971;
30const uint16_t kPracticeTeamNumber = 9971;
31
32const Values *DoGetValuesForTeam(uint16_t team) {
33 Values *const r = new Values();
34 Values::Intake *const intake = &r->intake;
35 Values::Proximal *const proximal = &r->proximal;
36 Values::Distal *const distal = &r->distal;
37
38 switch (team) {
39 // A set of constants for tests.
40 case 1:
41 r->down_error = 0;
42 r->vision_name = "test";
43 r->vision_error = -0.030;
44 intake->left_pot_offset = 0;
45 intake->right_pot_offset = 0;
46 proximal->pot_offset = 0;
47 distal->pot_offset = 0;
48 break;
49
50 case kCompTeamNumber:
51 r->down_error = 0;
52 r->vision_name = "competition";
53 r->vision_error = 0.0;
54 intake->left_pot_offset = 0;
55 intake->right_pot_offset = 0;
56 proximal->pot_offset = 0;
57 distal->pot_offset = 0;
58 break;
59
60 case kPracticeTeamNumber:
61 r->down_error = 0;
62 r->vision_name = "practice";
63 r->vision_error = 0.0;
64 intake->left_pot_offset = 0;
65 intake->right_pot_offset = 0;
66 proximal->pot_offset = 0;
67 distal->pot_offset = 0;
68 break;
69
70 default:
71 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
72 }
73
74 return r;
75}
76
77const Values *DoGetValues() {
78 uint16_t team = ::aos::network::GetTeamNumber();
79 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
80 return DoGetValuesForTeam(team);
81}
82
83} // namespace
84
85const Values &GetValues() {
86 const Values &r = *DoGetValues();
87 return r;
88}
89
90const Values &GetValuesForTeam(uint16_t team_number) {
91 static ::aos::Mutex mutex;
92 ::aos::MutexLocker locker(&mutex);
93
94 static ::std::map<uint16_t, const Values *> values;
95
96 if (values.count(team_number) == 0) {
97 values[team_number] = DoGetValuesForTeam(team_number);
98#if __has_feature(address_sanitizer)
99 __lsan_ignore_object(values[team_number]);
100#endif
101 }
102 return *values[team_number];
103}
104
105} // namespace constants
106} // namespace y2018