brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #include "frc971/constants.h" |
| 2 | |
| 3 | #include <stddef.h> |
| 4 | #include <inttypes.h> |
| 5 | |
| 6 | #include "aos/common/messages/RobotState.q.h" |
| 7 | #include "aos/atom_code/output/MotorOutput.h" |
| 8 | |
| 9 | namespace frc971 { |
| 10 | namespace constants { |
| 11 | |
| 12 | namespace { |
| 13 | |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 14 | constexpr double kCompHorizontalHallEffectStartAngle = 72 * M_PI / 180.0; |
| 15 | constexpr double kPracticeHorizontalHallEffectStartAngle = 72 * M_PI / 180.0; |
| 16 | |
| 17 | constexpr double kCompHorizontalHallEffectStopAngle = 100 * M_PI / 180.0; |
| 18 | constexpr double kPracticeHorizontalHallEffectStopAngle = 100 * M_PI / 180.0; |
| 19 | |
| 20 | constexpr double kPracticeHorizontalUpperPhysicalLimit = 95 * M_PI / 180.0; |
| 21 | constexpr double kCompHorizontalUpperPhysicalLimit = 95 * M_PI / 180.0; |
| 22 | |
| 23 | constexpr double kPracticeHorizontalLowerPhysicalLimit = -37.5 * M_PI / 180.0; |
| 24 | constexpr double kCompHorizontalLowerPhysicalLimit = -37.5 * M_PI / 180.0; |
| 25 | |
| 26 | constexpr double kPracticeHorizontalUpperLimit = 93 * M_PI / 180.0; |
| 27 | constexpr double kCompHorizontalUpperLimit = 93 * M_PI / 180.0; |
| 28 | |
| 29 | constexpr double kPracticeHorizontalLowerLimit = -36 * M_PI / 180.0; |
| 30 | constexpr double kCompHorizontalLowerLimit = -36 * M_PI / 180.0; |
| 31 | |
| 32 | constexpr double kHorizontalZeroingSpeed = 1.0; |
| 33 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 34 | const int kCompCameraCenter = -2; |
| 35 | const int kPracticeCameraCenter = -5; |
| 36 | |
| 37 | struct Values { |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 38 | // Wrist hall effect positive and negative edges. |
| 39 | double horizontal_hall_effect_start_angle; |
| 40 | double horizontal_hall_effect_stop_angle; |
| 41 | |
| 42 | // Upper and lower extreme limits of travel for the wrist. |
| 43 | double horizontal_upper_limit; |
| 44 | double horizontal_lower_limit; |
| 45 | // Physical limits. These are here for testing. |
| 46 | double horizontal_upper_physical_limit; |
| 47 | double horizontal_lower_physical_limit; |
| 48 | |
| 49 | // Zeroing speed. |
| 50 | double horizontal_zeroing_speed; |
| 51 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 52 | // what camera_center returns |
| 53 | int camera_center; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 54 | }; |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 55 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 56 | Values *values = NULL; |
| 57 | // Attempts to retrieve a new Values instance and stores it in values if |
| 58 | // necessary. |
| 59 | // Returns a valid Values instance or NULL. |
| 60 | const Values *GetValues() { |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 61 | // TODO(brians): Make this use the new Once construct. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 62 | if (values == NULL) { |
| 63 | LOG(INFO, "creating a Constants for team %"PRIu16"\n", |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 64 | ::aos::robot_state->team_id); |
| 65 | switch (::aos::robot_state->team_id) { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 66 | case kCompTeamNumber: |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 67 | values = new Values{kCompHorizontalHallEffectStartAngle, |
| 68 | kCompHorizontalHallEffectStopAngle, |
| 69 | kCompHorizontalUpperLimit, |
| 70 | kCompHorizontalLowerLimit, |
| 71 | kCompHorizontalUpperPhysicalLimit, |
| 72 | kCompHorizontalLowerPhysicalLimit, |
| 73 | kHorizontalZeroingSpeed, |
| 74 | kCompCameraCenter}; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 75 | break; |
| 76 | case kPracticeTeamNumber: |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 77 | values = new Values{kPracticeHorizontalHallEffectStartAngle, |
| 78 | kPracticeHorizontalHallEffectStopAngle, |
| 79 | kPracticeHorizontalUpperLimit, |
| 80 | kPracticeHorizontalLowerLimit, |
| 81 | kPracticeHorizontalUpperPhysicalLimit, |
| 82 | kPracticeHorizontalLowerPhysicalLimit, |
| 83 | kHorizontalZeroingSpeed, |
| 84 | kPracticeCameraCenter}; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 85 | break; |
| 86 | default: |
| 87 | LOG(ERROR, "unknown team #%"PRIu16"\n", |
| 88 | aos::robot_state->team_id); |
| 89 | return NULL; |
| 90 | } |
| 91 | } |
| 92 | return values; |
| 93 | } |
| 94 | |
| 95 | } // namespace |
| 96 | |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 97 | bool horizontal_hall_effect_start_angle(double *angle) { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 98 | const Values *const values = GetValues(); |
| 99 | if (values == NULL) return false; |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 100 | *angle = values->horizontal_hall_effect_start_angle; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 101 | return true; |
| 102 | } |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 103 | bool horizontal_hall_effect_stop_angle(double *angle) { |
| 104 | const Values *const values = GetValues(); |
| 105 | if (values == NULL) return false; |
| 106 | *angle = values->horizontal_hall_effect_stop_angle; |
| 107 | return true; |
| 108 | } |
| 109 | bool horizontal_upper_limit(double *angle) { |
| 110 | const Values *const values = GetValues(); |
| 111 | if (values == NULL) return false; |
| 112 | *angle = values->horizontal_upper_limit; |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | bool horizontal_lower_limit(double *angle) { |
| 117 | const Values *const values = GetValues(); |
| 118 | if (values == NULL) return false; |
| 119 | *angle = values->horizontal_lower_limit; |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | bool horizontal_upper_physical_limit(double *angle) { |
| 124 | const Values *const values = GetValues(); |
| 125 | if (values == NULL) return false; |
| 126 | *angle = values->horizontal_upper_physical_limit; |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | bool horizontal_lower_physical_limit(double *angle) { |
| 131 | const Values *const values = GetValues(); |
| 132 | if (values == NULL) return false; |
| 133 | *angle = values->horizontal_lower_physical_limit; |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | bool horizontal_zeroing_speed(double *speed) { |
| 138 | const Values *const values = GetValues(); |
| 139 | if (values == NULL) return false; |
| 140 | *speed = values->horizontal_zeroing_speed; |
| 141 | return true; |
| 142 | } |
| 143 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 144 | bool camera_center(int *center) { |
| 145 | const Values *const values = GetValues(); |
| 146 | if (values == NULL) return false; |
| 147 | *center = values->camera_center; |
| 148 | return true; |
| 149 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 150 | |
| 151 | } // namespace constants |
| 152 | } // namespace frc971 |