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