blob: 16f1f8c9fc8001c23e03cb2ae7f8160b9f12ab74 [file] [log] [blame]
Austin Schuh2a3e0632018-02-19 16:24:49 -08001#ifndef Y2018_CONSTANTS_H_
2#define Y2018_CONSTANTS_H_
3
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cmath>
5#include <cstdint>
Austin Schuh2a3e0632018-02-19 16:24:49 -08006
7#include "frc971/constants.h"
Austin Schuh2a3e0632018-02-19 16:24:49 -08008#include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
9#include "y2018/control_loops/superstructure/arm/dynamics.h"
10#include "y2018/control_loops/superstructure/intake/intake_plant.h"
11
12namespace y2018 {
13namespace constants {
14
15// Has all of our "constants", except the ones that come from other places. The
16// ones which change between robots are put together with a workable way to
17// retrieve the values for the current robot.
18
19// Everything is in SI units (volts, radians, meters, seconds, etc).
20// Some of these values are related to the conversion between raw values
21// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
22//
23// All ratios are from the encoder shaft to the output units.
24
25struct Values {
Sabina Davis8d20ca82018-02-19 13:17:45 -080026 static constexpr size_t kZeroingSampleSize() { return 200; }
Austin Schuh2a3e0632018-02-19 16:24:49 -080027
28 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
29 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
30 return kDrivetrainCyclesPerRevolution() * 4;
31 }
32 static constexpr double kDrivetrainEncoderRatio() {
33 return (20.0 / 48.0) * (30.0 / 36.0);
34 }
35 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
36 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
37 control_loops::drivetrain::kHighOutputRatio /
38 constants::Values::kDrivetrainEncoderRatio() *
39 kDrivetrainEncoderCountsPerRevolution();
40 }
41
Austin Schuh17dd0892018-03-02 20:06:31 -080042 static constexpr double kDrivetrainShifterPotMaxVoltage() { return 3.63; }
43 static constexpr double kDrivetrainShifterPotMinVoltage() { return 1.94; }
Austin Schuh2a3e0632018-02-19 16:24:49 -080044
Tyler Chatowbf0609c2021-07-31 16:13:27 -070045 static constexpr double kProximalEncoderCountsPerRevolution() {
46 return 4096.0;
47 }
Austin Schuh2a3e0632018-02-19 16:24:49 -080048 static constexpr double kProximalEncoderRatio() {
49 return (12.0 / 60.0) * (18.0 / 84.0);
50 }
51 static constexpr double kMaxProximalEncoderPulsesPerSecond() {
52 return control_loops::superstructure::arm::Dynamics::kFreeSpeed /
53 (2.0 * M_PI) / control_loops::superstructure::arm::Dynamics::kG1 /
54 kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution();
55 }
56 static constexpr double kProximalPotRatio() { return (12.0 / 60.0); }
57
58 static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; }
59 static constexpr double kDistalEncoderRatio() { return (12.0 / 60.0); }
60 static constexpr double kMaxDistalEncoderPulsesPerSecond() {
61 return control_loops::superstructure::arm::Dynamics::kFreeSpeed /
62 (2.0 * M_PI) / control_loops::superstructure::arm::Dynamics::kG2 /
63 kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution();
64 }
65 static constexpr double kDistalPotRatio() {
66 return (12.0 / 60.0) * (36.0 / 40.0);
67 }
68
69 static constexpr double kIntakeSpringRatio() {
70 return (10.0 * 0.080) / (2.0 * 1.5 * M_PI);
71 }
Austin Schuh6829f762018-03-02 21:36:01 -080072 static constexpr double kIntakeMotorEncoderCountsPerRevolution() {
73 return 4096.0;
74 }
Austin Schuh2a3e0632018-02-19 16:24:49 -080075 static constexpr double kIntakeMotorEncoderRatio() {
76 return (18.0 / 68.0) * (18.0 / 50.0);
77 }
78 static constexpr double kIntakeMotorPotRatio() { return (14.0 / 68.0); }
79 static constexpr double kMaxIntakeMotorEncoderPulsesPerSecond() {
80 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
81 control_loops::superstructure::intake::kGearRatio /
82 kIntakeMotorEncoderRatio() *
83 kIntakeMotorEncoderCountsPerRevolution();
84 }
85
Sabina Davis8d20ca82018-02-19 13:17:45 -080086 static constexpr ::frc971::constants::Range kIntakeRange() {
Austin Schuh6829f762018-03-02 21:36:01 -080087 // TODO(austin) Sort this out.
Tyler Chatowbf0609c2021-07-31 16:13:27 -070088 return ::frc971::constants::Range{-3.7, (1.25 * M_PI), -3.3, M_PI};
Sabina Davis8d20ca82018-02-19 13:17:45 -080089 }
90
91 struct IntakeSide {
92 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
93 double potentiometer_offset;
94 double spring_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -080095 };
Sabina Davis8d20ca82018-02-19 13:17:45 -080096 IntakeSide left_intake;
97 IntakeSide right_intake;
Austin Schuh2a3e0632018-02-19 16:24:49 -080098
99 struct Proximal {
Sabina Davis8d20ca82018-02-19 13:17:45 -0800100 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
101 double potentiometer_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800102 };
Austin Schuhcb091712018-02-21 20:01:55 -0800103 Proximal arm_proximal;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800104
105 struct Distal {
Sabina Davis8d20ca82018-02-19 13:17:45 -0800106 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
107 double potentiometer_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800108 };
Austin Schuhcb091712018-02-21 20:01:55 -0800109 Distal arm_distal;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800110
Austin Schuh2a3e0632018-02-19 16:24:49 -0800111 const char *vision_name;
112
113 double vision_error;
114};
115
116// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
117// returns a reference to it.
118const Values &GetValues();
119
120// Creates Values instances for each team number it is called with and returns
121// them.
122const Values &GetValuesForTeam(uint16_t team_number);
123
124} // namespace constants
125} // namespace y2018
126
127#endif // Y2018_CONSTANTS_H_