blob: 5c0411a42325608e2fd56419b334d3a10fa4abbc [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
James Kuszmaule06e2512013-03-02 15:04:53 -080015const double kCompWristHallEffectStartAngle = 72 * M_PI / 180.0;
16const double kPracticeWristHallEffectStartAngle = 72 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080017
James Kuszmaule06e2512013-03-02 15:04:53 -080018const double kCompWristHallEffectStopAngle = 100 * M_PI / 180.0;
19const double kPracticeWristHallEffectStopAngle = 100 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080020
James Kuszmaule06e2512013-03-02 15:04:53 -080021const double kPracticeWristUpperPhysicalLimit = 95 * M_PI / 180.0;
22const double kCompWristUpperPhysicalLimit = 95 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080023
James Kuszmaule06e2512013-03-02 15:04:53 -080024const double kPracticeWristLowerPhysicalLimit = -37.5 * M_PI / 180.0;
25const double kCompWristLowerPhysicalLimit = -37.5 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080026
James Kuszmaule06e2512013-03-02 15:04:53 -080027const double kPracticeWristUpperLimit = 93 * M_PI / 180.0;
28const double kCompWristUpperLimit = 93 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080029
James Kuszmaule06e2512013-03-02 15:04:53 -080030const double kPracticeWristLowerLimit = -36 * M_PI / 180.0;
31const double kCompWristLowerLimit = -36 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080032
James Kuszmaule06e2512013-03-02 15:04:53 -080033const double kWristZeroingSpeed = 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.
James Kuszmaule06e2512013-03-02 15:04:53 -080040 double wrist_hall_effect_start_angle;
41 double wrist_hall_effect_stop_angle;
Austin Schuhfa033692013-02-24 01:00:55 -080042
43 // Upper and lower extreme limits of travel for the wrist.
James Kuszmaule06e2512013-03-02 15:04:53 -080044 double wrist_upper_limit;
45 double wrist_lower_limit;
46
Austin Schuhfa033692013-02-24 01:00:55 -080047 // Physical limits. These are here for testing.
James Kuszmaule06e2512013-03-02 15:04:53 -080048 double wrist_upper_physical_limit;
49 double wrist_lower_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -080050
51 // Zeroing speed.
James Kuszmaule06e2512013-03-02 15:04:53 -080052 double wrist_zeroing_speed;
Austin Schuhfa033692013-02-24 01:00:55 -080053
brians343bc112013-02-10 01:53:46 +000054 // what camera_center returns
55 int camera_center;
brians343bc112013-02-10 01:53:46 +000056};
Austin Schuhfa033692013-02-24 01:00:55 -080057
brians343bc112013-02-10 01:53:46 +000058Values *values = NULL;
59// Attempts to retrieve a new Values instance and stores it in values if
60// necessary.
61// Returns a valid Values instance or NULL.
62const Values *GetValues() {
Austin Schuhfa033692013-02-24 01:00:55 -080063 // TODO(brians): Make this use the new Once construct.
brians343bc112013-02-10 01:53:46 +000064 if (values == NULL) {
65 LOG(INFO, "creating a Constants for team %"PRIu16"\n",
Austin Schuhfa033692013-02-24 01:00:55 -080066 ::aos::robot_state->team_id);
67 switch (::aos::robot_state->team_id) {
brians343bc112013-02-10 01:53:46 +000068 case kCompTeamNumber:
James Kuszmaule06e2512013-03-02 15:04:53 -080069 values = new Values{kCompWristHallEffectStartAngle,
70 kCompWristHallEffectStopAngle,
71 kCompWristUpperLimit,
72 kCompWristLowerLimit,
73 kCompWristUpperPhysicalLimit,
74 kCompWristLowerPhysicalLimit,
75 kWristZeroingSpeed,
Austin Schuhfa033692013-02-24 01:00:55 -080076 kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +000077 break;
78 case kPracticeTeamNumber:
James Kuszmaule06e2512013-03-02 15:04:53 -080079 values = new Values{kPracticeWristHallEffectStartAngle,
80 kPracticeWristHallEffectStopAngle,
81 kPracticeWristUpperLimit,
82 kPracticeWristLowerLimit,
83 kPracticeWristUpperPhysicalLimit,
84 kPracticeWristLowerPhysicalLimit,
85 kWristZeroingSpeed,
Austin Schuhfa033692013-02-24 01:00:55 -080086 kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +000087 break;
88 default:
89 LOG(ERROR, "unknown team #%"PRIu16"\n",
90 aos::robot_state->team_id);
91 return NULL;
92 }
93 }
94 return values;
95}
96
97} // namespace
98
James Kuszmaule06e2512013-03-02 15:04:53 -080099bool wrist_hall_effect_start_angle(double *angle) {
brians343bc112013-02-10 01:53:46 +0000100 const Values *const values = GetValues();
101 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800102 *angle = values->wrist_hall_effect_start_angle;
brians343bc112013-02-10 01:53:46 +0000103 return true;
104}
James Kuszmaule06e2512013-03-02 15:04:53 -0800105bool wrist_hall_effect_stop_angle(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800106 const Values *const values = GetValues();
107 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800108 *angle = values->wrist_hall_effect_stop_angle;
Austin Schuhfa033692013-02-24 01:00:55 -0800109 return true;
110}
James Kuszmaule06e2512013-03-02 15:04:53 -0800111bool wrist_upper_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800112 const Values *const values = GetValues();
113 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800114 *angle = values->wrist_upper_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800115 return true;
116}
117
James Kuszmaule06e2512013-03-02 15:04:53 -0800118bool wrist_lower_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800119 const Values *const values = GetValues();
120 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800121 *angle = values->wrist_lower_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800122 return true;
123}
124
James Kuszmaule06e2512013-03-02 15:04:53 -0800125bool wrist_upper_physical_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800126 const Values *const values = GetValues();
127 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800128 *angle = values->wrist_upper_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800129 return true;
130}
131
James Kuszmaule06e2512013-03-02 15:04:53 -0800132bool wrist_lower_physical_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800133 const Values *const values = GetValues();
134 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800135 *angle = values->wrist_lower_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800136 return true;
137}
138
James Kuszmaule06e2512013-03-02 15:04:53 -0800139bool wrist_zeroing_speed(double *speed) {
Austin Schuhfa033692013-02-24 01:00:55 -0800140 const Values *const values = GetValues();
141 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800142 *speed = values->wrist_zeroing_speed;
Austin Schuhfa033692013-02-24 01:00:55 -0800143 return true;
144}
145
brians343bc112013-02-10 01:53:46 +0000146bool camera_center(int *center) {
147 const Values *const values = GetValues();
148 if (values == NULL) return false;
149 *center = values->camera_center;
150 return true;
151}
brians343bc112013-02-10 01:53:46 +0000152
153} // namespace constants
154} // namespace frc971