blob: 46d28f1c72b1bda0d8906b93ba1ec1dab6c80276 [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"
Theo Bafrali00e42272019-02-12 01:07:46 -08008#include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
Sabina Davis7be49f32019-02-02 00:30:19 -08009#include "y2019/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080010#include "y2019/control_loops/superstructure/elevator/elevator_plant.h"
Theo Bafrali00e42272019-02-12 01:07:46 -080011#include "y2019/control_loops/superstructure/intake/intake_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080012#include "y2019/control_loops/superstructure/stilts/stilts_plant.h"
13#include "y2019/control_loops/superstructure/wrist/wrist_plant.h"
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080014
15namespace y2019 {
16namespace constants {
17
18// Has all of our "constants", except the ones that come from other places. The
19// ones which change between robots are put together with a workable way to
20// retrieve the values for the current robot.
21
22// Everything is in SI units (volts, radians, meters, seconds, etc).
23// Some of these values are related to the conversion between raw values
24// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
25//
26// All ratios are from the encoder shaft to the output units.
27
28struct Values {
29 static const int kZeroingSampleSize = 200;
Sabina Davis7be49f32019-02-02 00:30:19 -080030
Theo Bafrali00e42272019-02-12 01:07:46 -080031 // Drivetrain Constants
Sabina Davis7be49f32019-02-02 00:30:19 -080032 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
33 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
34 return kDrivetrainCyclesPerRevolution() * 4;
35 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080036 static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); }
Sabina Davis7be49f32019-02-02 00:30:19 -080037 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
38 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
39 control_loops::drivetrain::kHighOutputRatio /
40 constants::Values::kDrivetrainEncoderRatio() *
41 kDrivetrainEncoderCountsPerRevolution();
42 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080043
44 // Elevator
45 static constexpr double kElevatorEncoderCountsPerRevolution() {
46 return 4096.0;
47 }
48
49 static constexpr double kElevatorEncoderRatio() {
50 return (1.0) * control_loops::superstructure::elevator::kRadius;
51 }
52
53 static constexpr double kMaxElevatorEncoderPulsesPerSecond() {
54 return control_loops::superstructure::elevator::kFreeSpeed *
55 control_loops::superstructure::elevator::kOutputRatio /
56 kElevatorEncoderRatio() / (2.0 * M_PI) *
57 kElevatorEncoderCountsPerRevolution();
58 }
59
60 static constexpr double kElevatorPotRatio() {
61 return (1.0) * control_loops::superstructure::elevator::kRadius;
62 }
63
Austin Schuh7c473cb2019-02-10 14:49:19 -080064 static constexpr ::frc971::constants::Range kElevatorRange() {
65 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -080066 -0.01, // Bottom Hard
67 1.62, // Top Hard
68 0.01, // Bottom Soft
69 1.59 // Top Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -080070 };
71 }
72
Alex Perry5fb5ff22019-02-09 21:53:17 -080073 // Intake
74 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
75
76 static constexpr double kIntakeEncoderRatio() { return (18.0 / 38.0); }
77
78 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
79 return control_loops::superstructure::intake::kFreeSpeed *
80 control_loops::superstructure::intake::kOutputRatio /
81 kIntakeEncoderRatio() / (2.0 * M_PI) *
82 kIntakeEncoderCountsPerRevolution();
83 }
84
Austin Schuh7c473cb2019-02-10 14:49:19 -080085 static constexpr ::frc971::constants::Range kIntakeRange() {
86 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -080087 -1.30, // Back Hard
88 1.35, // Front Hard
89 -1.25, // Back Soft
90 1.30 // Front Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -080091 };
92 }
93
Alex Perry5fb5ff22019-02-09 21:53:17 -080094 // Wrist
95 static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; }
96
97 static constexpr double kWristEncoderRatio() {
98 return (20.0 / 100.0) * (24.0 / 84.0);
99 }
100
101 static constexpr double kMaxWristEncoderPulsesPerSecond() {
102 return control_loops::superstructure::wrist::kFreeSpeed *
103 control_loops::superstructure::wrist::kOutputRatio /
104 kWristEncoderRatio() / (2.0 * M_PI) *
105 kWristEncoderCountsPerRevolution();
106 }
107
108 static constexpr double kWristPotRatio() { return (24.0) / (84.0); }
109
Austin Schuh7c473cb2019-02-10 14:49:19 -0800110 static constexpr ::frc971::constants::Range kWristRange() {
111 return ::frc971::constants::Range{
112 -3.14, // Back Hard
Austin Schuhed7f8632019-02-15 23:12:20 -0800113 3.14, // Front Hard
Austin Schuh7c473cb2019-02-10 14:49:19 -0800114 -2.97, // Back Soft
115 2.41 // Front Soft
116 };
117 }
118
Alex Perry5fb5ff22019-02-09 21:53:17 -0800119 // Stilts
120 static constexpr double kStiltsEncoderCountsPerRevolution() { return 4096.0; }
121
Theo Bafrali00e42272019-02-12 01:07:46 -0800122 // Stilts Constants
Alex Perry5fb5ff22019-02-09 21:53:17 -0800123 static constexpr double kStiltsEncoderRatio() {
124 return (1.0 /* Gear ratio */) *
125 control_loops::superstructure::stilts::kRadius;
126 }
127
128 static constexpr double kMaxStiltsEncoderPulsesPerSecond() {
129 return control_loops::superstructure::stilts::kFreeSpeed *
130 control_loops::superstructure::stilts::kOutputRatio /
131 kStiltsEncoderRatio() / (2.0 * M_PI) *
132 kStiltsEncoderCountsPerRevolution();
133 }
134
135 static constexpr double kStiltsPotRatio() {
136 return (1.0 /* Gear ratio */) *
137 control_loops::superstructure::stilts::kRadius;
138 }
139
Austin Schuh7c473cb2019-02-10 14:49:19 -0800140 static constexpr ::frc971::constants::Range kStiltsRange() {
141 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -0800142 -0.01, // Top Hard
143 0.72, // Bottom Hard
144 0.00, // Top Soft
145 0.71 // Bottom Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800146 };
147 }
148
Alex Perry5fb5ff22019-02-09 21:53:17 -0800149 struct PotAndAbsConstants {
Theo Bafrali00e42272019-02-12 01:07:46 -0800150 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
151 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
152 subsystem_params;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800153 double potentiometer_offset;
154 };
Theo Bafrali00e42272019-02-12 01:07:46 -0800155
Alex Perry5fb5ff22019-02-09 21:53:17 -0800156 PotAndAbsConstants elevator;
157 PotAndAbsConstants wrist;
Theo Bafrali00e42272019-02-12 01:07:46 -0800158 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
159 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
160 intake;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800161
Theo Bafrali00e42272019-02-12 01:07:46 -0800162 PotAndAbsConstants stilts;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800163};
164
165// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
166// returns a reference to it.
167const Values &GetValues();
168
169// Creates Values instances for each team number it is called with and returns
170// them.
171const Values &GetValuesForTeam(uint16_t team_number);
172
173} // namespace constants
174} // namespace y2019
175
176#endif // Y2019_CONSTANTS_H_