blob: d1d0c7cddc68b9b5c39266a83f83553ef63ae96c [file] [log] [blame]
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08001#ifndef Y2019_CONSTANTS_H_
2#define Y2019_CONSTANTS_H_
3
James Kuszmaul22c5ab32019-02-09 14:45:58 -08004#include <array>
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08005#include <math.h>
Sabina Davis1b84afa2019-02-09 01:20:21 -08006#include <stdint.h>
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08007
8#include "frc971/constants.h"
James Kuszmaulf4ede202020-02-14 08:47:40 -08009#include "frc971/control_loops/drivetrain/camera.h"
Theo Bafrali00e42272019-02-12 01:07:46 -080010#include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
Sabina Davis7be49f32019-02-02 00:30:19 -080011#include "y2019/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080012#include "y2019/control_loops/superstructure/elevator/elevator_plant.h"
Theo Bafrali00e42272019-02-12 01:07:46 -080013#include "y2019/control_loops/superstructure/intake/intake_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080014#include "y2019/control_loops/superstructure/stilts/stilts_plant.h"
15#include "y2019/control_loops/superstructure/wrist/wrist_plant.h"
James Kuszmaul22c5ab32019-02-09 14:45:58 -080016#include "frc971/control_loops/pose.h"
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080017
18namespace y2019 {
19namespace constants {
20
21// Has all of our "constants", except the ones that come from other places. The
22// ones which change between robots are put together with a workable way to
23// retrieve the values for the current robot.
24
25// Everything is in SI units (volts, radians, meters, seconds, etc).
26// Some of these values are related to the conversion between raw values
27// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
28//
29// All ratios are from the encoder shaft to the output units.
30
James Kuszmaul22c5ab32019-02-09 14:45:58 -080031
32class Field {
33 public:
34 typedef ::frc971::control_loops::TypedPose<double> Pose;
James Kuszmaulf4ede202020-02-14 08:47:40 -080035 typedef ::frc971::control_loops::TypedTarget<double> Target;
James Kuszmaul22c5ab32019-02-09 14:45:58 -080036 typedef ::frc971::control_loops::TypedLineSegment<double> Obstacle;
37
38 static constexpr size_t kNumTargets = 32;
39 static constexpr size_t kNumObstacles = 10;
40
41 Field();
42
43 ::std::array<Target, kNumTargets> targets() const { return targets_; }
44 ::std::array<Obstacle, kNumObstacles> obstacles() const { return obstacles_; }
45
46 private:
47 // All target locations are defined as being at the center of the target,
48 // except for the height, for which we use the top of the target.
49 ::std::array<Target, kNumTargets> targets_;
50 // Obstacle locations are approximate, as we are just trying to roughly
51 // approximate what will block our view when on the field.
52 // If anything, we should err on the side of making obstacles too small so
53 // that if there is any error in our position, we don't assume that it must
54 // be hidden behind a target when it really is not.
55 ::std::array<Obstacle, kNumObstacles> obstacles_;
56};
57
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080058struct Values {
59 static const int kZeroingSampleSize = 200;
Sabina Davis7be49f32019-02-02 00:30:19 -080060
Theo Bafrali00e42272019-02-12 01:07:46 -080061 // Drivetrain Constants
Sabina Davis7be49f32019-02-02 00:30:19 -080062 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
63 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
64 return kDrivetrainCyclesPerRevolution() * 4;
65 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080066 static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); }
Sabina Davis7be49f32019-02-02 00:30:19 -080067 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
68 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
69 control_loops::drivetrain::kHighOutputRatio /
70 constants::Values::kDrivetrainEncoderRatio() *
71 kDrivetrainEncoderCountsPerRevolution();
72 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080073
74 // Elevator
75 static constexpr double kElevatorEncoderCountsPerRevolution() {
76 return 4096.0;
77 }
78
79 static constexpr double kElevatorEncoderRatio() {
80 return (1.0) * control_loops::superstructure::elevator::kRadius;
81 }
82
83 static constexpr double kMaxElevatorEncoderPulsesPerSecond() {
84 return control_loops::superstructure::elevator::kFreeSpeed *
85 control_loops::superstructure::elevator::kOutputRatio /
86 kElevatorEncoderRatio() / (2.0 * M_PI) *
87 kElevatorEncoderCountsPerRevolution();
88 }
89
90 static constexpr double kElevatorPotRatio() {
91 return (1.0) * control_loops::superstructure::elevator::kRadius;
92 }
93
Austin Schuh7c473cb2019-02-10 14:49:19 -080094 static constexpr ::frc971::constants::Range kElevatorRange() {
95 return ::frc971::constants::Range{
Austin Schuhdc9050b2019-02-22 20:45:12 -080096 -0.02, // Bottom Hard
Austin Schuhed7f8632019-02-15 23:12:20 -080097 1.62, // Top Hard
98 0.01, // Bottom Soft
99 1.59 // Top Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800100 };
101 }
102
Alex Perry5fb5ff22019-02-09 21:53:17 -0800103 // Intake
104 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
105
106 static constexpr double kIntakeEncoderRatio() { return (18.0 / 38.0); }
107
108 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
109 return control_loops::superstructure::intake::kFreeSpeed *
110 control_loops::superstructure::intake::kOutputRatio /
111 kIntakeEncoderRatio() / (2.0 * M_PI) *
112 kIntakeEncoderCountsPerRevolution();
113 }
114
Austin Schuh7c473cb2019-02-10 14:49:19 -0800115 static constexpr ::frc971::constants::Range kIntakeRange() {
116 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -0800117 -1.30, // Back Hard
118 1.35, // Front Hard
119 -1.25, // Back Soft
120 1.30 // Front Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800121 };
122 }
123
Alex Perry5fb5ff22019-02-09 21:53:17 -0800124 // Wrist
125 static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; }
126
127 static constexpr double kWristEncoderRatio() {
128 return (20.0 / 100.0) * (24.0 / 84.0);
129 }
130
131 static constexpr double kMaxWristEncoderPulsesPerSecond() {
132 return control_loops::superstructure::wrist::kFreeSpeed *
133 control_loops::superstructure::wrist::kOutputRatio /
134 kWristEncoderRatio() / (2.0 * M_PI) *
135 kWristEncoderCountsPerRevolution();
136 }
137
138 static constexpr double kWristPotRatio() { return (24.0) / (84.0); }
139
Austin Schuh7c473cb2019-02-10 14:49:19 -0800140 static constexpr ::frc971::constants::Range kWristRange() {
141 return ::frc971::constants::Range{
142 -3.14, // Back Hard
Austin Schuhed7f8632019-02-15 23:12:20 -0800143 3.14, // Front Hard
Austin Schuh7c473cb2019-02-10 14:49:19 -0800144 -2.97, // Back Soft
145 2.41 // Front Soft
146 };
147 }
148
Alex Perry5fb5ff22019-02-09 21:53:17 -0800149 // Stilts
150 static constexpr double kStiltsEncoderCountsPerRevolution() { return 4096.0; }
151
Theo Bafrali00e42272019-02-12 01:07:46 -0800152 // Stilts Constants
Alex Perry5fb5ff22019-02-09 21:53:17 -0800153 static constexpr double kStiltsEncoderRatio() {
154 return (1.0 /* Gear ratio */) *
155 control_loops::superstructure::stilts::kRadius;
156 }
157
158 static constexpr double kMaxStiltsEncoderPulsesPerSecond() {
159 return control_loops::superstructure::stilts::kFreeSpeed *
160 control_loops::superstructure::stilts::kOutputRatio /
161 kStiltsEncoderRatio() / (2.0 * M_PI) *
162 kStiltsEncoderCountsPerRevolution();
163 }
164
165 static constexpr double kStiltsPotRatio() {
166 return (1.0 /* Gear ratio */) *
167 control_loops::superstructure::stilts::kRadius;
168 }
169
Austin Schuh7c473cb2019-02-10 14:49:19 -0800170 static constexpr ::frc971::constants::Range kStiltsRange() {
171 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -0800172 -0.01, // Top Hard
173 0.72, // Bottom Hard
174 0.00, // Top Soft
175 0.71 // Bottom Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800176 };
177 }
178
Alex Perry5fb5ff22019-02-09 21:53:17 -0800179 struct PotAndAbsConstants {
Theo Bafrali00e42272019-02-12 01:07:46 -0800180 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
181 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
182 subsystem_params;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800183 double potentiometer_offset;
184 };
Theo Bafrali00e42272019-02-12 01:07:46 -0800185
Alex Perry5fb5ff22019-02-09 21:53:17 -0800186 PotAndAbsConstants elevator;
187 PotAndAbsConstants wrist;
Theo Bafrali00e42272019-02-12 01:07:46 -0800188 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
189 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
190 intake;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800191
Theo Bafrali00e42272019-02-12 01:07:46 -0800192 PotAndAbsConstants stilts;
James Kuszmaul09f564a2019-02-18 17:37:09 -0800193
194 struct CameraCalibration {
James Kuszmaul09f564a2019-02-18 17:37:09 -0800195 // Pose of the camera relative to the robot.
196 ::frc971::control_loops::TypedPose<double> pose;
197 // Field of view, in radians. This is total horizontal FOV, from left
198 // edge to right edge of the camera image.
199 double fov;
200 };
201
202 static constexpr size_t kNumCameras = 5;
203 ::std::array<CameraCalibration, kNumCameras> cameras;
James Kuszmaulf4ede202020-02-14 08:47:40 -0800204 frc971::control_loops::TypedCamera<Field::kNumTargets, Field::kNumObstacles,
205 double>::NoiseParameters
206 camera_noise_parameters;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800207};
208
209// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
210// returns a reference to it.
211const Values &GetValues();
212
213// Creates Values instances for each team number it is called with and returns
214// them.
215const Values &GetValuesForTeam(uint16_t team_number);
216
217} // namespace constants
218} // namespace y2019
219
220#endif // Y2019_CONSTANTS_H_