blob: 6c7c54bf1d4ec1adcc5d0f8450a005ce42aa8fb0 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include "frc971/constants.h"
2
3#include <stddef.h>
Austin Schuh464ee1a2013-03-01 22:37:39 -08004#include <math.h>
James Kuszmaul4a4622b2013-03-02 16:28:29 -08005#include <array>
brians343bc112013-02-10 01:53:46 +00006
Brian Silverman20fdbef2013-03-09 13:42:03 -08007#include "aos/common/inttypes.h"
brians343bc112013-02-10 01:53:46 +00008#include "aos/common/messages/RobotState.q.h"
9#include "aos/atom_code/output/MotorOutput.h"
10
Brian Silverman20fdbef2013-03-09 13:42:03 -080011#ifndef M_PI
12#define M_PI 3.14159265358979323846
13#endif
14
James Kuszmaul4a4622b2013-03-02 16:28:29 -080015// Note: So far, none of the Angle Adjust numbers have been measured.
16// Do not rely on them for real life.
17
brians343bc112013-02-10 01:53:46 +000018namespace frc971 {
19namespace constants {
20
21namespace {
22
James Kuszmaule06e2512013-03-02 15:04:53 -080023const double kCompWristHallEffectStartAngle = 72 * M_PI / 180.0;
24const double kPracticeWristHallEffectStartAngle = 72 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080025
James Kuszmaule06e2512013-03-02 15:04:53 -080026const double kCompWristHallEffectStopAngle = 100 * M_PI / 180.0;
27const double kPracticeWristHallEffectStopAngle = 100 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080028
James Kuszmaule06e2512013-03-02 15:04:53 -080029const double kPracticeWristUpperPhysicalLimit = 95 * M_PI / 180.0;
30const double kCompWristUpperPhysicalLimit = 95 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080031
James Kuszmaule06e2512013-03-02 15:04:53 -080032const double kPracticeWristLowerPhysicalLimit = -37.5 * M_PI / 180.0;
33const double kCompWristLowerPhysicalLimit = -37.5 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080034
James Kuszmaul4a4622b2013-03-02 16:28:29 -080035const int kAngleAdjustHallEffect = 2;
36
37const ::std::array<double, kAngleAdjustHallEffect>
38 kCompAngleAdjustHorizontalHallEffectStartAngle = {{-0.1, 1.0}};
39const ::std::array<double, kAngleAdjustHallEffect>
40 kPracticeAngleAdjustHorizontalHallEffectStartAngle = {{-0.1, 1.0}};
41
42const ::std::array<double, kAngleAdjustHallEffect>
43 kCompAngleAdjustHorizontalHallEffectStopAngle = {{0.5, 1.5}};
44const ::std::array<double, kAngleAdjustHallEffect>
45 kPracticeAngleAdjustHorizontalHallEffectStopAngle = {{0.5, 1.5}};
46
47const double kPracticeAngleAdjustHorizontalUpperPhysicalLimit =
48 3.0;
49const double kCompAngleAdjustHorizontalUpperPhysicalLimit =
50 3.0;
51
James Kuszmaule06e2512013-03-02 15:04:53 -080052const double kPracticeWristUpperLimit = 93 * M_PI / 180.0;
53const double kCompWristUpperLimit = 93 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080054
James Kuszmaule06e2512013-03-02 15:04:53 -080055const double kPracticeWristLowerLimit = -36 * M_PI / 180.0;
56const double kCompWristLowerLimit = -36 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080057
James Kuszmaule06e2512013-03-02 15:04:53 -080058const double kWristZeroingSpeed = 1.0;
Austin Schuhfa033692013-02-24 01:00:55 -080059
James Kuszmaul4a4622b2013-03-02 16:28:29 -080060const double kPracticeAngleAdjustHorizontalLowerPhysicalLimit =
61 0.0;
62const double kCompAngleAdjustHorizontalLowerPhysicalLimit =
63 0.0;
64
65const double kPracticeAngleAdjustHorizontalUpperLimit =
66 3.0;
67const double kCompAngleAdjustHorizontalUpperLimit =
68 3.0;
69
70const double kPracticeAngleAdjustHorizontalLowerLimit =
71 0.0;
72const double kCompAngleAdjustHorizontalLowerLimit =
73 0.0;
74
75const double kAngleAdjustHorizontalZeroingSpeed = 1.0;
76
brians343bc112013-02-10 01:53:46 +000077const int kCompCameraCenter = -2;
78const int kPracticeCameraCenter = -5;
79
80struct Values {
Austin Schuhfa033692013-02-24 01:00:55 -080081 // Wrist hall effect positive and negative edges.
James Kuszmaule06e2512013-03-02 15:04:53 -080082 double wrist_hall_effect_start_angle;
83 double wrist_hall_effect_stop_angle;
Austin Schuhfa033692013-02-24 01:00:55 -080084
85 // Upper and lower extreme limits of travel for the wrist.
James Kuszmaule06e2512013-03-02 15:04:53 -080086 double wrist_upper_limit;
87 double wrist_lower_limit;
88
Austin Schuhfa033692013-02-24 01:00:55 -080089 // Physical limits. These are here for testing.
James Kuszmaule06e2512013-03-02 15:04:53 -080090 double wrist_upper_physical_limit;
91 double wrist_lower_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -080092
93 // Zeroing speed.
James Kuszmaule06e2512013-03-02 15:04:53 -080094 double wrist_zeroing_speed;
Austin Schuhfa033692013-02-24 01:00:55 -080095
James Kuszmaul4a4622b2013-03-02 16:28:29 -080096 // AngleAdjust hall effect positive and negative edges.
97 ::std::array<double, 2> angle_adjust_horizontal_hall_effect_start_angle;
98 ::std::array<double, 2> angle_adjust_horizontal_hall_effect_stop_angle;
99
100 // Upper and lower extreme limits of travel for the angle adjust.
101 double angle_adjust_horizontal_upper_limit;
102 double angle_adjust_horizontal_lower_limit;
103 // Physical limits. These are here for testing.
104 double angle_adjust_horizontal_upper_physical_limit;
105 double angle_adjust_horizontal_lower_physical_limit;
106
107 // Zeroing speed.
108 double angle_adjust_horizontal_zeroing_speed;
109
brians343bc112013-02-10 01:53:46 +0000110 // what camera_center returns
111 int camera_center;
brians343bc112013-02-10 01:53:46 +0000112};
Austin Schuhfa033692013-02-24 01:00:55 -0800113
brians343bc112013-02-10 01:53:46 +0000114Values *values = NULL;
115// Attempts to retrieve a new Values instance and stores it in values if
116// necessary.
117// Returns a valid Values instance or NULL.
118const Values *GetValues() {
Austin Schuhfa033692013-02-24 01:00:55 -0800119 // TODO(brians): Make this use the new Once construct.
brians343bc112013-02-10 01:53:46 +0000120 if (values == NULL) {
121 LOG(INFO, "creating a Constants for team %"PRIu16"\n",
Austin Schuhfa033692013-02-24 01:00:55 -0800122 ::aos::robot_state->team_id);
123 switch (::aos::robot_state->team_id) {
brians343bc112013-02-10 01:53:46 +0000124 case kCompTeamNumber:
James Kuszmaule06e2512013-03-02 15:04:53 -0800125 values = new Values{kCompWristHallEffectStartAngle,
126 kCompWristHallEffectStopAngle,
127 kCompWristUpperLimit,
128 kCompWristLowerLimit,
129 kCompWristUpperPhysicalLimit,
130 kCompWristLowerPhysicalLimit,
131 kWristZeroingSpeed,
James Kuszmaul4a4622b2013-03-02 16:28:29 -0800132 kCompAngleAdjustHorizontalHallEffectStartAngle,
133 kCompAngleAdjustHorizontalHallEffectStopAngle,
134 kCompAngleAdjustHorizontalUpperLimit,
135 kCompAngleAdjustHorizontalLowerLimit,
136 kCompAngleAdjustHorizontalUpperPhysicalLimit,
137 kCompAngleAdjustHorizontalLowerPhysicalLimit,
138 kAngleAdjustHorizontalZeroingSpeed,
Austin Schuhfa033692013-02-24 01:00:55 -0800139 kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +0000140 break;
141 case kPracticeTeamNumber:
James Kuszmaule06e2512013-03-02 15:04:53 -0800142 values = new Values{kPracticeWristHallEffectStartAngle,
143 kPracticeWristHallEffectStopAngle,
144 kPracticeWristUpperLimit,
145 kPracticeWristLowerLimit,
146 kPracticeWristUpperPhysicalLimit,
147 kPracticeWristLowerPhysicalLimit,
148 kWristZeroingSpeed,
James Kuszmaul4a4622b2013-03-02 16:28:29 -0800149 kPracticeAngleAdjustHorizontalHallEffectStartAngle,
150 kPracticeAngleAdjustHorizontalHallEffectStopAngle,
151 kPracticeAngleAdjustHorizontalUpperLimit,
152 kPracticeAngleAdjustHorizontalLowerLimit,
153 kPracticeAngleAdjustHorizontalUpperPhysicalLimit,
154 kPracticeAngleAdjustHorizontalLowerPhysicalLimit,
155 kAngleAdjustHorizontalZeroingSpeed,
Austin Schuhfa033692013-02-24 01:00:55 -0800156 kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +0000157 break;
158 default:
159 LOG(ERROR, "unknown team #%"PRIu16"\n",
160 aos::robot_state->team_id);
161 return NULL;
162 }
163 }
164 return values;
165}
166
167} // namespace
168
James Kuszmaule06e2512013-03-02 15:04:53 -0800169bool wrist_hall_effect_start_angle(double *angle) {
brians343bc112013-02-10 01:53:46 +0000170 const Values *const values = GetValues();
171 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800172 *angle = values->wrist_hall_effect_start_angle;
brians343bc112013-02-10 01:53:46 +0000173 return true;
174}
James Kuszmaule06e2512013-03-02 15:04:53 -0800175bool wrist_hall_effect_stop_angle(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800176 const Values *const values = GetValues();
177 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800178 *angle = values->wrist_hall_effect_stop_angle;
Austin Schuhfa033692013-02-24 01:00:55 -0800179 return true;
180}
James Kuszmaule06e2512013-03-02 15:04:53 -0800181bool wrist_upper_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800182 const Values *const values = GetValues();
183 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800184 *angle = values->wrist_upper_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800185 return true;
186}
187
James Kuszmaule06e2512013-03-02 15:04:53 -0800188bool wrist_lower_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800189 const Values *const values = GetValues();
190 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800191 *angle = values->wrist_lower_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800192 return true;
193}
194
James Kuszmaule06e2512013-03-02 15:04:53 -0800195bool wrist_upper_physical_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800196 const Values *const values = GetValues();
197 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800198 *angle = values->wrist_upper_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800199 return true;
200}
201
James Kuszmaule06e2512013-03-02 15:04:53 -0800202bool wrist_lower_physical_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800203 const Values *const values = GetValues();
204 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800205 *angle = values->wrist_lower_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800206 return true;
207}
208
James Kuszmaule06e2512013-03-02 15:04:53 -0800209bool wrist_zeroing_speed(double *speed) {
Austin Schuhfa033692013-02-24 01:00:55 -0800210 const Values *const values = GetValues();
211 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800212 *speed = values->wrist_zeroing_speed;
Austin Schuhfa033692013-02-24 01:00:55 -0800213 return true;
214}
215
James Kuszmaul4a4622b2013-03-02 16:28:29 -0800216bool angle_adjust_horizontal_hall_effect_start_angle(
217 ::std::array<double, 2> *angle) {
218 const Values *const values = GetValues();
219 if (values == NULL) return false;
220 *angle = values->angle_adjust_horizontal_hall_effect_start_angle;
221 return true;
222}
223bool angle_adjust_horizontal_hall_effect_stop_angle(
224 ::std::array<double, 2> *angle) {
225 const Values *const values = GetValues();
226 if (values == NULL) return false;
227 *angle = values->angle_adjust_horizontal_hall_effect_stop_angle;
228 return true;
229}
230bool angle_adjust_horizontal_upper_limit(double *angle) {
231 const Values *const values = GetValues();
232 if (values == NULL) return false;
233 *angle = values->angle_adjust_horizontal_upper_limit;
234 return true;
235}
236
237bool angle_adjust_horizontal_lower_limit(double *angle) {
238 const Values *const values = GetValues();
239 if (values == NULL) return false;
240 *angle = values->angle_adjust_horizontal_lower_limit;
241 return true;
242}
243
244bool angle_adjust_horizontal_upper_physical_limit(double *angle) {
245 const Values *const values = GetValues();
246 if (values == NULL) return false;
247 *angle = values->angle_adjust_horizontal_upper_physical_limit;
248 return true;
249}
250
251bool angle_adjust_horizontal_lower_physical_limit(double *angle) {
252 const Values *const values = GetValues();
253 if (values == NULL) return false;
254 *angle = values->angle_adjust_horizontal_lower_physical_limit;
255 return true;
256}
257
258bool angle_adjust_horizontal_zeroing_speed(double *speed) {
259 const Values *const values = GetValues();
260 if (values == NULL) return false;
261 *speed = values->angle_adjust_horizontal_zeroing_speed;
262 return true;
263}
264
brians343bc112013-02-10 01:53:46 +0000265bool camera_center(int *center) {
266 const Values *const values = GetValues();
267 if (values == NULL) return false;
268 *center = values->camera_center;
269 return true;
270}
brians343bc112013-02-10 01:53:46 +0000271
272} // namespace constants
273} // namespace frc971