blob: 6c16097d98495ad31cfae3ba5292239fe2046c53 [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;
24 // what drivetrain_motor_controllers returns
25 char drivetrain_controllers;
26};
27Values *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.
31const 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
55bool horizontal_offset(double *horizontal) {
56 const Values *const values = GetValues();
57 if (values == NULL) return false;
58 *horizontal = values->horizontal;
59 return true;
60}
61bool 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}
67bool 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