blob: 1c18bde60ff44994d4e23dd90c919bfbe8d60af1 [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 {
Sabina Davis8d20ca82018-02-19 13:17:45 -080027 static constexpr size_t kZeroingSampleSize() { return 200; }
Austin Schuh2a3e0632018-02-19 16:24:49 -080028
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
Sabina Davis8d20ca82018-02-19 13:17:45 -080083 static constexpr ::frc971::constants::Range kIntakeRange() {
84 return ::frc971::constants::Range{(-0.75 * M_PI), (1.25 * M_PI),
85 (-2.0 / 3.0 * M_PI), M_PI};
86 }
87
88 struct IntakeSide {
89 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
90 double potentiometer_offset;
91 double spring_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -080092 };
Sabina Davis8d20ca82018-02-19 13:17:45 -080093 IntakeSide left_intake;
94 IntakeSide right_intake;
Austin Schuh2a3e0632018-02-19 16:24:49 -080095
96 struct Proximal {
Sabina Davis8d20ca82018-02-19 13:17:45 -080097 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
98 double potentiometer_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -080099 };
Austin Schuhcb091712018-02-21 20:01:55 -0800100 Proximal arm_proximal;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800101
102 struct Distal {
Sabina Davis8d20ca82018-02-19 13:17:45 -0800103 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
104 double potentiometer_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800105 };
Austin Schuhcb091712018-02-21 20:01:55 -0800106 Distal arm_distal;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800107
Austin Schuh2a3e0632018-02-19 16:24:49 -0800108 const char *vision_name;
109
110 double vision_error;
111};
112
113// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
114// returns a reference to it.
115const Values &GetValues();
116
117// Creates Values instances for each team number it is called with and returns
118// them.
119const Values &GetValuesForTeam(uint16_t team_number);
120
121} // namespace constants
122} // namespace y2018
123
124#endif // Y2018_CONSTANTS_H_