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 | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame^] | 43 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 44 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 45 | *const roll_joint_params = &roll_joint->subsystem_params; |
| 46 | |
| 47 | roll_joint_params->zeroing_voltage = 3.0; |
| 48 | roll_joint_params->operating_voltage = 12.0; |
| 49 | roll_joint_params->zeroing_profile_params = {0.5, 3.0}; |
| 50 | roll_joint_params->default_profile_params = {6.0, 30.0}; |
| 51 | roll_joint_params->range = Values::kRollJointRange(); |
| 52 | roll_joint_params->make_integral_loop = |
| 53 | control_loops::superstructure::roll::MakeIntegralRollLoop; |
| 54 | roll_joint_params->zeroing_constants.average_filter_size = |
| 55 | Values::kZeroingSampleSize; |
| 56 | roll_joint_params->zeroing_constants.one_revolution_distance = |
| 57 | M_PI * 2.0 * constants::Values::kRollJointEncoderRatio(); |
| 58 | roll_joint_params->zeroing_constants.zeroing_threshold = 0.0005; |
| 59 | roll_joint_params->zeroing_constants.moving_buffer_size = 20; |
| 60 | roll_joint_params->zeroing_constants.allowable_encoder_error = 0.9; |
| 61 | |
| 62 | wrist->zeroing_voltage = 3.0; |
| 63 | wrist->operating_voltage = 12.0; |
| 64 | wrist->zeroing_profile_params = {0.5, 3.0}; |
| 65 | wrist->default_profile_params = {6.0, 30.0}; |
| 66 | wrist->range = Values::kWristRange(); |
| 67 | wrist->make_integral_loop = |
| 68 | control_loops::superstructure::wrist::MakeIntegralWristLoop; |
| 69 | wrist->zeroing_constants.average_filter_size = Values::kZeroingSampleSize; |
| 70 | wrist->zeroing_constants.one_revolution_distance = |
| 71 | M_PI * 2.0 * constants::Values::kWristEncoderRatio(); |
| 72 | wrist->zeroing_constants.zeroing_threshold = 0.0005; |
| 73 | wrist->zeroing_constants.moving_buffer_size = 20; |
| 74 | wrist->zeroing_constants.allowable_encoder_error = 0.9; |
| 75 | wrist->zeroing_constants.middle_position = Values::kWristRange().middle(); |
| 76 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 77 | switch (team) { |
| 78 | // A set of constants for tests. |
| 79 | case 1: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 80 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 81 | arm_proximal->potentiometer_offset = 0.0; |
| 82 | |
| 83 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 84 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame^] | 85 | |
| 86 | roll_joint_params->zeroing_constants.measured_absolute_position = 0.0; |
| 87 | roll_joint->potentiometer_offset = 0.0; |
| 88 | |
| 89 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 90 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 91 | break; |
| 92 | |
| 93 | case kCompTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 94 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 95 | arm_proximal->potentiometer_offset = 0.0; |
| 96 | |
| 97 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 98 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame^] | 99 | |
| 100 | roll_joint_params->zeroing_constants.measured_absolute_position = 0.0; |
| 101 | roll_joint->potentiometer_offset = 0.0; |
| 102 | |
| 103 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 104 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 105 | break; |
| 106 | |
| 107 | case kPracticeTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 108 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 109 | arm_proximal->potentiometer_offset = 0.0; |
| 110 | |
| 111 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 112 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame^] | 113 | |
| 114 | roll_joint_params->zeroing_constants.measured_absolute_position = 0.0; |
| 115 | roll_joint->potentiometer_offset = 0.0; |
| 116 | |
| 117 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 118 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | case kCodingRobotTeamNumber: |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 122 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 123 | arm_proximal->potentiometer_offset = 0.0; |
| 124 | |
| 125 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 126 | arm_distal->potentiometer_offset = 0.0; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame^] | 127 | |
| 128 | roll_joint_params->zeroing_constants.measured_absolute_position = 0.0; |
| 129 | roll_joint->potentiometer_offset = 0.0; |
| 130 | |
| 131 | wrist->zeroing_constants.measured_absolute_position = 0.0; |
| 132 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 133 | break; |
| 134 | |
| 135 | default: |
| 136 | LOG(FATAL) << "unknown team: " << team; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame^] | 137 | |
| 138 | // TODO(milind): add pot range checks once we add ranges |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | return r; |
| 142 | } |
| 143 | |
| 144 | Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); } |
| 145 | |
| 146 | } // namespace constants |
| 147 | } // namespace y2023 |