blob: e71fb643d211743d4224f13a9934a7bdf5c9e608 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#include "y2022/constants.h"
2
3#include <cinttypes>
4#include <map>
5
6#if __has_feature(address_sanitizer)
7#include "sanitizer/lsan_interface.h"
8#endif
9
10#include "absl/base/call_once.h"
11#include "aos/mutex/mutex.h"
12#include "aos/network/team_number.h"
13#include "glog/logging.h"
Yash Chainani997a7492022-01-29 15:48:56 -080014#include "y2022/control_loops/superstructure/intake/integral_intake_plant.h"
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080015#include "y2022/control_loops/superstructure/climber/integral_climber_plant.h"
milind-u086d7262022-01-19 20:44:18 -080016
17namespace y2022 {
18namespace constants {
19
20const int Values::kZeroingSampleSize;
21
22namespace {
23
24const uint16_t kCompTeamNumber = 971;
25const uint16_t kPracticeTeamNumber = 9971;
26const uint16_t kCodingRobotTeamNumber = 7971;
27
28const Values *DoGetValuesForTeam(uint16_t team) {
29 Values *const r = new Values();
30
Yash Chainani997a7492022-01-29 15:48:56 -080031 // TODO(Yash): Set constants
32 // Intake constants.
33 auto *const intake = &r->intake;
34
35 intake->zeroing_voltage = 3.0;
36 intake->operating_voltage = 12.0;
37 intake->zeroing_profile_params = {0.5, 3.0};
38 intake->default_profile_params = {6.0, 30.0};
39 intake->range = Values::kIntakeRange();
40 intake->make_integral_loop =
41 control_loops::superstructure::intake::MakeIntegralIntakeLoop;
42
43 // The number of samples in the moving average filter.
44 intake->zeroing_constants.average_filter_size = Values::kZeroingSampleSize;
45 // The distance that the absolute encoder needs to complete a full rotation.
46 intake->zeroing_constants.one_revolution_distance =
47 M_PI * 2.0 * constants::Values::kIntakeEncoderRatio();
48
49 // Threshold for deciding if we are moving. moving_buffer_size samples need to
50 // be within this distance of each other before we use the middle one to zero.
51 intake->zeroing_constants.zeroing_threshold = 0.0005;
52 // Buffer size for deciding if we are moving.
53 intake->zeroing_constants.moving_buffer_size = 20;
54
55 // Value between 0 and 1 indicating what fraction of one_revolution_distance
56 // it is acceptable for the offset to move.
57 intake->zeroing_constants.allowable_encoder_error = 0.9;
58
59 // Measured absolute position of the encoder when at zero.
60 intake->zeroing_constants.measured_absolute_position = 0.0;
61
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080062 // Climber constants
63 auto *const climber = &r->climber;
64 climber->subsystem_params.zeroing_voltage = 3.0;
65 climber->subsystem_params.operating_voltage = 12.0;
66 climber->subsystem_params.zeroing_profile_params = {0.5, 0.1};
67 climber->subsystem_params.default_profile_params = {6.0, 1.0};
68 climber->subsystem_params.range = Values::kClimberRange();
69 climber->subsystem_params.make_integral_loop =
70 control_loops::superstructure::climber::MakeIntegralClimberLoop;
71
milind-u086d7262022-01-19 20:44:18 -080072 switch (team) {
73 // A set of constants for tests.
74 case 1:
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080075 climber->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -080076 break;
77
78 case kCompTeamNumber:
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080079 climber->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -080080 break;
81
82 case kPracticeTeamNumber:
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080083 climber->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -080084 break;
85
86 case kCodingRobotTeamNumber:
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080087 climber->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -080088 break;
89
90 default:
91 LOG(FATAL) << "unknown team: " << team;
92 }
93
94 return r;
95}
96
97const Values *values = nullptr;
98
99void DoGetValues() {
100 uint16_t team = ::aos::network::GetTeamNumber();
101 LOG(INFO) << "creating a Constants for team: " << team;
102 values = DoGetValuesForTeam(team);
103}
104
105} // namespace
106
107void InitValues() {
108 static absl::once_flag once;
109 absl::call_once(once, DoGetValues);
110}
111
112const Values &GetValues() {
113 CHECK(values)
114 << "Values are uninitialized. Call InitValues before accessing them.";
115 return *values;
116}
117
118} // namespace constants
119} // namespace y2022