Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #include "y2023/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" |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 14 | #include "y2023/control_loops/superstructure/roll/integral_roll_plant.h" |
| 15 | #include "y2023/control_loops/superstructure/wrist/integral_wrist_plant.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 16 | |
| 17 | namespace y2023 { |
| 18 | namespace constants { |
| 19 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 20 | Values MakeValues(uint16_t team) { |
| 21 | LOG(INFO) << "creating a Constants for team: " << team; |
| 22 | |
| 23 | Values r; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 24 | auto *const arm_proximal = &r.arm_proximal; |
| 25 | auto *const arm_distal = &r.arm_distal; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 26 | auto *const wrist = &r.wrist; |
| 27 | auto *const roll_joint = &r.roll_joint; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 28 | |
| 29 | arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 30 | arm_proximal->zeroing.one_revolution_distance = |
| 31 | M_PI * 2.0 * constants::Values::kProximalEncoderRatio(); |
| 32 | arm_proximal->zeroing.zeroing_threshold = 0.0005; |
| 33 | arm_proximal->zeroing.moving_buffer_size = 20; |
| 34 | arm_proximal->zeroing.allowable_encoder_error = 0.9; |
| 35 | |
| 36 | arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 37 | arm_distal->zeroing.one_revolution_distance = |
| 38 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
| 39 | arm_distal->zeroing.zeroing_threshold = 0.0005; |
| 40 | arm_distal->zeroing.moving_buffer_size = 20; |
| 41 | arm_distal->zeroing.allowable_encoder_error = 0.9; |
| 42 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 43 | roll_joint->zeroing.average_filter_size = Values::kZeroingSampleSize; |
| 44 | roll_joint->zeroing.one_revolution_distance = |
Austin Schuh | 1a3b817 | 2023-02-22 20:38:33 -0800 | [diff] [blame] | 45 | M_PI * 2.0 * constants::Values::kRollJointEncoderRatio(); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 46 | roll_joint->zeroing.zeroing_threshold = 0.0005; |
| 47 | roll_joint->zeroing.moving_buffer_size = 20; |
| 48 | roll_joint->zeroing.allowable_encoder_error = 0.9; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 49 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 50 | wrist->subsystem_params.zeroing_voltage = 3.0; |
| 51 | wrist->subsystem_params.operating_voltage = 12.0; |
| 52 | wrist->subsystem_params.zeroing_profile_params = {0.5, 3.0}; |
| 53 | wrist->subsystem_params.default_profile_params = {6.0, 30.0}; |
| 54 | wrist->subsystem_params.range = Values::kWristRange(); |
| 55 | wrist->subsystem_params.make_integral_loop = |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 56 | control_loops::superstructure::wrist::MakeIntegralWristLoop; |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 57 | wrist->subsystem_params.zeroing_constants.average_filter_size = |
| 58 | Values::kZeroingSampleSize; |
| 59 | wrist->subsystem_params.zeroing_constants.one_revolution_distance = |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 60 | M_PI * 2.0 * constants::Values::kWristEncoderRatio(); |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 61 | wrist->subsystem_params.zeroing_constants.zeroing_threshold = 0.0005; |
| 62 | wrist->subsystem_params.zeroing_constants.moving_buffer_size = 20; |
| 63 | wrist->subsystem_params.zeroing_constants.allowable_encoder_error = 0.9; |
| 64 | wrist->subsystem_params.zeroing_constants.middle_position = |
| 65 | Values::kWristRange().middle(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 66 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 67 | switch (team) { |
| 68 | // A set of constants for tests. |
| 69 | case 1: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 70 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 71 | arm_proximal->potentiometer_offset = 0.0; |
| 72 | |
| 73 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 74 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 75 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 76 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 77 | roll_joint->potentiometer_offset = 0.0; |
| 78 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 79 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 80 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 81 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 82 | break; |
| 83 | |
| 84 | case kCompTeamNumber: |
Austin Schuh | 6d59ffb | 2023-02-23 21:44:04 -0800 | [diff] [blame] | 85 | arm_proximal->zeroing.measured_absolute_position = 0.0910237406998185; |
| 86 | arm_proximal->potentiometer_offset = 0.931355973012855 + 8.6743197253382 - |
| 87 | 0.101200335326309 - |
| 88 | 0.0820901660993467; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 89 | |
Austin Schuh | 6d59ffb | 2023-02-23 21:44:04 -0800 | [diff] [blame] | 90 | arm_distal->zeroing.measured_absolute_position = 0.556077643172765; |
| 91 | arm_distal->potentiometer_offset = |
| 92 | 0.436664933370656 + 0.49457213779426 + 6.78213223139724 - |
| 93 | 0.0220711555235029 - 0.0162945074111813 + 0.00630344935527365 - |
| 94 | 0.0164398318919943; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 95 | |
Austin Schuh | 6d59ffb | 2023-02-23 21:44:04 -0800 | [diff] [blame] | 96 | roll_joint->zeroing.measured_absolute_position = 1.10682573591996; |
Austin Schuh | 7dcc49b | 2023-02-21 17:35:10 -0800 | [diff] [blame] | 97 | roll_joint->potentiometer_offset = |
| 98 | 3.87038557084874 - 0.0241774522172967 + 0.0711345168020632 - |
| 99 | 0.866186131631967 - 0.0256788357596952 + 0.18101759154572017 - |
Austin Schuh | 6d59ffb | 2023-02-23 21:44:04 -0800 | [diff] [blame] | 100 | 0.0208958996127179 - 0.186395903925026 + 0.45801689548395 - |
| 101 | 0.5935210745062; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 102 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 103 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 104 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 105 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 106 | break; |
| 107 | |
| 108 | case kPracticeTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 109 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 110 | arm_proximal->potentiometer_offset = 0.0; |
| 111 | |
| 112 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 113 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 114 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 115 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 116 | roll_joint->potentiometer_offset = 0.0; |
| 117 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 118 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 119 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 120 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 121 | break; |
| 122 | |
| 123 | case kCodingRobotTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 124 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 125 | arm_proximal->potentiometer_offset = 0.0; |
| 126 | |
| 127 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 128 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 129 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 130 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 131 | roll_joint->potentiometer_offset = 0.0; |
| 132 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 133 | wrist->subsystem_params.zeroing_constants.measured_absolute_position = |
| 134 | 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 135 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 136 | break; |
| 137 | |
| 138 | default: |
| 139 | LOG(FATAL) << "unknown team: " << team; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 140 | |
| 141 | // TODO(milind): add pot range checks once we add ranges |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return r; |
| 145 | } |
| 146 | |
| 147 | Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); } |
| 148 | |
| 149 | } // namespace constants |
| 150 | } // namespace y2023 |