blob: a7bbfa54ee98714e41c6f626536d2f1089f9acbe [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>
brians343bc112013-02-10 01:53:46 +00005
Brian Silverman20fdbef2013-03-09 13:42:03 -08006#include "aos/common/inttypes.h"
brians343bc112013-02-10 01:53:46 +00007#include "aos/common/messages/RobotState.q.h"
8#include "aos/atom_code/output/MotorOutput.h"
9
Brian Silverman20fdbef2013-03-09 13:42:03 -080010#ifndef M_PI
11#define M_PI 3.14159265358979323846
12#endif
13
brians343bc112013-02-10 01:53:46 +000014namespace frc971 {
15namespace constants {
16
17namespace {
18
James Kuszmaule06e2512013-03-02 15:04:53 -080019const double kCompWristHallEffectStartAngle = 72 * M_PI / 180.0;
20const double kPracticeWristHallEffectStartAngle = 72 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080021
James Kuszmaule06e2512013-03-02 15:04:53 -080022const double kCompWristHallEffectStopAngle = 100 * M_PI / 180.0;
23const double kPracticeWristHallEffectStopAngle = 100 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080024
James Kuszmaule06e2512013-03-02 15:04:53 -080025const double kPracticeWristUpperPhysicalLimit = 95 * M_PI / 180.0;
26const double kCompWristUpperPhysicalLimit = 95 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080027
James Kuszmaule06e2512013-03-02 15:04:53 -080028const double kPracticeWristLowerPhysicalLimit = -37.5 * M_PI / 180.0;
29const double kCompWristLowerPhysicalLimit = -37.5 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080030
James Kuszmaule06e2512013-03-02 15:04:53 -080031const double kPracticeWristUpperLimit = 93 * M_PI / 180.0;
32const double kCompWristUpperLimit = 93 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080033
James Kuszmaule06e2512013-03-02 15:04:53 -080034const double kPracticeWristLowerLimit = -36 * M_PI / 180.0;
35const double kCompWristLowerLimit = -36 * M_PI / 180.0;
Austin Schuhfa033692013-02-24 01:00:55 -080036
James Kuszmaule06e2512013-03-02 15:04:53 -080037const double kWristZeroingSpeed = 1.0;
Austin Schuhfa033692013-02-24 01:00:55 -080038
brians343bc112013-02-10 01:53:46 +000039const int kCompCameraCenter = -2;
40const int kPracticeCameraCenter = -5;
41
42struct Values {
Austin Schuhfa033692013-02-24 01:00:55 -080043 // Wrist hall effect positive and negative edges.
James Kuszmaule06e2512013-03-02 15:04:53 -080044 double wrist_hall_effect_start_angle;
45 double wrist_hall_effect_stop_angle;
Austin Schuhfa033692013-02-24 01:00:55 -080046
47 // Upper and lower extreme limits of travel for the wrist.
James Kuszmaule06e2512013-03-02 15:04:53 -080048 double wrist_upper_limit;
49 double wrist_lower_limit;
50
Austin Schuhfa033692013-02-24 01:00:55 -080051 // Physical limits. These are here for testing.
James Kuszmaule06e2512013-03-02 15:04:53 -080052 double wrist_upper_physical_limit;
53 double wrist_lower_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -080054
55 // Zeroing speed.
James Kuszmaule06e2512013-03-02 15:04:53 -080056 double wrist_zeroing_speed;
Austin Schuhfa033692013-02-24 01:00:55 -080057
brians343bc112013-02-10 01:53:46 +000058 // what camera_center returns
59 int camera_center;
brians343bc112013-02-10 01:53:46 +000060};
Austin Schuhfa033692013-02-24 01:00:55 -080061
brians343bc112013-02-10 01:53:46 +000062Values *values = NULL;
63// Attempts to retrieve a new Values instance and stores it in values if
64// necessary.
65// Returns a valid Values instance or NULL.
66const Values *GetValues() {
Austin Schuhfa033692013-02-24 01:00:55 -080067 // TODO(brians): Make this use the new Once construct.
brians343bc112013-02-10 01:53:46 +000068 if (values == NULL) {
69 LOG(INFO, "creating a Constants for team %"PRIu16"\n",
Austin Schuhfa033692013-02-24 01:00:55 -080070 ::aos::robot_state->team_id);
71 switch (::aos::robot_state->team_id) {
brians343bc112013-02-10 01:53:46 +000072 case kCompTeamNumber:
James Kuszmaule06e2512013-03-02 15:04:53 -080073 values = new Values{kCompWristHallEffectStartAngle,
74 kCompWristHallEffectStopAngle,
75 kCompWristUpperLimit,
76 kCompWristLowerLimit,
77 kCompWristUpperPhysicalLimit,
78 kCompWristLowerPhysicalLimit,
79 kWristZeroingSpeed,
Austin Schuhfa033692013-02-24 01:00:55 -080080 kCompCameraCenter};
brians343bc112013-02-10 01:53:46 +000081 break;
82 case kPracticeTeamNumber:
James Kuszmaule06e2512013-03-02 15:04:53 -080083 values = new Values{kPracticeWristHallEffectStartAngle,
84 kPracticeWristHallEffectStopAngle,
85 kPracticeWristUpperLimit,
86 kPracticeWristLowerLimit,
87 kPracticeWristUpperPhysicalLimit,
88 kPracticeWristLowerPhysicalLimit,
89 kWristZeroingSpeed,
Austin Schuhfa033692013-02-24 01:00:55 -080090 kPracticeCameraCenter};
brians343bc112013-02-10 01:53:46 +000091 break;
92 default:
93 LOG(ERROR, "unknown team #%"PRIu16"\n",
94 aos::robot_state->team_id);
95 return NULL;
96 }
97 }
98 return values;
99}
100
101} // namespace
102
James Kuszmaule06e2512013-03-02 15:04:53 -0800103bool wrist_hall_effect_start_angle(double *angle) {
brians343bc112013-02-10 01:53:46 +0000104 const Values *const values = GetValues();
105 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800106 *angle = values->wrist_hall_effect_start_angle;
brians343bc112013-02-10 01:53:46 +0000107 return true;
108}
James Kuszmaule06e2512013-03-02 15:04:53 -0800109bool wrist_hall_effect_stop_angle(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800110 const Values *const values = GetValues();
111 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800112 *angle = values->wrist_hall_effect_stop_angle;
Austin Schuhfa033692013-02-24 01:00:55 -0800113 return true;
114}
James Kuszmaule06e2512013-03-02 15:04:53 -0800115bool wrist_upper_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800116 const Values *const values = GetValues();
117 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800118 *angle = values->wrist_upper_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800119 return true;
120}
121
James Kuszmaule06e2512013-03-02 15:04:53 -0800122bool wrist_lower_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800123 const Values *const values = GetValues();
124 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800125 *angle = values->wrist_lower_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800126 return true;
127}
128
James Kuszmaule06e2512013-03-02 15:04:53 -0800129bool wrist_upper_physical_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800130 const Values *const values = GetValues();
131 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800132 *angle = values->wrist_upper_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800133 return true;
134}
135
James Kuszmaule06e2512013-03-02 15:04:53 -0800136bool wrist_lower_physical_limit(double *angle) {
Austin Schuhfa033692013-02-24 01:00:55 -0800137 const Values *const values = GetValues();
138 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800139 *angle = values->wrist_lower_physical_limit;
Austin Schuhfa033692013-02-24 01:00:55 -0800140 return true;
141}
142
James Kuszmaule06e2512013-03-02 15:04:53 -0800143bool wrist_zeroing_speed(double *speed) {
Austin Schuhfa033692013-02-24 01:00:55 -0800144 const Values *const values = GetValues();
145 if (values == NULL) return false;
James Kuszmaule06e2512013-03-02 15:04:53 -0800146 *speed = values->wrist_zeroing_speed;
Austin Schuhfa033692013-02-24 01:00:55 -0800147 return true;
148}
149
brians343bc112013-02-10 01:53:46 +0000150bool camera_center(int *center) {
151 const Values *const values = GetValues();
152 if (values == NULL) return false;
153 *center = values->camera_center;
154 return true;
155}
brians343bc112013-02-10 01:53:46 +0000156
157} // namespace constants
158} // namespace frc971