blob: 796ff62c9da8bb95cc06b11804ed976f6e9f368b [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include "frc971/constants.h"
2
3#include <stddef.h>
4#include <inttypes.h>
Austin Schuh464ee1a2013-03-01 22:37:39 -08005#include <math.h>
brians343bc112013-02-10 01:53:46 +00006
7#include "aos/common/messages/RobotState.q.h"
8#include "aos/atom_code/output/MotorOutput.h"
9
10namespace frc971 {
11namespace constants {
12
13namespace {
14
Austin Schuh464ee1a2013-03-01 22:37:39 -080015const double kCompHorizontalHallEffectStartAngle = 72 * M_PI / 180.0;
16const double kPracticeHorizontalHallEffectStartAngle = 72 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080017
Austin Schuh464ee1a2013-03-01 22:37:39 -080018const double kCompHorizontalHallEffectStopAngle = 100 * M_PI / 180.0;
19const double kPracticeHorizontalHallEffectStopAngle = 100 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080020
Austin Schuh464ee1a2013-03-01 22:37:39 -080021const double kPracticeHorizontalUpperPhysicalLimit = 95 * M_PI / 180.0;
22const double kCompHorizontalUpperPhysicalLimit = 95 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080023
Austin Schuh464ee1a2013-03-01 22:37:39 -080024const double kPracticeHorizontalLowerPhysicalLimit = -37.5 * M_PI / 180.0;
25const double kCompHorizontalLowerPhysicalLimit = -37.5 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080026
Austin Schuh464ee1a2013-03-01 22:37:39 -080027const double kPracticeHorizontalUpperLimit = 93 * M_PI / 180.0;
28const double kCompHorizontalUpperLimit = 93 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080029
Austin Schuh464ee1a2013-03-01 22:37:39 -080030const double kPracticeHorizontalLowerLimit = -36 * M_PI / 180.0;
31const double kCompHorizontalLowerLimit = -36 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080032
Austin Schuh464ee1a2013-03-01 22:37:39 -080033const double kHorizontalZeroingSpeed = 1.0;
Austin Schuhfa033692013-02-24 01:00:55 -080034
brians343bc112013-02-10 01:53:46 +000035const int kCompCameraCenter = -2;
36const int kPracticeCameraCenter = -5;
37
38struct Values {
Austin Schuhfa033692013-02-24 01:00:55 -080039 // Wrist hall effect positive and negative edges.
40 double horizontal_hall_effect_start_angle;
41 double horizontal_hall_effect_stop_angle;
42
43 // Upper and lower extreme limits of travel for the wrist.
44 double horizontal_upper_limit;
45 double horizontal_lower_limit;
46 // Physical limits. These are here for testing.
47 double horizontal_upper_physical_limit;
48 double horizontal_lower_physical_limit;
49
50 // Zeroing speed.
51 double horizontal_zeroing_speed;
52
brians343bc112013-02-10 01:53:46 +000053 // what camera_center returns
54 int camera_center;
brians343bc112013-02-10 01:53:46 +000055};
Austin Schuhfa033692013-02-24 01:00:55 -080056
brians343bc112013-02-10 01:53:46 +000057Values *values = NULL;
58// Attempts to retrieve a new Values instance and stores it in values if
59// necessary.
60// Returns a valid Values instance or NULL.
61const Values *GetValues() {
Austin Schuhfa033692013-02-24 01:00:55 -080062 // TODO(brians): Make this use the new Once construct.
brians343bc112013-02-10 01:53:46 +000063 if (values == NULL) {
64 LOG(INFO, "creating a Constants for team %"PRIu16"\n",
Austin Schuhfa033692013-02-24 01:00:55 -080065 ::aos::robot_state->team_id);
66 switch (::aos::robot_state->team_id) {
brians343bc112013-02-10 01:53:46 +000067 case kCompTeamNumber:
Austin Schuhfa033692013-02-24 01:00:55 -080068 values = new Values{kCompHorizontalHallEffectStartAngle,
69 kCompHorizontalHallEffectStopAngle,
70 kCompHorizontalUpperLimit,
71 kCompHorizontalLowerLimit,
72 kCompHorizontalUpperPhysicalLimit,
73 kCompHorizontalLowerPhysicalLimit,
74 kHorizontalZeroingSpeed,
75 kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +000076 break;
77 case kPracticeTeamNumber:
Austin Schuhfa033692013-02-24 01:00:55 -080078 values = new Values{kPracticeHorizontalHallEffectStartAngle,
79 kPracticeHorizontalHallEffectStopAngle,
80 kPracticeHorizontalUpperLimit,
81 kPracticeHorizontalLowerLimit,
82 kPracticeHorizontalUpperPhysicalLimit,
83 kPracticeHorizontalLowerPhysicalLimit,
84 kHorizontalZeroingSpeed,
85 kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +000086 break;
87 default:
88 LOG(ERROR, "unknown team #%"PRIu16"\n",
89 aos::robot_state->team_id);
90 return NULL;
91 }
92 }
93 return values;
94}
95
96} // namespace
97
Austin Schuhfa033692013-02-24 01:00:55 -080098bool horizontal_hall_effect_start_angle(double *angle) {
brians343bc112013-02-10 01:53:46 +000099 const Values *const values = GetValues();
100 if (values == NULL) return false;
Austin Schuhfa033692013-02-24 01:00:55 -0800101 *angle = values->horizontal_hall_effect_start_angle;
brians343bc112013-02-10 01:53:46 +0000102 return true;
103}
Austin Schuhfa033692013-02-24 01:00:55 -0800104bool horizontal_hall_effect_stop_angle(double *angle) {
105 const Values *const values = GetValues();
106 if (values == NULL) return false;
107 *angle = values->horizontal_hall_effect_stop_angle;
108 return true;
109}
110bool horizontal_upper_limit(double *angle) {
111 const Values *const values = GetValues();
112 if (values == NULL) return false;
113 *angle = values->horizontal_upper_limit;
114 return true;
115}
116
117bool horizontal_lower_limit(double *angle) {
118 const Values *const values = GetValues();
119 if (values == NULL) return false;
120 *angle = values->horizontal_lower_limit;
121 return true;
122}
123
124bool horizontal_upper_physical_limit(double *angle) {
125 const Values *const values = GetValues();
126 if (values == NULL) return false;
127 *angle = values->horizontal_upper_physical_limit;
128 return true;
129}
130
131bool horizontal_lower_physical_limit(double *angle) {
132 const Values *const values = GetValues();
133 if (values == NULL) return false;
134 *angle = values->horizontal_lower_physical_limit;
135 return true;
136}
137
138bool horizontal_zeroing_speed(double *speed) {
139 const Values *const values = GetValues();
140 if (values == NULL) return false;
141 *speed = values->horizontal_zeroing_speed;
142 return true;
143}
144
brians343bc112013-02-10 01:53:46 +0000145bool camera_center(int *center) {
146 const Values *const values = GetValues();
147 if (values == NULL) return false;
148 *center = values->camera_center;
149 return true;
150}
brians343bc112013-02-10 01:53:46 +0000151
152} // namespace constants
153} // namespace frc971