| #include "y2020/constants.h" |
| |
| #include <inttypes.h> |
| |
| #include <map> |
| |
| #if __has_feature(address_sanitizer) |
| #include "sanitizer/lsan_interface.h" |
| #endif |
| |
| #include "absl/base/call_once.h" |
| #include "aos/logging/logging.h" |
| #include "aos/mutex/mutex.h" |
| #include "aos/network/team_number.h" |
| #include "y2020/control_loops/superstructure/intake/integral_intake_plant.h" |
| |
| #include "y2020/control_loops/superstructure/hood/integral_hood_plant.h" |
| |
| namespace y2020 { |
| namespace constants { |
| |
| const int Values::kZeroingSampleSize; |
| |
| namespace { |
| |
| const uint16_t kCompTeamNumber = 971; |
| const uint16_t kPracticeTeamNumber = 9971; |
| const uint16_t kCodingRobotTeamNumber = 7971; |
| |
| const Values *DoGetValuesForTeam(uint16_t team) { |
| Values *const r = new Values(); |
| ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> *const hood = |
| &r->hood; |
| |
| // Hood constants. |
| hood->zeroing_voltage = 3.0; |
| hood->operating_voltage = 12.0; |
| hood->zeroing_profile_params = {0.5, 3.0}; |
| hood->default_profile_params = {6.0, 30.0}; |
| hood->range = Values::kHoodRange(); |
| hood->make_integral_loop = |
| control_loops::superstructure::hood::MakeIntegralHoodLoop; |
| hood->zeroing_constants.average_filter_size = Values::kZeroingSampleSize; |
| hood->zeroing_constants.one_revolution_distance = |
| M_PI * 2.0 * constants::Values::kHoodEncoderRatio(); |
| hood->zeroing_constants.zeroing_threshold = 0.0005; |
| hood->zeroing_constants.moving_buffer_size = 20; |
| hood->zeroing_constants.allowable_encoder_error = 0.9; |
| hood->zeroing_constants.middle_position = Values::kHoodRange().middle(); |
| |
| ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> *const intake = |
| &r->intake; |
| |
| // Intake constants. |
| intake->zeroing_voltage = 3.0; |
| intake->operating_voltage = 12.0; |
| intake->zeroing_profile_params = {0.5, 3.0}; |
| intake->default_profile_params = {6.0, 30.0}; |
| intake->range = Values::kIntakeRange(); |
| intake->make_integral_loop = |
| control_loops::superstructure::intake::MakeIntegralIntakeLoop; |
| intake->zeroing_constants.average_filter_size = Values::kZeroingSampleSize; |
| intake->zeroing_constants.one_revolution_distance = |
| M_PI * 2.0 * constants::Values::kIntakeEncoderRatio(); |
| intake->zeroing_constants.zeroing_threshold = 0.0005; |
| intake->zeroing_constants.moving_buffer_size = 20; |
| intake->zeroing_constants.allowable_encoder_error = 0.9; |
| intake->zeroing_constants.middle_position = Values::kIntakeRange().middle(); |
| |
| switch (team) { |
| // A set of constants for tests. |
| case 1: |
| break; |
| |
| case kCompTeamNumber: |
| hood->zeroing_constants.measured_absolute_position = 0.0; |
| intake->zeroing_constants.measured_absolute_position = 0.0; |
| break; |
| |
| case kPracticeTeamNumber: |
| hood->zeroing_constants.measured_absolute_position = 0.0; |
| intake->zeroing_constants.measured_absolute_position = 0.0; |
| break; |
| |
| case kCodingRobotTeamNumber: |
| hood->zeroing_constants.measured_absolute_position = 0.0; |
| intake->zeroing_constants.measured_absolute_position = 0.0; |
| break; |
| |
| default: |
| AOS_LOG(FATAL, "unknown team #%" PRIu16 "\n", team); |
| } |
| |
| return r; |
| } |
| |
| void DoGetValues(const Values **result) { |
| uint16_t team = ::aos::network::GetTeamNumber(); |
| AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team); |
| *result = DoGetValuesForTeam(team); |
| } |
| |
| } // namespace |
| |
| const Values &GetValues() { |
| static absl::once_flag once; |
| static const Values *result; |
| absl::call_once(once, DoGetValues, &result); |
| return *result; |
| } |
| |
| const Values &GetValuesForTeam(uint16_t team_number) { |
| static ::aos::Mutex mutex; |
| ::aos::MutexLocker locker(&mutex); |
| |
| // IMPORTANT: This declaration has to stay after the mutex is locked to avoid |
| // race conditions. |
| static ::std::map<uint16_t, const Values *> values; |
| |
| if (values.count(team_number) == 0) { |
| values[team_number] = DoGetValuesForTeam(team_number); |
| #if __has_feature(address_sanitizer) |
| __lsan_ignore_object(values[team_number]); |
| #endif |
| } |
| return *values[team_number]; |
| } |
| |
| } // namespace constants |
| } // namespace y2020 |