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 | |
| 14 | const double kCompHorizontal = -1.77635 + 0.180; |
| 15 | const double kPracticeHorizontal = -1.77635 + -0.073631; |
| 16 | const int kCompCameraCenter = -2; |
| 17 | const int kPracticeCameraCenter = -5; |
| 18 | |
| 19 | struct Values { |
| 20 | // what horizontal_offset returns |
| 21 | double horizontal; |
| 22 | // what camera_center returns |
| 23 | int camera_center; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 24 | }; |
| 25 | Values *values = NULL; |
| 26 | // Attempts to retrieve a new Values instance and stores it in values if |
| 27 | // necessary. |
| 28 | // Returns a valid Values instance or NULL. |
| 29 | const Values *GetValues() { |
| 30 | if (values == NULL) { |
| 31 | LOG(INFO, "creating a Constants for team %"PRIu16"\n", |
| 32 | aos::robot_state->team_id); |
| 33 | switch (aos::robot_state->team_id) { |
| 34 | case kCompTeamNumber: |
brians | 9df6280 | 2013-02-27 03:44:32 +0000 | [diff] [blame] | 35 | values = new Values{kCompHorizontal, kCompCameraCenter}; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 36 | break; |
| 37 | case kPracticeTeamNumber: |
brians | 9df6280 | 2013-02-27 03:44:32 +0000 | [diff] [blame] | 38 | values = new Values{kPracticeHorizontal, kPracticeCameraCenter}; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 39 | break; |
| 40 | default: |
| 41 | LOG(ERROR, "unknown team #%"PRIu16"\n", |
| 42 | aos::robot_state->team_id); |
| 43 | return NULL; |
| 44 | } |
| 45 | } |
| 46 | return values; |
| 47 | } |
| 48 | |
| 49 | } // namespace |
| 50 | |
| 51 | bool horizontal_offset(double *horizontal) { |
| 52 | const Values *const values = GetValues(); |
| 53 | if (values == NULL) return false; |
| 54 | *horizontal = values->horizontal; |
| 55 | return true; |
| 56 | } |
| 57 | bool camera_center(int *center) { |
| 58 | const Values *const values = GetValues(); |
| 59 | if (values == NULL) return false; |
| 60 | *center = values->camera_center; |
| 61 | return true; |
| 62 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 63 | |
| 64 | } // namespace constants |
| 65 | } // namespace frc971 |