milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | #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 Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 14 | #include "y2022/control_loops/superstructure/intake/integral_intake_plant.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 15 | |
| 16 | namespace y2022 { |
| 17 | namespace constants { |
| 18 | |
| 19 | const int Values::kZeroingSampleSize; |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | const uint16_t kCompTeamNumber = 971; |
| 24 | const uint16_t kPracticeTeamNumber = 9971; |
| 25 | const uint16_t kCodingRobotTeamNumber = 7971; |
| 26 | |
| 27 | const Values *DoGetValuesForTeam(uint16_t team) { |
| 28 | Values *const r = new Values(); |
| 29 | |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 30 | // TODO(Yash): Set constants |
| 31 | // Intake constants. |
| 32 | auto *const intake = &r->intake; |
| 33 | |
| 34 | intake->zeroing_voltage = 3.0; |
| 35 | intake->operating_voltage = 12.0; |
| 36 | intake->zeroing_profile_params = {0.5, 3.0}; |
| 37 | intake->default_profile_params = {6.0, 30.0}; |
| 38 | intake->range = Values::kIntakeRange(); |
| 39 | intake->make_integral_loop = |
| 40 | control_loops::superstructure::intake::MakeIntegralIntakeLoop; |
| 41 | |
| 42 | // The number of samples in the moving average filter. |
| 43 | intake->zeroing_constants.average_filter_size = Values::kZeroingSampleSize; |
| 44 | // The distance that the absolute encoder needs to complete a full rotation. |
| 45 | intake->zeroing_constants.one_revolution_distance = |
| 46 | M_PI * 2.0 * constants::Values::kIntakeEncoderRatio(); |
| 47 | |
| 48 | // Threshold for deciding if we are moving. moving_buffer_size samples need to |
| 49 | // be within this distance of each other before we use the middle one to zero. |
| 50 | intake->zeroing_constants.zeroing_threshold = 0.0005; |
| 51 | // Buffer size for deciding if we are moving. |
| 52 | intake->zeroing_constants.moving_buffer_size = 20; |
| 53 | |
| 54 | // Value between 0 and 1 indicating what fraction of one_revolution_distance |
| 55 | // it is acceptable for the offset to move. |
| 56 | intake->zeroing_constants.allowable_encoder_error = 0.9; |
| 57 | |
| 58 | // Measured absolute position of the encoder when at zero. |
| 59 | intake->zeroing_constants.measured_absolute_position = 0.0; |
| 60 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 61 | switch (team) { |
| 62 | // A set of constants for tests. |
| 63 | case 1: |
| 64 | break; |
| 65 | |
| 66 | case kCompTeamNumber: |
| 67 | break; |
| 68 | |
| 69 | case kPracticeTeamNumber: |
| 70 | break; |
| 71 | |
| 72 | case kCodingRobotTeamNumber: |
| 73 | break; |
| 74 | |
| 75 | default: |
| 76 | LOG(FATAL) << "unknown team: " << team; |
| 77 | } |
| 78 | |
| 79 | return r; |
| 80 | } |
| 81 | |
| 82 | const Values *values = nullptr; |
| 83 | |
| 84 | void DoGetValues() { |
| 85 | uint16_t team = ::aos::network::GetTeamNumber(); |
| 86 | LOG(INFO) << "creating a Constants for team: " << team; |
| 87 | values = DoGetValuesForTeam(team); |
| 88 | } |
| 89 | |
| 90 | } // namespace |
| 91 | |
| 92 | void InitValues() { |
| 93 | static absl::once_flag once; |
| 94 | absl::call_once(once, DoGetValues); |
| 95 | } |
| 96 | |
| 97 | const Values &GetValues() { |
| 98 | CHECK(values) |
| 99 | << "Values are uninitialized. Call InitValues before accessing them."; |
| 100 | return *values; |
| 101 | } |
| 102 | |
| 103 | } // namespace constants |
| 104 | } // namespace y2022 |