blob: bd2f078778917e5a592daeac5e2f52b59024fd17 [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"
8
9namespace frc971 {
10namespace constants {
11
12namespace {
13
14const double kCompHorizontal = -1.77635 + 0.180;
15const double kPracticeHorizontal = -1.77635 + -0.073631;
16const int kCompCameraCenter = -2;
17const int kPracticeCameraCenter = -5;
18
19struct Values {
20 // what horizontal_offset returns
21 double horizontal;
22 // what camera_center returns
23 int camera_center;
brians343bc112013-02-10 01:53:46 +000024};
25Values *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.
29const 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:
brians9df62802013-02-27 03:44:32 +000035 values = new Values{kCompHorizontal, kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +000036 break;
37 case kPracticeTeamNumber:
brians9df62802013-02-27 03:44:32 +000038 values = new Values{kPracticeHorizontal, kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +000039 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
51bool horizontal_offset(double *horizontal) {
52 const Values *const values = GetValues();
53 if (values == NULL) return false;
54 *horizontal = values->horizontal;
55 return true;
56}
57bool 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}
brians343bc112013-02-10 01:53:46 +000063
64} // namespace constants
65} // namespace frc971