blob: 5048007562ee72990dbf050ccf0af42d0b00055d [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
Austin Schuhfa033692013-02-24 01:00:55 -080014constexpr double kCompHorizontalHallEffectStartAngle = 72 * M_PI / 180.0;
15constexpr double kPracticeHorizontalHallEffectStartAngle = 72 * M_PI / 180.0;
16
17constexpr double kCompHorizontalHallEffectStopAngle = 100 * M_PI / 180.0;
18constexpr double kPracticeHorizontalHallEffectStopAngle = 100 * M_PI / 180.0;
19
20constexpr double kPracticeHorizontalUpperPhysicalLimit = 95 * M_PI / 180.0;
21constexpr double kCompHorizontalUpperPhysicalLimit = 95 * M_PI / 180.0;
22
23constexpr double kPracticeHorizontalLowerPhysicalLimit = -37.5 * M_PI / 180.0;
24constexpr double kCompHorizontalLowerPhysicalLimit = -37.5 * M_PI / 180.0;
25
26constexpr double kPracticeHorizontalUpperLimit = 93 * M_PI / 180.0;
27constexpr double kCompHorizontalUpperLimit = 93 * M_PI / 180.0;
28
29constexpr double kPracticeHorizontalLowerLimit = -36 * M_PI / 180.0;
30constexpr double kCompHorizontalLowerLimit = -36 * M_PI / 180.0;
31
32constexpr double kHorizontalZeroingSpeed = 1.0;
33
brians343bc112013-02-10 01:53:46 +000034const int kCompCameraCenter = -2;
35const int kPracticeCameraCenter = -5;
36
37struct Values {
Austin Schuhfa033692013-02-24 01:00:55 -080038 // Wrist hall effect positive and negative edges.
39 double horizontal_hall_effect_start_angle;
40 double horizontal_hall_effect_stop_angle;
41
42 // Upper and lower extreme limits of travel for the wrist.
43 double horizontal_upper_limit;
44 double horizontal_lower_limit;
45 // Physical limits. These are here for testing.
46 double horizontal_upper_physical_limit;
47 double horizontal_lower_physical_limit;
48
49 // Zeroing speed.
50 double horizontal_zeroing_speed;
51
brians343bc112013-02-10 01:53:46 +000052 // what camera_center returns
53 int camera_center;
brians343bc112013-02-10 01:53:46 +000054};
Austin Schuhfa033692013-02-24 01:00:55 -080055
brians343bc112013-02-10 01:53:46 +000056Values *values = NULL;
57// Attempts to retrieve a new Values instance and stores it in values if
58// necessary.
59// Returns a valid Values instance or NULL.
60const Values *GetValues() {
Austin Schuhfa033692013-02-24 01:00:55 -080061 // TODO(brians): Make this use the new Once construct.
brians343bc112013-02-10 01:53:46 +000062 if (values == NULL) {
63 LOG(INFO, "creating a Constants for team %"PRIu16"\n",
Austin Schuhfa033692013-02-24 01:00:55 -080064 ::aos::robot_state->team_id);
65 switch (::aos::robot_state->team_id) {
brians343bc112013-02-10 01:53:46 +000066 case kCompTeamNumber:
Austin Schuhfa033692013-02-24 01:00:55 -080067 values = new Values{kCompHorizontalHallEffectStartAngle,
68 kCompHorizontalHallEffectStopAngle,
69 kCompHorizontalUpperLimit,
70 kCompHorizontalLowerLimit,
71 kCompHorizontalUpperPhysicalLimit,
72 kCompHorizontalLowerPhysicalLimit,
73 kHorizontalZeroingSpeed,
74 kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +000075 break;
76 case kPracticeTeamNumber:
Austin Schuhfa033692013-02-24 01:00:55 -080077 values = new Values{kPracticeHorizontalHallEffectStartAngle,
78 kPracticeHorizontalHallEffectStopAngle,
79 kPracticeHorizontalUpperLimit,
80 kPracticeHorizontalLowerLimit,
81 kPracticeHorizontalUpperPhysicalLimit,
82 kPracticeHorizontalLowerPhysicalLimit,
83 kHorizontalZeroingSpeed,
84 kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +000085 break;
86 default:
87 LOG(ERROR, "unknown team #%"PRIu16"\n",
88 aos::robot_state->team_id);
89 return NULL;
90 }
91 }
92 return values;
93}
94
95} // namespace
96
Austin Schuhfa033692013-02-24 01:00:55 -080097bool horizontal_hall_effect_start_angle(double *angle) {
brians343bc112013-02-10 01:53:46 +000098 const Values *const values = GetValues();
99 if (values == NULL) return false;
Austin Schuhfa033692013-02-24 01:00:55 -0800100 *angle = values->horizontal_hall_effect_start_angle;
brians343bc112013-02-10 01:53:46 +0000101 return true;
102}
Austin Schuhfa033692013-02-24 01:00:55 -0800103bool horizontal_hall_effect_stop_angle(double *angle) {
104 const Values *const values = GetValues();
105 if (values == NULL) return false;
106 *angle = values->horizontal_hall_effect_stop_angle;
107 return true;
108}
109bool horizontal_upper_limit(double *angle) {
110 const Values *const values = GetValues();
111 if (values == NULL) return false;
112 *angle = values->horizontal_upper_limit;
113 return true;
114}
115
116bool horizontal_lower_limit(double *angle) {
117 const Values *const values = GetValues();
118 if (values == NULL) return false;
119 *angle = values->horizontal_lower_limit;
120 return true;
121}
122
123bool horizontal_upper_physical_limit(double *angle) {
124 const Values *const values = GetValues();
125 if (values == NULL) return false;
126 *angle = values->horizontal_upper_physical_limit;
127 return true;
128}
129
130bool horizontal_lower_physical_limit(double *angle) {
131 const Values *const values = GetValues();
132 if (values == NULL) return false;
133 *angle = values->horizontal_lower_physical_limit;
134 return true;
135}
136
137bool horizontal_zeroing_speed(double *speed) {
138 const Values *const values = GetValues();
139 if (values == NULL) return false;
140 *speed = values->horizontal_zeroing_speed;
141 return true;
142}
143
brians343bc112013-02-10 01:53:46 +0000144bool camera_center(int *center) {
145 const Values *const values = GetValues();
146 if (values == NULL) return false;
147 *center = values->camera_center;
148 return true;
149}
brians343bc112013-02-10 01:53:46 +0000150
151} // namespace constants
152} // namespace frc971