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: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 82 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 83 | arm_proximal->potentiometer_offset = 0.0; |
| 84 | |
| 85 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 86 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 87 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 88 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 89 | roll_joint->potentiometer_offset = 0.0; |
| 90 | |
| 91 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 92 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 93 | break; |
| 94 | |
| 95 | case kPracticeTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 96 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 97 | arm_proximal->potentiometer_offset = 0.0; |
| 98 | |
| 99 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 100 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 101 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 102 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 103 | roll_joint->potentiometer_offset = 0.0; |
| 104 | |
| 105 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 106 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 107 | break; |
| 108 | |
| 109 | case kCodingRobotTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 110 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 111 | arm_proximal->potentiometer_offset = 0.0; |
| 112 | |
| 113 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 114 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 115 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 116 | roll_joint->zeroing.measured_absolute_position = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 117 | roll_joint->potentiometer_offset = 0.0; |
| 118 | |
| 119 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 120 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 121 | break; |
| 122 | |
| 123 | default: |
| 124 | LOG(FATAL) << "unknown team: " << team; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 125 | |
| 126 | // TODO(milind): add pot range checks once we add ranges |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | return r; |
| 130 | } |
| 131 | |
| 132 | Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); } |
| 133 | |
| 134 | } // namespace constants |
| 135 | } // namespace y2023 |