blob: f122ee330ac6b8a177f3bfb024e4c910dcee0c81 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#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 Silverman3204dd82013-03-12 18:42:01 -07008#include "aos/common/logging/logging.h"
brians343bc112013-02-10 01:53:46 +00009
10namespace frc971 {
11namespace constants {
12
13namespace {
14
15const double kCompHorizontal = -1.77635 + 0.180;
16const double kPracticeHorizontal = -1.77635 + -0.073631;
17const int kCompCameraCenter = -2;
18const int kPracticeCameraCenter = -5;
19
20struct Values {
21 // what horizontal_offset returns
22 double horizontal;
23 // what camera_center returns
24 int camera_center;
brians343bc112013-02-10 01:53:46 +000025};
26Values *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.
30const 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:
brians9df62802013-02-27 03:44:32 +000036 values = new Values{kCompHorizontal, kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +000037 break;
38 case kPracticeTeamNumber:
brians9df62802013-02-27 03:44:32 +000039 values = new Values{kPracticeHorizontal, kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +000040 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
52bool horizontal_offset(double *horizontal) {
53 const Values *const values = GetValues();
54 if (values == NULL) return false;
55 *horizontal = values->horizontal;
56 return true;
57}
58bool 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}
brians343bc112013-02-10 01:53:46 +000064
65} // namespace constants
66} // namespace frc971