blob: bf0702296e3f3ed3f2dee1255bb9cc3c3cf3cc6f [file] [log] [blame]
Brian Silverman431500a2013-10-28 19:50:15 -07001#include "frc971/constants.h"
2
3#include <math.h>
4#include <stdint.h>
5#include <inttypes.h>
6
7#include "aos/common/logging/logging.h"
8#include "aos/common/once.h"
9#include "aos/common/network/team_number.h"
10
Brian Silverman2c590c32013-11-04 18:08:54 -080011#include "frc971/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
12#include "frc971/control_loops/drivetrain/polydrivetrain_clutch_motor_plant.h"
13#include "frc971/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
14#include "frc971/control_loops/drivetrain/drivetrain_clutch_motor_plant.h"
15
Brian Silverman431500a2013-10-28 19:50:15 -070016#ifndef M_PI
17#define M_PI 3.14159265358979323846
18#endif
19
20namespace frc971 {
21namespace constants {
22namespace {
23
Brian Silverman1a6590d2013-11-04 14:46:46 -080024const double kCompDrivetrainEncoderRatio =
25 (15.0 / 50.0) /*output reduction*/ * (36.0 / 24.0) /*encoder gears*/;
26const double kCompLowGearRatio = 14.0 / 60.0 * 15.0 / 50.0;
27const double kCompHighGearRatio = 30.0 / 44.0 * 15.0 / 50.0;
Brian Silverman431500a2013-10-28 19:50:15 -070028
Brian Silverman1a6590d2013-11-04 14:46:46 -080029const double kPracticeDrivetrainEncoderRatio =
30 (17.0 / 50.0) /*output reduction*/ * (64.0 / 24.0) /*encoder gears*/;
31const double kPracticeLowGearRatio = 16.0 / 60.0 * 19.0 / 50.0;
32const double kPracticeHighGearRatio = 28.0 / 48.0 * 19.0 / 50.0;
33
Brian Silverman98e1ab62013-11-06 21:03:23 -080034const ShifterHallEffect kCompLeftDriveShifter{0.83, 2.32, 1.2, 1.0};
Brian Silverman1a6590d2013-11-04 14:46:46 -080035const ShifterHallEffect kCompRightDriveShifter{0.865, 2.375, 1.2, 1.0};
Brian Silverman6eb51f12013-11-02 14:39:01 -070036
37const ShifterHallEffect kPracticeLeftDriveShifter{2.082283, 0.834433, 0.60,
38 0.47};
39const ShifterHallEffect kPracticeRightDriveShifter{2.070124, 0.838993, 0.62,
40 0.55};
Austin Schuhbe1401f2014-02-18 03:18:41 -080041const double shooter_zeroing_off_speed = 0.0;
42const double shooter_zeroing_speed = 0.1;
Brian Silverman6eb51f12013-11-02 14:39:01 -070043
Ben Fredricksona9dcfa42014-02-23 02:05:59 +000044const Values *DoGetValuesForTeam(uint16_t team) {
Brian Silverman431500a2013-10-28 19:50:15 -070045 switch (team) {
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080046 case 1: // for tests
47 return new Values{
48 kCompDrivetrainEncoderRatio,
49 kCompLowGearRatio,
50 kCompHighGearRatio,
51 kCompLeftDriveShifter,
52 kCompRightDriveShifter,
53 true,
54 control_loops::MakeVClutchDrivetrainLoop,
55 control_loops::MakeClutchDrivetrainLoop,
56 // ShooterLimits
57 // TODO(ben): make these real numbers
58 {-0.00127, 0.298196, -0.001524, 0.305054, 0.0149098,
59 {-0.001778, 0.000762, 0, 0}, {-0.001778, 0.009906, 0, 0}, {0.006096, 0.026416, 0, 0},
60 shooter_zeroing_off_speed,
61 shooter_zeroing_speed
62 },
63 {0.5,
64 0.1,
65 0.1,
66 0.0,
67 1.57,
68 0,
69 0,
70 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, 0, 0}, {1.0, 1.1, 0, 0}, {2.0, 2.1, 0, 0}},
71 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, 0, 0}, {1.0, 1.1, 0, 0}, {2.0, 2.1, 0, 0}},
72 0.01, // claw_unimportant_epsilon
73 0.9, // start_fine_tune_pos
74 4.0,
75 }
76 };
77 break;
Brian Silverman431500a2013-10-28 19:50:15 -070078 case kCompTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -080079 return new Values{
Austin Schuh288c8c32014-02-16 17:20:17 -080080 kCompDrivetrainEncoderRatio,
81 kCompLowGearRatio,
82 kCompHighGearRatio,
83 kCompLeftDriveShifter,
84 kCompRightDriveShifter,
85 true,
86 control_loops::MakeVClutchDrivetrainLoop,
87 control_loops::MakeClutchDrivetrainLoop,
Brian Silverman5911b402014-02-16 19:40:50 -080088 // ShooterLimits
89 // TODO(ben): make these real numbers
Austin Schuh30537882014-02-18 01:07:23 -080090 {-0.00127, 0.298196, -0.001524, 0.305054, 0.0149098,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080091 {-0.001778, 0.000762, 0, 0}, {-0.001778, 0.009906, 0, 0}, {0.006096, 0.026416, 0, 0},
Austin Schuh30537882014-02-18 01:07:23 -080092 shooter_zeroing_off_speed,
93 shooter_zeroing_speed
Austin Schuh60c56662014-02-17 14:37:19 -080094 },
Austin Schuhd27931c2014-02-16 19:18:20 -080095 {0.5,
96 0.1,
97 0.1,
98 0.0,
99 1.57,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800100 0,
101 0,
102 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, 0, 0}, {1.0, 1.1, 0, 0}, {2.0, 2.1, 0, 0}},
103 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, 0, 0}, {1.0, 1.1, 0, 0}, {2.0, 2.1, 0, 0}},
Austin Schuhd27931c2014-02-16 19:18:20 -0800104 0.01, // claw_unimportant_epsilon
105 0.9, // start_fine_tune_pos
Austin Schuh4cb047f2014-02-16 21:10:19 -0800106 4.0,
Austin Schuhd27931c2014-02-16 19:18:20 -0800107 }
Brian Silverman756f9ff2014-01-17 23:40:23 -0800108 };
Brian Silverman431500a2013-10-28 19:50:15 -0700109 break;
110 case kPracticeTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -0800111 return new Values{
Austin Schuh288c8c32014-02-16 17:20:17 -0800112 kPracticeDrivetrainEncoderRatio,
113 kPracticeLowGearRatio,
114 kPracticeHighGearRatio,
115 kPracticeLeftDriveShifter,
116 kPracticeRightDriveShifter,
117 false,
118 control_loops::MakeVDogDrivetrainLoop,
119 control_loops::MakeDogDrivetrainLoop,
Brian Silverman5911b402014-02-16 19:40:50 -0800120 // ShooterLimits
121 // TODO(ben): make these real numbers
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800122 {-0.000446, 0.300038, -0.001, 0.304354,
123 0.014436,
124 {-2, 0.001786, 0.001786, -2}, {-2, -0.000446, -2, 0.026938}, {0.006096, 0.026416, 0, 0},
Austin Schuh30537882014-02-18 01:07:23 -0800125 shooter_zeroing_off_speed,
126 shooter_zeroing_speed
Austin Schuh60c56662014-02-17 14:37:19 -0800127 },
Austin Schuhd27931c2014-02-16 19:18:20 -0800128 {0.5,
129 0.2,
130 0.1,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800131 -0.446558,
132 0.90675,
133 -0.39110,
134 0.843349,
135#if 0
136 separations (top, bottom)
137 hard min position:-0.253845, position:-0.001136,
138 soft min position:-0.244528, position:-0.047269,
139 soft max position:0.526326, position:-0.510872,
140 hard max position:0.517917, position:-0.582685,
141#endif
142 {-1.62102, 1.039699, -1.606248, 0.989702, {-1.65, -1.546252, -1.65, -1.548752}, {-0.13249, -0.02113, -0.134763, -0.021589}, {0.934024, 1.05, 0.92970, 1.05}},
143 {-1.420352, 1.348313, -1.161281, 1.264001, {-1.45, -1.283771, -1.45, -1.28468}, {-0.332476, -0.214984, -0.334294, -0.217029}, {1.248547, 1.37, 1.245366, 1.37}},
Austin Schuhd27931c2014-02-16 19:18:20 -0800144 0.01, // claw_unimportant_epsilon
145 0.9, // start_fine_tune_pos
Austin Schuh4cb047f2014-02-16 21:10:19 -0800146 4.0,
Austin Schuhd27931c2014-02-16 19:18:20 -0800147 }
Brian Silverman756f9ff2014-01-17 23:40:23 -0800148 };
Brian Silverman431500a2013-10-28 19:50:15 -0700149 break;
150 default:
151 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
152 }
153}
154
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000155const Values *DoGetValues() {
156 uint16_t team = ::aos::network::GetTeamNumber();
157 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
158 return DoGetValuesForTeam(team);
159}
160
Brian Silverman431500a2013-10-28 19:50:15 -0700161} // namespace
162
163const Values &GetValues() {
164 static ::aos::Once<const Values> once(DoGetValues);
165 return *once.Get();
166}
167
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000168const Values &GetValuesForTeam(uint16_t team_number) {
169 return *(DoGetValuesForTeam(team_number));
170}
171
Brian Silverman431500a2013-10-28 19:50:15 -0700172} // namespace constants
173} // namespace frc971