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