Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 1 | #include "y2018/constants.h" |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | #include <math.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #include <map> |
| 8 | |
| 9 | #if __has_feature(address_sanitizer) |
| 10 | #include "sanitizer/lsan_interface.h" |
| 11 | #endif |
| 12 | |
| 13 | #include "aos/common/logging/logging.h" |
| 14 | #include "aos/common/mutex.h" |
| 15 | #include "aos/common/network/team_number.h" |
| 16 | #include "aos/once.h" |
| 17 | |
| 18 | #include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
| 19 | #include "y2018/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h" |
| 20 | |
| 21 | #ifndef M_PI |
| 22 | #define M_PI 3.14159265358979323846 |
| 23 | #endif |
| 24 | |
| 25 | namespace y2018 { |
| 26 | namespace constants { |
| 27 | namespace { |
| 28 | |
| 29 | const uint16_t kCompTeamNumber = 971; |
| 30 | const uint16_t kPracticeTeamNumber = 9971; |
| 31 | |
| 32 | const Values *DoGetValuesForTeam(uint16_t team) { |
| 33 | Values *const r = new Values(); |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 34 | Values::IntakeSide *const left_intake = &r->left_intake; |
| 35 | Values::IntakeSide *const right_intake = &r->right_intake; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 36 | Values::Proximal *const arm_proximal = &r->arm_proximal; |
| 37 | Values::Distal *const arm_distal = &r->arm_distal; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 38 | |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 39 | left_intake->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 40 | left_intake->zeroing.one_revolution_distance = |
| 41 | M_PI * 2.0 * constants::Values::kIntakeMotorEncoderRatio(); |
| 42 | left_intake->zeroing.zeroing_threshold = 0.0005; |
| 43 | left_intake->zeroing.moving_buffer_size = 20; |
| 44 | left_intake->zeroing.allowable_encoder_error = 1.9; |
| 45 | |
| 46 | *right_intake = *left_intake; |
| 47 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 48 | arm_proximal->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 49 | arm_proximal->zeroing.one_revolution_distance = |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 50 | M_PI * 2.0 * constants::Values::kProximalEncoderRatio(); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 51 | arm_proximal->zeroing.zeroing_threshold = 0.0005; |
| 52 | arm_proximal->zeroing.moving_buffer_size = 20; |
| 53 | arm_proximal->zeroing.allowable_encoder_error = 0.9; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 54 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 55 | arm_distal->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 56 | arm_distal->zeroing.one_revolution_distance = |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 57 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 58 | arm_distal->zeroing.zeroing_threshold = 0.0005; |
| 59 | arm_distal->zeroing.moving_buffer_size = 20; |
| 60 | arm_distal->zeroing.allowable_encoder_error = 0.9; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 61 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame^] | 62 | constexpr double kDistalZeroingPosition = |
| 63 | M_PI * 3.0 / 2.0 + (28.5 / 180.0) * M_PI; |
| 64 | // 5.209807817203074 |
| 65 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 66 | switch (team) { |
| 67 | // A set of constants for tests. |
| 68 | case 1: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 69 | r->vision_name = "test"; |
| 70 | r->vision_error = -0.030; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 71 | |
| 72 | left_intake->zeroing.measured_absolute_position = 0.0; |
| 73 | left_intake->potentiometer_offset = 0.0; |
| 74 | left_intake->spring_offset = 0.0; |
| 75 | |
| 76 | right_intake->zeroing.measured_absolute_position = 0.0; |
| 77 | right_intake->potentiometer_offset = 0.0; |
| 78 | right_intake->spring_offset = 0.0; |
| 79 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 80 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 81 | arm_proximal->potentiometer_offset = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 82 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 83 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 84 | arm_distal->potentiometer_offset = 0.0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 85 | break; |
| 86 | |
| 87 | case kCompTeamNumber: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 88 | r->vision_name = "competition"; |
| 89 | r->vision_error = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 90 | |
| 91 | left_intake->zeroing.measured_absolute_position = 0.0; |
| 92 | left_intake->potentiometer_offset = 0.0; |
| 93 | left_intake->spring_offset = 0.0; |
| 94 | |
| 95 | right_intake->zeroing.measured_absolute_position = 0.0; |
| 96 | right_intake->potentiometer_offset = 0.0; |
| 97 | right_intake->spring_offset = 0.0; |
| 98 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 99 | arm_proximal->zeroing.measured_absolute_position = 0.0; |
| 100 | arm_proximal->potentiometer_offset = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 101 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 102 | arm_distal->zeroing.measured_absolute_position = 0.0; |
| 103 | arm_distal->potentiometer_offset = 0.0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 104 | break; |
| 105 | |
| 106 | case kPracticeTeamNumber: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 107 | r->vision_name = "practice"; |
| 108 | r->vision_error = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 109 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame^] | 110 | left_intake->zeroing.measured_absolute_position = 0.031709; |
| 111 | left_intake->potentiometer_offset = -10.55 - 3.621232 + 4.996959; |
| 112 | left_intake->spring_offset = -0.249 - 0.002; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 113 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame^] | 114 | right_intake->zeroing.measured_absolute_position = 0.351376; |
| 115 | right_intake->potentiometer_offset = 9.59 + 1.530320 - 3.620648; |
| 116 | right_intake->spring_offset = 0.255 + 0.008; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 117 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame^] | 118 | arm_proximal->zeroing.measured_absolute_position = 0.1877 + 0.02; |
| 119 | arm_proximal->potentiometer_offset = -1.242 - 0.03; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 120 | |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame^] | 121 | arm_distal->zeroing.measured_absolute_position = |
| 122 | 1.102987 - kDistalZeroingPosition; |
| 123 | arm_distal->potentiometer_offset = 2.772210 + M_PI + 0.434; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 124 | break; |
| 125 | |
| 126 | default: |
| 127 | LOG(FATAL, "unknown team #%" PRIu16 "\n", team); |
| 128 | } |
| 129 | |
| 130 | return r; |
| 131 | } |
| 132 | |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 133 | const Values &DoGetValues() { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 134 | uint16_t team = ::aos::network::GetTeamNumber(); |
| 135 | LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team); |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 136 | return GetValuesForTeam(team); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | } // namespace |
| 140 | |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 141 | const Values &GetValues() { return DoGetValues(); } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 142 | |
| 143 | const Values &GetValuesForTeam(uint16_t team_number) { |
| 144 | static ::aos::Mutex mutex; |
| 145 | ::aos::MutexLocker locker(&mutex); |
| 146 | |
| 147 | static ::std::map<uint16_t, const Values *> values; |
| 148 | |
| 149 | if (values.count(team_number) == 0) { |
| 150 | values[team_number] = DoGetValuesForTeam(team_number); |
| 151 | #if __has_feature(address_sanitizer) |
| 152 | __lsan_ignore_object(values[team_number]); |
| 153 | #endif |
| 154 | } |
| 155 | return *values[team_number]; |
| 156 | } |
| 157 | |
| 158 | } // namespace constants |
| 159 | } // namespace y2018 |