blob: 21c061c980ca3a9e9aaa8f318b4ce50127e4f879 [file] [log] [blame]
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08001#ifndef Y2019_CONSTANTS_H_
2#define Y2019_CONSTANTS_H_
3
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08004#include <math.h>
Sabina Davis1b84afa2019-02-09 01:20:21 -08005#include <stdint.h>
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08006
7#include "frc971/constants.h"
Sabina Davis7be49f32019-02-02 00:30:19 -08008#include "y2019/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -08009#include "y2019/control_loops/superstructure/intake/intake_plant.h"
10#include "y2019/control_loops/superstructure/elevator/elevator_plant.h"
11#include "y2019/control_loops/superstructure/stilts/stilts_plant.h"
12#include "y2019/control_loops/superstructure/wrist/wrist_plant.h"
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080013
14namespace y2019 {
15namespace constants {
16
17// Has all of our "constants", except the ones that come from other places. The
18// ones which change between robots are put together with a workable way to
19// retrieve the values for the current robot.
20
21// Everything is in SI units (volts, radians, meters, seconds, etc).
22// Some of these values are related to the conversion between raw values
23// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
24//
25// All ratios are from the encoder shaft to the output units.
26
27struct Values {
28 static const int kZeroingSampleSize = 200;
Sabina Davis7be49f32019-02-02 00:30:19 -080029
30 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
31 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
32 return kDrivetrainCyclesPerRevolution() * 4;
33 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080034 static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); }
Sabina Davis7be49f32019-02-02 00:30:19 -080035 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 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080041
42 // Elevator
43 static constexpr double kElevatorEncoderCountsPerRevolution() {
44 return 4096.0;
45 }
46
47 static constexpr double kElevatorEncoderRatio() {
48 return (1.0) * control_loops::superstructure::elevator::kRadius;
49 }
50
51 static constexpr double kMaxElevatorEncoderPulsesPerSecond() {
52 return control_loops::superstructure::elevator::kFreeSpeed *
53 control_loops::superstructure::elevator::kOutputRatio /
54 kElevatorEncoderRatio() / (2.0 * M_PI) *
55 kElevatorEncoderCountsPerRevolution();
56 }
57
58 static constexpr double kElevatorPotRatio() {
59 return (1.0) * control_loops::superstructure::elevator::kRadius;
60 }
61
Austin Schuh7c473cb2019-02-10 14:49:19 -080062 static constexpr ::frc971::constants::Range kElevatorRange() {
63 return ::frc971::constants::Range{
64 0.0, // Bottom Hard
65 1.44, // Top Hard
66 0.025, // Bottom Soft
67 1.415 // Top Soft
68 };
69 }
70
Alex Perry5fb5ff22019-02-09 21:53:17 -080071 // Intake
72 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
73
74 static constexpr double kIntakeEncoderRatio() { return (18.0 / 38.0); }
75
76 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
77 return control_loops::superstructure::intake::kFreeSpeed *
78 control_loops::superstructure::intake::kOutputRatio /
79 kIntakeEncoderRatio() / (2.0 * M_PI) *
80 kIntakeEncoderCountsPerRevolution();
81 }
82
Austin Schuh7c473cb2019-02-10 14:49:19 -080083 static constexpr ::frc971::constants::Range kIntakeRange() {
84 return ::frc971::constants::Range{
85 -1.15, // Back Hard
86 1.36, // Front Hard
87 -1.14, // Back Soft
88 1.22 // Front Soft
89 };
90 }
91
Alex Perry5fb5ff22019-02-09 21:53:17 -080092 // Wrist
93 static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; }
94
95 static constexpr double kWristEncoderRatio() {
96 return (20.0 / 100.0) * (24.0 / 84.0);
97 }
98
99 static constexpr double kMaxWristEncoderPulsesPerSecond() {
100 return control_loops::superstructure::wrist::kFreeSpeed *
101 control_loops::superstructure::wrist::kOutputRatio /
102 kWristEncoderRatio() / (2.0 * M_PI) *
103 kWristEncoderCountsPerRevolution();
104 }
105
106 static constexpr double kWristPotRatio() { return (24.0) / (84.0); }
107
Austin Schuh7c473cb2019-02-10 14:49:19 -0800108 static constexpr ::frc971::constants::Range kWristRange() {
109 return ::frc971::constants::Range{
110 -3.14, // Back Hard
111 2.58, // Front Hard
112 -2.97, // Back Soft
113 2.41 // Front Soft
114 };
115 }
116
Alex Perry5fb5ff22019-02-09 21:53:17 -0800117 // Stilts
118 static constexpr double kStiltsEncoderCountsPerRevolution() { return 4096.0; }
119
120 static constexpr double kStiltsEncoderRatio() {
121 return (1.0 /* Gear ratio */) *
122 control_loops::superstructure::stilts::kRadius;
123 }
124
125 static constexpr double kMaxStiltsEncoderPulsesPerSecond() {
126 return control_loops::superstructure::stilts::kFreeSpeed *
127 control_loops::superstructure::stilts::kOutputRatio /
128 kStiltsEncoderRatio() / (2.0 * M_PI) *
129 kStiltsEncoderCountsPerRevolution();
130 }
131
132 static constexpr double kStiltsPotRatio() {
133 return (1.0 /* Gear ratio */) *
134 control_loops::superstructure::stilts::kRadius;
135 }
136
Austin Schuh7c473cb2019-02-10 14:49:19 -0800137 static constexpr ::frc971::constants::Range kStiltsRange() {
138 return ::frc971::constants::Range{
139 -0.026, // Top Hard
140 0.693, // Bottom Hard
141 -0.02, // Top Soft
142 0.673 // Bottom Soft
143 };
144 }
145
Alex Perry5fb5ff22019-02-09 21:53:17 -0800146 struct PotAndAbsConstants {
147 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
148 double potentiometer_offset;
149 };
150 PotAndAbsConstants elevator;
151 PotAndAbsConstants wrist;
152 PotAndAbsConstants stilts;
153
154 struct Intake {
155 ::frc971::constants::AbsoluteEncoderZeroingConstants zeroing;
156 };
157 Intake intake;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800158};
159
160// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
161// returns a reference to it.
162const Values &GetValues();
163
164// Creates Values instances for each team number it is called with and returns
165// them.
166const Values &GetValuesForTeam(uint16_t team_number);
167
168} // namespace constants
169} // namespace y2019
170
171#endif // Y2019_CONSTANTS_H_