blob: 9d29107603b0408e1e6fb3bb7facb0d8d9076db0 [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
Austin Schuh809c2562014-03-02 11:50:19 -080034const ShifterHallEffect kCompRightDriveShifter{525, 635, 603, 529, 0.3, 0.7};
35const ShifterHallEffect kCompLeftDriveShifter{525, 645, 620, 533, 0.3, 0.7};
Brian Silverman6eb51f12013-11-02 14:39:01 -070036
Austin Schuh809c2562014-03-02 11:50:19 -080037const ShifterHallEffect kPracticeRightDriveShifter{550, 640, 635, 550, 0.2, 0.7};
38const ShifterHallEffect kPracticeLeftDriveShifter{540, 620, 640, 550, 0.2, 0.7};
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,
Austin Schuh11726212014-03-02 14:01:02 -080051 false,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080052 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,
James Kuszmaul9ead1de2014-02-28 21:24:39 -080073 },
Austin Schuh809c2562014-03-02 11:50:19 -080074 {0.07, 0.15}, // shooter_action
Ben Fredrickson890c3fe2014-03-02 00:15:16 +000075 0.02, // drivetrain done delta
76 5.0 // drivetrain max speed
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080077 };
78 break;
Brian Silverman431500a2013-10-28 19:50:15 -070079 case kCompTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -080080 return new Values{
Austin Schuh288c8c32014-02-16 17:20:17 -080081 kCompDrivetrainEncoderRatio,
82 kCompLowGearRatio,
83 kCompHighGearRatio,
84 kCompLeftDriveShifter,
85 kCompRightDriveShifter,
Austin Schuh11726212014-03-02 14:01:02 -080086 false,
Austin Schuh288c8c32014-02-16 17:20:17 -080087 control_loops::MakeVClutchDrivetrainLoop,
88 control_loops::MakeClutchDrivetrainLoop,
Brian Silverman5911b402014-02-16 19:40:50 -080089 // ShooterLimits
90 // TODO(ben): make these real numbers
Austin Schuh30537882014-02-18 01:07:23 -080091 {-0.00127, 0.298196, -0.001524, 0.305054, 0.0149098,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -080092 {-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 -080093 shooter_zeroing_speed,
94 shooter_unload_speed
Austin Schuh60c56662014-02-17 14:37:19 -080095 },
Austin Schuhd27931c2014-02-16 19:18:20 -080096 {0.5,
97 0.1,
98 0.1,
99 0.0,
100 1.57,
Brian Silverman0d2b7cb2014-02-18 20:25:57 -0800101 0,
102 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}},
104 {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 -0800105 0.01, // claw_unimportant_epsilon
106 0.9, // start_fine_tune_pos
Austin Schuh4cb047f2014-02-16 21:10:19 -0800107 4.0,
James Kuszmaul9ead1de2014-02-28 21:24:39 -0800108 },
109 //TODO(james): Get realer numbers for shooter_action.
Austin Schuh809c2562014-03-02 11:50:19 -0800110 {0.07, 0.15}, // shooter_action
Ben Fredrickson890c3fe2014-03-02 00:15:16 +0000111 0.02, // drivetrain done delta
112 5.0 // drivetrain max speed
Brian Silverman756f9ff2014-01-17 23:40:23 -0800113 };
Brian Silverman431500a2013-10-28 19:50:15 -0700114 break;
115 case kPracticeTeamNumber:
Brian Silverman756f9ff2014-01-17 23:40:23 -0800116 return new Values{
Austin Schuh288c8c32014-02-16 17:20:17 -0800117 kPracticeDrivetrainEncoderRatio,
118 kPracticeLowGearRatio,
119 kPracticeHighGearRatio,
120 kPracticeLeftDriveShifter,
121 kPracticeRightDriveShifter,
122 false,
123 control_loops::MakeVDogDrivetrainLoop,
124 control_loops::MakeDogDrivetrainLoop,
Brian Silverman5911b402014-02-16 19:40:50 -0800125 // ShooterLimits
Austin Schuh06cbbf12014-02-22 02:07:31 -0800126 {-0.001042, 0.294084, -0.001935, 0.303460, 0.0138401,
127 {-0.002, 0.000446, -0.002, 0.000446},
128 {-0.002, 0.009078, -0.002, 0.009078},
129 {0.003869, 0.026194, 0.003869, 0.026194},
Austin Schuh6b428602014-02-22 21:02:00 -0800130 shooter_zeroing_speed,
131 shooter_unload_speed
Austin Schuh60c56662014-02-17 14:37:19 -0800132 },
Austin Schuh78d55462014-02-23 01:39:30 -0800133 {0.400000 * 2.0,
134 0.200000 * 2.0,
135 0.000000 * 2.0,
136 -0.762218 * 2.0,
137 0.912207 * 2.0,
138 -0.849484,
139 1.42308,
140 {-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}},
141 {-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}},
142 0.020000 * 2.0, // claw_unimportant_epsilon
143 -0.200000 * 2.0, // start_fine_tune_pos
Austin Schuh54e2e6c2014-02-21 22:58:53 -0800144 4.000000,
James Kuszmaul9ead1de2014-02-28 21:24:39 -0800145 },
146 //TODO(james): Get realer numbers for shooter_action.
Austin Schuh809c2562014-03-02 11:50:19 -0800147 {0.07, 0.15}, // shooter_action
Ben Fredrickson890c3fe2014-03-02 00:15:16 +0000148 0.02, // drivetrain done delta
149 5.0 // drivetrain max speed
Brian Silverman756f9ff2014-01-17 23:40:23 -0800150 };
Brian Silverman431500a2013-10-28 19:50:15 -0700151 break;
152 default:
153 LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
154 }
155}
156
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000157const Values *DoGetValues() {
158 uint16_t team = ::aos::network::GetTeamNumber();
159 LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
160 return DoGetValuesForTeam(team);
161}
162
Brian Silverman431500a2013-10-28 19:50:15 -0700163} // namespace
164
165const Values &GetValues() {
166 static ::aos::Once<const Values> once(DoGetValues);
167 return *once.Get();
168}
169
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000170const Values &GetValuesForTeam(uint16_t team_number) {
171 return *(DoGetValuesForTeam(team_number));
172}
173
Brian Silverman431500a2013-10-28 19:50:15 -0700174} // namespace constants
175} // namespace frc971