blob: a36e4b3a531d6c49a504b1355071f9f118d35c22 [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 Chatowbf0609c2021-07-31 16:13:27 -07005#include <cmath>
6#include <cstdint>
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"
Tyler Chatowbf0609c2021-07-31 16:13:27 -070010#include "frc971/control_loops/pose.h"
Theo Bafrali00e42272019-02-12 01:07:46 -080011#include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
James Kuszmaulec635d22023-08-12 18:39:24 -070012#include "frc971/zeroing/absolute_encoder.h"
13#include "frc971/zeroing/pot_and_absolute_encoder.h"
Sabina Davis7be49f32019-02-02 00:30:19 -080014#include "y2019/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080015#include "y2019/control_loops/superstructure/elevator/elevator_plant.h"
Theo Bafrali00e42272019-02-12 01:07:46 -080016#include "y2019/control_loops/superstructure/intake/intake_plant.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080017#include "y2019/control_loops/superstructure/stilts/stilts_plant.h"
18#include "y2019/control_loops/superstructure/wrist/wrist_plant.h"
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080019
20namespace y2019 {
21namespace constants {
22
23// Has all of our "constants", except the ones that come from other places. The
24// ones which change between robots are put together with a workable way to
25// retrieve the values for the current robot.
26
27// Everything is in SI units (volts, radians, meters, seconds, etc).
28// Some of these values are related to the conversion between raw values
29// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
30//
31// All ratios are from the encoder shaft to the output units.
32
James Kuszmaul22c5ab32019-02-09 14:45:58 -080033class Field {
34 public:
35 typedef ::frc971::control_loops::TypedPose<double> Pose;
James Kuszmaulf4ede202020-02-14 08:47:40 -080036 typedef ::frc971::control_loops::TypedTarget<double> Target;
James Kuszmaul22c5ab32019-02-09 14:45:58 -080037 typedef ::frc971::control_loops::TypedLineSegment<double> Obstacle;
38
39 static constexpr size_t kNumTargets = 32;
40 static constexpr size_t kNumObstacles = 10;
41
42 Field();
43
44 ::std::array<Target, kNumTargets> targets() const { return targets_; }
45 ::std::array<Obstacle, kNumObstacles> obstacles() const { return obstacles_; }
46
47 private:
48 // All target locations are defined as being at the center of the target,
49 // except for the height, for which we use the top of the target.
50 ::std::array<Target, kNumTargets> targets_;
51 // Obstacle locations are approximate, as we are just trying to roughly
52 // approximate what will block our view when on the field.
53 // If anything, we should err on the side of making obstacles too small so
54 // that if there is any error in our position, we don't assume that it must
55 // be hidden behind a target when it really is not.
56 ::std::array<Obstacle, kNumObstacles> obstacles_;
57};
58
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080059struct Values {
60 static const int kZeroingSampleSize = 200;
Sabina Davis7be49f32019-02-02 00:30:19 -080061
Theo Bafrali00e42272019-02-12 01:07:46 -080062 // Drivetrain Constants
Sabina Davis7be49f32019-02-02 00:30:19 -080063 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
64 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
65 return kDrivetrainCyclesPerRevolution() * 4;
66 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080067 static constexpr double kDrivetrainEncoderRatio() { return (24.0 / 52.0); }
Sabina Davis7be49f32019-02-02 00:30:19 -080068 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
69 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
70 control_loops::drivetrain::kHighOutputRatio /
71 constants::Values::kDrivetrainEncoderRatio() *
72 kDrivetrainEncoderCountsPerRevolution();
73 }
Alex Perry5fb5ff22019-02-09 21:53:17 -080074
75 // Elevator
76 static constexpr double kElevatorEncoderCountsPerRevolution() {
77 return 4096.0;
78 }
79
80 static constexpr double kElevatorEncoderRatio() {
81 return (1.0) * control_loops::superstructure::elevator::kRadius;
82 }
83
84 static constexpr double kMaxElevatorEncoderPulsesPerSecond() {
85 return control_loops::superstructure::elevator::kFreeSpeed *
86 control_loops::superstructure::elevator::kOutputRatio /
87 kElevatorEncoderRatio() / (2.0 * M_PI) *
88 kElevatorEncoderCountsPerRevolution();
89 }
90
91 static constexpr double kElevatorPotRatio() {
92 return (1.0) * control_loops::superstructure::elevator::kRadius;
93 }
94
Austin Schuh7c473cb2019-02-10 14:49:19 -080095 static constexpr ::frc971::constants::Range kElevatorRange() {
96 return ::frc971::constants::Range{
Austin Schuhdc9050b2019-02-22 20:45:12 -080097 -0.02, // Bottom Hard
Austin Schuhed7f8632019-02-15 23:12:20 -080098 1.62, // Top Hard
99 0.01, // Bottom Soft
100 1.59 // Top Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800101 };
102 }
103
Alex Perry5fb5ff22019-02-09 21:53:17 -0800104 // Intake
105 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
106
107 static constexpr double kIntakeEncoderRatio() { return (18.0 / 38.0); }
108
109 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
110 return control_loops::superstructure::intake::kFreeSpeed *
111 control_loops::superstructure::intake::kOutputRatio /
112 kIntakeEncoderRatio() / (2.0 * M_PI) *
113 kIntakeEncoderCountsPerRevolution();
114 }
115
Austin Schuh7c473cb2019-02-10 14:49:19 -0800116 static constexpr ::frc971::constants::Range kIntakeRange() {
117 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -0800118 -1.30, // Back Hard
119 1.35, // Front Hard
120 -1.25, // Back Soft
121 1.30 // Front Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800122 };
123 }
124
Alex Perry5fb5ff22019-02-09 21:53:17 -0800125 // Wrist
126 static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; }
127
128 static constexpr double kWristEncoderRatio() {
129 return (20.0 / 100.0) * (24.0 / 84.0);
130 }
131
132 static constexpr double kMaxWristEncoderPulsesPerSecond() {
133 return control_loops::superstructure::wrist::kFreeSpeed *
134 control_loops::superstructure::wrist::kOutputRatio /
135 kWristEncoderRatio() / (2.0 * M_PI) *
136 kWristEncoderCountsPerRevolution();
137 }
138
139 static constexpr double kWristPotRatio() { return (24.0) / (84.0); }
140
Austin Schuh7c473cb2019-02-10 14:49:19 -0800141 static constexpr ::frc971::constants::Range kWristRange() {
142 return ::frc971::constants::Range{
143 -3.14, // Back Hard
Austin Schuhed7f8632019-02-15 23:12:20 -0800144 3.14, // Front Hard
Austin Schuh7c473cb2019-02-10 14:49:19 -0800145 -2.97, // Back Soft
146 2.41 // Front Soft
147 };
148 }
149
Alex Perry5fb5ff22019-02-09 21:53:17 -0800150 // Stilts
151 static constexpr double kStiltsEncoderCountsPerRevolution() { return 4096.0; }
152
Theo Bafrali00e42272019-02-12 01:07:46 -0800153 // Stilts Constants
Alex Perry5fb5ff22019-02-09 21:53:17 -0800154 static constexpr double kStiltsEncoderRatio() {
155 return (1.0 /* Gear ratio */) *
156 control_loops::superstructure::stilts::kRadius;
157 }
158
159 static constexpr double kMaxStiltsEncoderPulsesPerSecond() {
160 return control_loops::superstructure::stilts::kFreeSpeed *
161 control_loops::superstructure::stilts::kOutputRatio /
162 kStiltsEncoderRatio() / (2.0 * M_PI) *
163 kStiltsEncoderCountsPerRevolution();
164 }
165
166 static constexpr double kStiltsPotRatio() {
167 return (1.0 /* Gear ratio */) *
168 control_loops::superstructure::stilts::kRadius;
169 }
170
Austin Schuh7c473cb2019-02-10 14:49:19 -0800171 static constexpr ::frc971::constants::Range kStiltsRange() {
172 return ::frc971::constants::Range{
Austin Schuhed7f8632019-02-15 23:12:20 -0800173 -0.01, // Top Hard
174 0.72, // Bottom Hard
175 0.00, // Top Soft
176 0.71 // Bottom Soft
Austin Schuh7c473cb2019-02-10 14:49:19 -0800177 };
178 }
179
Alex Perry5fb5ff22019-02-09 21:53:17 -0800180 struct PotAndAbsConstants {
Theo Bafrali00e42272019-02-12 01:07:46 -0800181 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
182 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
183 subsystem_params;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800184 double potentiometer_offset;
185 };
Theo Bafrali00e42272019-02-12 01:07:46 -0800186
Alex Perry5fb5ff22019-02-09 21:53:17 -0800187 PotAndAbsConstants elevator;
188 PotAndAbsConstants wrist;
Theo Bafrali00e42272019-02-12 01:07:46 -0800189 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
190 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
191 intake;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800192
Theo Bafrali00e42272019-02-12 01:07:46 -0800193 PotAndAbsConstants stilts;
James Kuszmaul09f564a2019-02-18 17:37:09 -0800194
195 struct CameraCalibration {
James Kuszmaul09f564a2019-02-18 17:37:09 -0800196 // Pose of the camera relative to the robot.
197 ::frc971::control_loops::TypedPose<double> pose;
198 // Field of view, in radians. This is total horizontal FOV, from left
199 // edge to right edge of the camera image.
200 double fov;
201 };
202
203 static constexpr size_t kNumCameras = 5;
204 ::std::array<CameraCalibration, kNumCameras> cameras;
James Kuszmaulf4ede202020-02-14 08:47:40 -0800205 frc971::control_loops::TypedCamera<Field::kNumTargets, Field::kNumObstacles,
206 double>::NoiseParameters
207 camera_noise_parameters;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800208};
209
210// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
211// returns a reference to it.
212const Values &GetValues();
213
214// Creates Values instances for each team number it is called with and returns
215// them.
216const Values &GetValuesForTeam(uint16_t team_number);
217
218} // namespace constants
219} // namespace y2019
220
221#endif // Y2019_CONSTANTS_H_