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; |
| 24 | // what drivetrain_motor_controllers returns |
| 25 | char drivetrain_controllers; |
| 26 | }; |
| 27 | Values *values = NULL; |
| 28 | // Attempts to retrieve a new Values instance and stores it in values if |
| 29 | // necessary. |
| 30 | // Returns a valid Values instance or NULL. |
| 31 | const Values *GetValues() { |
| 32 | if (values == NULL) { |
| 33 | LOG(INFO, "creating a Constants for team %"PRIu16"\n", |
| 34 | aos::robot_state->team_id); |
| 35 | switch (aos::robot_state->team_id) { |
| 36 | case kCompTeamNumber: |
| 37 | values = new Values{kCompHorizontal, kCompCameraCenter, |
| 38 | aos::MotorOutput::TALON}; |
| 39 | break; |
| 40 | case kPracticeTeamNumber: |
| 41 | values = new Values{kPracticeHorizontal, kPracticeCameraCenter, |
| 42 | aos::MotorOutput::VICTOR}; |
| 43 | break; |
| 44 | default: |
| 45 | LOG(ERROR, "unknown team #%"PRIu16"\n", |
| 46 | aos::robot_state->team_id); |
| 47 | return NULL; |
| 48 | } |
| 49 | } |
| 50 | return values; |
| 51 | } |
| 52 | |
| 53 | } // namespace |
| 54 | |
| 55 | bool horizontal_offset(double *horizontal) { |
| 56 | const Values *const values = GetValues(); |
| 57 | if (values == NULL) return false; |
| 58 | *horizontal = values->horizontal; |
| 59 | return true; |
| 60 | } |
| 61 | bool camera_center(int *center) { |
| 62 | const Values *const values = GetValues(); |
| 63 | if (values == NULL) return false; |
| 64 | *center = values->camera_center; |
| 65 | return true; |
| 66 | } |
| 67 | bool drivetrain_motor_controllers(char *controllers) { |
| 68 | const Values *const values = GetValues(); |
| 69 | if (values == NULL) return false; |
| 70 | *controllers = values->drivetrain_controllers; |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | } // namespace constants |
| 75 | } // namespace frc971 |