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" |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 15 | #include "y2022/control_loops/superstructure/climber/integral_climber_plant.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 16 | |
| 17 | namespace y2022 { |
| 18 | namespace constants { |
| 19 | |
| 20 | const int Values::kZeroingSampleSize; |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | const uint16_t kCompTeamNumber = 971; |
| 25 | const uint16_t kPracticeTeamNumber = 9971; |
| 26 | const uint16_t kCodingRobotTeamNumber = 7971; |
| 27 | |
| 28 | const Values *DoGetValuesForTeam(uint16_t team) { |
| 29 | Values *const r = new Values(); |
| 30 | |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 31 | // 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 Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 62 | // 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-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 72 | switch (team) { |
| 73 | // A set of constants for tests. |
| 74 | case 1: |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 75 | climber->potentiometer_offset = 0.0; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 76 | break; |
| 77 | |
| 78 | case kCompTeamNumber: |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 79 | climber->potentiometer_offset = 0.0; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 80 | break; |
| 81 | |
| 82 | case kPracticeTeamNumber: |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 83 | climber->potentiometer_offset = 0.0; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 84 | break; |
| 85 | |
| 86 | case kCodingRobotTeamNumber: |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 87 | climber->potentiometer_offset = 0.0; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 88 | break; |
| 89 | |
| 90 | default: |
| 91 | LOG(FATAL) << "unknown team: " << team; |
| 92 | } |
| 93 | |
| 94 | return r; |
| 95 | } |
| 96 | |
| 97 | const Values *values = nullptr; |
| 98 | |
| 99 | void 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 | |
| 107 | void InitValues() { |
| 108 | static absl::once_flag once; |
| 109 | absl::call_once(once, DoGetValues); |
| 110 | } |
| 111 | |
| 112 | const 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 |