blob: 1e5e1d0d68e3d953b29e71bc4ffaa274dbafbc5b [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
Austin Schuh78d55462014-02-23 01:39:30 -080037const ShifterHallEffect kPracticeRightDriveShifter{2.575, 3.16, 0.98, 0.40};
38const ShifterHallEffect kPracticeLeftDriveShifter{2.57, 3.15, 0.98, 0.4};
Austin Schuh06cbbf12014-02-22 02:07:31 -080039const double shooter_zeroing_speed = 0.05;
Austin Schuh6b428602014-02-22 21:02:00 -080040const double shooter_unload_speed = 0.08;
Brian Silverman6eb51f12013-11-02 14:39:01 -070041
Ben Fredricksona9dcfa42014-02-23 02:05:59 +000042const Values *DoGetValuesForTeam(uint16_t team) {
Brian Silverman431500a2013-10-28 19:50:15 -070043 switch (team) {
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080044 case 1: // for tests
45 return new Values{
46 kCompDrivetrainEncoderRatio,
47 kCompLowGearRatio,
48 kCompHighGearRatio,
49 kCompLeftDriveShifter,
50 kCompRightDriveShifter,
51 true,
52 control_loops::MakeVClutchDrivetrainLoop,
53 control_loops::MakeClutchDrivetrainLoop,
54 // ShooterLimits
55 // TODO(ben): make these real numbers
56 {-0.00127, 0.298196, -0.001524, 0.305054, 0.0149098,
57 {-0.001778, 0.000762, 0, 0}, {-0.001778, 0.009906, 0, 0}, {0.006096, 0.026416, 0, 0},
Austin Schuh6b428602014-02-22 21:02:00 -080058 shooter_zeroing_speed,
59 shooter_unload_speed
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080060 },
61 {0.5,
62 0.1,
63 0.1,
64 0.0,
65 1.57,
66 0,
67 0,
Austin Schuh27b8fb12014-02-22 15:10:05 -080068 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, -0.1, 0.05}, {1.0, 1.1, 1.0, 1.1}, {2.0, 2.1, 2.0, 2.1}},
69 {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, -0.1, 0.05}, {1.0, 1.1, 1.0, 1.1}, {2.0, 2.1, 2.0, 2.1}},
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080070 0.01, // claw_unimportant_epsilon
71 0.9, // start_fine_tune_pos
72 4.0,
73 }
74 };
75 break;
Brian Silverman431500a2013-10-28 19:50:15 -070076 case kCompTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -080077 return new Values{
Austin Schuh288c8c32014-02-16 17:20:17 -080078 kCompDrivetrainEncoderRatio,
79 kCompLowGearRatio,
80 kCompHighGearRatio,
81 kCompLeftDriveShifter,
82 kCompRightDriveShifter,
83 true,
84 control_loops::MakeVClutchDrivetrainLoop,
85 control_loops::MakeClutchDrivetrainLoop,
Brian Silverman5911b402014-02-16 19:40:50 -080086 // ShooterLimits
87 // TODO(ben): make these real numbers
Austin Schuh30537882014-02-18 01:07:23 -080088 {-0.00127, 0.298196, -0.001524, 0.305054, 0.0149098,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080089 {-0.001778, 0.000762, 0, 0}, {-0.001778, 0.009906, 0, 0}, {0.006096, 0.026416, 0, 0},
Austin Schuh6b428602014-02-22 21:02:00 -080090 shooter_zeroing_speed,
91 shooter_unload_speed
Austin Schuh60c56662014-02-17 14:37:19 -080092 },
Austin Schuhd27931c2014-02-16 19:18:20 -080093 {0.5,
94 0.1,
95 0.1,
96 0.0,
97 1.57,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080098 0,
99 0,
100 {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}},
101 {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 -0800102 0.01, // claw_unimportant_epsilon
103 0.9, // start_fine_tune_pos
Austin Schuh4cb047f2014-02-16 21:10:19 -0800104 4.0,
Austin Schuhd27931c2014-02-16 19:18:20 -0800105 }
Brian Silverman756f9ff2014-01-17 23:40:23 -0800106 };
Brian Silverman431500a2013-10-28 19:50:15 -0700107 break;
108 case kPracticeTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -0800109 return new Values{
Austin Schuh288c8c32014-02-16 17:20:17 -0800110 kPracticeDrivetrainEncoderRatio,
111 kPracticeLowGearRatio,
112 kPracticeHighGearRatio,
113 kPracticeLeftDriveShifter,
114 kPracticeRightDriveShifter,
115 false,
116 control_loops::MakeVDogDrivetrainLoop,
117 control_loops::MakeDogDrivetrainLoop,
Brian Silverman5911b402014-02-16 19:40:50 -0800118 // ShooterLimits
119 // TODO(ben): make these real numbers
Austin Schuh06cbbf12014-02-22 02:07:31 -0800120 {-0.001042, 0.294084, -0.001935, 0.303460, 0.0138401,
121 {-0.002, 0.000446, -0.002, 0.000446},
122 {-0.002, 0.009078, -0.002, 0.009078},
123 {0.003869, 0.026194, 0.003869, 0.026194},
Austin Schuh6b428602014-02-22 21:02:00 -0800124 shooter_zeroing_speed,
125 shooter_unload_speed
Austin Schuh60c56662014-02-17 14:37:19 -0800126 },
Austin Schuh78d55462014-02-23 01:39:30 -0800127 {0.400000 * 2.0,
128 0.200000 * 2.0,
129 0.000000 * 2.0,
130 -0.762218 * 2.0,
131 0.912207 * 2.0,
132 -0.849484,
133 1.42308,
134 {-1.682379 * 2.0, 1.043334 * 2.0, -3.166136, 0.643334 * 2.0, {-1.7 * 2.0, -1.544662 * 2.0, -1.7 * 2.0, -1.547616 * 2.0}, {-0.130218 * 2.0, -0.019771 * 2.0, -0.132036 * 2.0, -0.018862 * 2.0}, {0.935842 * 2.0, 1.1 * 2.0, 0.932660 * 2.0, 1.1 * 2.0}},
135 {-1.225821 * 2.0, 1.553752 * 2.0, -2.273474, 1.153752 * 2.0, {-1.3 * 2.0, -1.088331 * 2.0, -1.3 * 2.0, -1.088331 * 2.0}, {-0.134536 * 2.0, -0.018408 * 2.0, -0.136127 * 2.0, -0.019771 * 2.0}, {1.447396 * 2.0, 1.6 * 2.0, 1.443987 * 2.0, 1.6 * 2.0}},
136 0.020000 * 2.0, // claw_unimportant_epsilon
137 -0.200000 * 2.0, // start_fine_tune_pos
Austin Schuh54e2e6c2014-02-21 22:58:53 -0800138 4.000000,
Austin Schuhd27931c2014-02-16 19:18:20 -0800139 }
Brian Silverman756f9ff2014-01-17 23:40:23 -0800140 };
Brian Silverman431500a2013-10-28 19:50:15 -0700141 break;
142 default:
143 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
144 }
145}
146
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000147const Values *DoGetValues() {
148 uint16_t team = ::aos::network::GetTeamNumber();
149 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
150 return DoGetValuesForTeam(team);
151}
152
Brian Silverman431500a2013-10-28 19:50:15 -0700153} // namespace
154
155const Values &GetValues() {
156 static ::aos::Once<const Values> once(DoGetValues);
157 return *once.Get();
158}
159
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000160const Values &GetValuesForTeam(uint16_t team_number) {
161 return *(DoGetValuesForTeam(team_number));
162}
163
Brian Silverman431500a2013-10-28 19:50:15 -0700164} // namespace constants
165} // namespace frc971