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