blob: a576f96e9b06dac304ea9a4b0312c95d3de276d5 [file] [log] [blame]
Austin Schuh2a3e0632018-02-19 16:24:49 -08001#ifndef Y2018_CONSTANTS_H_
2#define Y2018_CONSTANTS_H_
3
4#include <stdint.h>
5#include <math.h>
6
7#include "frc971/constants.h"
8
9#include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
10#include "y2018/control_loops/superstructure/arm/dynamics.h"
11#include "y2018/control_loops/superstructure/intake/intake_plant.h"
12
13namespace y2018 {
14namespace constants {
15
16// Has all of our "constants", except the ones that come from other places. The
17// ones which change between robots are put together with a workable way to
18// retrieve the values for the current robot.
19
20// Everything is in SI units (volts, radians, meters, seconds, etc).
21// Some of these values are related to the conversion between raw values
22// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
23//
24// All ratios are from the encoder shaft to the output units.
25
26struct Values {
27 static constexpr int kZeroingSampleSize() { return 200; }
28
29 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
30 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
31 return kDrivetrainCyclesPerRevolution() * 4;
32 }
33 static constexpr double kDrivetrainEncoderRatio() {
34 return (20.0 / 48.0) * (30.0 / 36.0);
35 }
36 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
37 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
38 control_loops::drivetrain::kHighOutputRatio /
39 constants::Values::kDrivetrainEncoderRatio() *
40 kDrivetrainEncoderCountsPerRevolution();
41 }
42
43 static constexpr double kDrivetrainShifterPotMaxVoltage() { return 2.0; }
44 static constexpr double kDrivetrainShifterPotMinVoltage() { return 1.0; }
45
46 static constexpr double kProximalEncoderCountsPerRevolution() { return 4096.0; }
47 static constexpr double kProximalEncoderRatio() {
48 return (12.0 / 60.0) * (18.0 / 84.0);
49 }
50 static constexpr double kMaxProximalEncoderPulsesPerSecond() {
51 return control_loops::superstructure::arm::Dynamics::kFreeSpeed /
52 (2.0 * M_PI) / control_loops::superstructure::arm::Dynamics::kG1 /
53 kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution();
54 }
55 static constexpr double kProximalPotRatio() { return (12.0 / 60.0); }
56
57 static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; }
58 static constexpr double kDistalEncoderRatio() { return (12.0 / 60.0); }
59 static constexpr double kMaxDistalEncoderPulsesPerSecond() {
60 return control_loops::superstructure::arm::Dynamics::kFreeSpeed /
61 (2.0 * M_PI) / control_loops::superstructure::arm::Dynamics::kG2 /
62 kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution();
63 }
64 static constexpr double kDistalPotRatio() {
65 return (12.0 / 60.0) * (36.0 / 40.0);
66 }
67
68 static constexpr double kIntakeSpringRatio() {
69 return (10.0 * 0.080) / (2.0 * 1.5 * M_PI);
70 }
71 static constexpr double kIntakeMotorEncoderCountsPerRevolution() { return 4096.0; }
72 static constexpr double kIntakeMotorEncoderRatio() {
73 return (18.0 / 68.0) * (18.0 / 50.0);
74 }
75 static constexpr double kIntakeMotorPotRatio() { return (14.0 / 68.0); }
76 static constexpr double kMaxIntakeMotorEncoderPulsesPerSecond() {
77 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
78 control_loops::superstructure::intake::kGearRatio /
79 kIntakeMotorEncoderRatio() *
80 kIntakeMotorEncoderCountsPerRevolution();
81 }
82
83 struct Intake {
84 double left_pot_offset;
85 double right_pot_offset;
86 };
87 Intake intake;
88
89 struct Proximal {
90 double pot_offset;
91 };
92 Proximal proximal;
93
94 struct Distal {
95 double pot_offset;
96 };
97 Distal distal;
98
99 double down_error;
100 const char *vision_name;
101
102 double vision_error;
103};
104
105// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
106// returns a reference to it.
107const Values &GetValues();
108
109// Creates Values instances for each team number it is called with and returns
110// them.
111const Values &GetValuesForTeam(uint16_t team_number);
112
113} // namespace constants
114} // namespace y2018
115
116#endif // Y2018_CONSTANTS_H_