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 | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 36 | Values::Proximal *const proximal = &r->proximal; |
| 37 | Values::Distal *const distal = &r->distal; |
| 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 | |
| 48 | proximal->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 49 | proximal->zeroing.one_revolution_distance = |
| 50 | M_PI * 2.0 * constants::Values::kProximalEncoderRatio(); |
| 51 | proximal->zeroing.zeroing_threshold = 0.0005; |
| 52 | proximal->zeroing.moving_buffer_size = 20; |
| 53 | proximal->zeroing.allowable_encoder_error = 0.9; |
| 54 | |
| 55 | distal->zeroing.average_filter_size = Values::kZeroingSampleSize(); |
| 56 | distal->zeroing.one_revolution_distance = |
| 57 | M_PI * 2.0 * constants::Values::kDistalEncoderRatio(); |
| 58 | distal->zeroing.zeroing_threshold = 0.0005; |
| 59 | distal->zeroing.moving_buffer_size = 20; |
| 60 | distal->zeroing.allowable_encoder_error = 0.9; |
| 61 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 62 | switch (team) { |
| 63 | // A set of constants for tests. |
| 64 | case 1: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 65 | r->vision_name = "test"; |
| 66 | r->vision_error = -0.030; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame^] | 67 | |
| 68 | left_intake->zeroing.measured_absolute_position = 0.0; |
| 69 | left_intake->potentiometer_offset = 0.0; |
| 70 | left_intake->spring_offset = 0.0; |
| 71 | |
| 72 | right_intake->zeroing.measured_absolute_position = 0.0; |
| 73 | right_intake->potentiometer_offset = 0.0; |
| 74 | right_intake->spring_offset = 0.0; |
| 75 | |
| 76 | proximal->zeroing.measured_absolute_position = 0.0; |
| 77 | proximal->potentiometer_offset = 0.0; |
| 78 | |
| 79 | distal->zeroing.measured_absolute_position = 0.0; |
| 80 | distal->potentiometer_offset = 0.0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 81 | break; |
| 82 | |
| 83 | case kCompTeamNumber: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 84 | r->vision_name = "competition"; |
| 85 | r->vision_error = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame^] | 86 | |
| 87 | left_intake->zeroing.measured_absolute_position = 0.0; |
| 88 | left_intake->potentiometer_offset = 0.0; |
| 89 | left_intake->spring_offset = 0.0; |
| 90 | |
| 91 | right_intake->zeroing.measured_absolute_position = 0.0; |
| 92 | right_intake->potentiometer_offset = 0.0; |
| 93 | right_intake->spring_offset = 0.0; |
| 94 | |
| 95 | proximal->zeroing.measured_absolute_position = 0.0; |
| 96 | proximal->potentiometer_offset = 0.0; |
| 97 | |
| 98 | distal->zeroing.measured_absolute_position = 0.0; |
| 99 | distal->potentiometer_offset = 0.0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 100 | break; |
| 101 | |
| 102 | case kPracticeTeamNumber: |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 103 | r->vision_name = "practice"; |
| 104 | r->vision_error = 0.0; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame^] | 105 | |
| 106 | left_intake->zeroing.measured_absolute_position = 0.0; |
| 107 | left_intake->potentiometer_offset = 0.0; |
| 108 | left_intake->spring_offset = 0.0; |
| 109 | |
| 110 | right_intake->zeroing.measured_absolute_position = 0.0; |
| 111 | right_intake->potentiometer_offset = 0.0; |
| 112 | right_intake->spring_offset = 0.0; |
| 113 | |
| 114 | proximal->zeroing.measured_absolute_position = 0.0; |
| 115 | proximal->potentiometer_offset = 0.0; |
| 116 | |
| 117 | distal->zeroing.measured_absolute_position = 0.0; |
| 118 | distal->potentiometer_offset = 0.0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | default: |
| 122 | LOG(FATAL, "unknown team #%" PRIu16 "\n", team); |
| 123 | } |
| 124 | |
| 125 | return r; |
| 126 | } |
| 127 | |
| 128 | const Values *DoGetValues() { |
| 129 | uint16_t team = ::aos::network::GetTeamNumber(); |
| 130 | LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team); |
| 131 | return DoGetValuesForTeam(team); |
| 132 | } |
| 133 | |
| 134 | } // namespace |
| 135 | |
| 136 | const Values &GetValues() { |
| 137 | const Values &r = *DoGetValues(); |
| 138 | return r; |
| 139 | } |
| 140 | |
| 141 | const Values &GetValuesForTeam(uint16_t team_number) { |
| 142 | static ::aos::Mutex mutex; |
| 143 | ::aos::MutexLocker locker(&mutex); |
| 144 | |
| 145 | static ::std::map<uint16_t, const Values *> values; |
| 146 | |
| 147 | if (values.count(team_number) == 0) { |
| 148 | values[team_number] = DoGetValuesForTeam(team_number); |
| 149 | #if __has_feature(address_sanitizer) |
| 150 | __lsan_ignore_object(values[team_number]); |
| 151 | #endif |
| 152 | } |
| 153 | return *values[team_number]; |
| 154 | } |
| 155 | |
| 156 | } // namespace constants |
| 157 | } // namespace y2018 |