blob: c70b0ea31212bf9b9a87a72069732a18a397725f [file] [log] [blame]
Tyler Chatow6107aba2017-01-22 01:39:40 +00001#ifndef Y2017_CONSTANTS_H_
2#define Y2017_CONSTANTS_H_
3
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cmath>
5#include <cstdint>
Ed Jordan8683f432017-02-12 00:13:26 +00006
7#include "frc971/constants.h"
Philipp Schrader9a833362017-04-09 22:56:16 +00008#include "frc971/shooter_interpolation/interpolation.h"
Brian Silverman052e69d2017-02-12 16:19:55 -08009#include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Austin Schuhd5ccb862017-03-11 22:06:36 -080010#include "y2017/control_loops/superstructure/column/column_plant.h"
Brian Silverman052e69d2017-02-12 16:19:55 -080011#include "y2017/control_loops/superstructure/hood/hood_plant.h"
Austin Schuhd5ccb862017-03-11 22:06:36 -080012#include "y2017/control_loops/superstructure/intake/intake_plant.h"
13#include "y2017/control_loops/superstructure/shooter/shooter_plant.h"
Brian Silverman052e69d2017-02-12 16:19:55 -080014
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080015namespace y2017::constants {
Tyler Chatow6107aba2017-01-22 01:39:40 +000016
Brian Silvermandb8498a2017-02-11 17:16:09 -080017// 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.
Tyler Chatow6107aba2017-01-22 01:39:40 +000020
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).
Brian Silvermandb8498a2017-02-11 17:16:09 -080024//
25// All ratios are from the encoder shaft to the output units.
Tyler Chatow6107aba2017-01-22 01:39:40 +000026
Tyler Chatow6107aba2017-01-22 01:39:40 +000027struct Values {
Ed Jordan8683f432017-02-12 00:13:26 +000028 struct Intake {
29 double pot_offset;
Adam Snaider79900c22017-02-08 20:23:15 -080030 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000031 };
Ed Jordan8683f432017-02-12 00:13:26 +000032
Ed Jordan8683f432017-02-12 00:13:26 +000033 struct Hood {
34 double pot_offset;
Austin Schuh6a90cd92017-02-19 20:55:33 -080035 ::frc971::constants::EncoderPlusIndexZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000036 };
Brian Silvermandb8498a2017-02-11 17:16:09 -080037
Austin Schuh55934032017-03-11 12:45:27 -080038 struct Column {
39 ::frc971::constants::HallEffectZeroingConstants indexer_zeroing;
40 ::frc971::constants::HallEffectZeroingConstants turret_zeroing;
Austin Schuhd5ccb862017-03-11 22:06:36 -080041 // The max absolute value of the turret angle that we need to get to to be
42 // classified as zeroed. Otherwise, we may be ambiguous on which wrap we
43 // are on.
44 double turret_zeroed_distance;
Austin Schuh55934032017-03-11 12:45:27 -080045 };
46
Brian Silvermandb8498a2017-02-11 17:16:09 -080047 static const int kZeroingSampleSize = 200;
48
Brian Silverman052e69d2017-02-12 16:19:55 -080049 static constexpr double kDrivetrainCyclesPerRevolution = 256;
50 static constexpr double kDrivetrainEncoderCountsPerRevolution =
51 kDrivetrainCyclesPerRevolution * 4;
52 static constexpr double kDrivetrainEncoderRatio =
53 1.0 * control_loops::drivetrain::kWheelRadius;
54 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
55 control_loops::drivetrain::kFreeSpeed *
56 control_loops::drivetrain::kHighOutputRatio /
57 constants::Values::kDrivetrainEncoderRatio *
58 kDrivetrainEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080059
Brian Silverman052e69d2017-02-12 16:19:55 -080060 static constexpr double kShooterEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080061 static constexpr double kShooterEncoderRatio = 32.0 / 48.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080062 static constexpr double kMaxShooterEncoderPulsesPerSecond =
63 control_loops::superstructure::shooter::kFreeSpeed *
64 control_loops::superstructure::shooter::kOutputRatio /
65 constants::Values::kShooterEncoderRatio *
66 kShooterEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080067
Brian Silverman052e69d2017-02-12 16:19:55 -080068 static constexpr double kIntakeEncoderCountsPerRevolution = 1024 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080069 static constexpr double kIntakeEncoderRatio =
70 (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254;
71 static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254;
72 static constexpr double kIntakeEncoderIndexDifference =
73 2.0 * M_PI * kIntakeEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080074 static constexpr double kMaxIntakeEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080075 control_loops::superstructure::intake::kFreeSpeed *
76 control_loops::superstructure::intake::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080077 constants::Values::kIntakeEncoderRatio *
78 kIntakeEncoderCountsPerRevolution;
Austin Schuh53a2c452017-03-22 21:18:20 -070079 static constexpr ::frc971::constants::Range kIntakeRange{-0.01, 0.250, 0.01,
80 0.235};
Brian Silvermandb8498a2017-02-11 17:16:09 -080081
Brian Silverman052e69d2017-02-12 16:19:55 -080082 static constexpr double kHoodEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080083 static constexpr double kHoodEncoderRatio = 20.0 / 345.0;
Brian Silvermandb8498a2017-02-11 17:16:09 -080084 static constexpr double kHoodEncoderIndexDifference =
85 2.0 * M_PI * kHoodEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080086 static constexpr double kMaxHoodEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080087 control_loops::superstructure::hood::kFreeSpeed *
88 control_loops::superstructure::hood::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080089 constants::Values::kHoodEncoderRatio * kHoodEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080090 static constexpr ::frc971::constants::Range kHoodRange{
Tyler Chatowbf0609c2021-07-31 16:13:27 -070091 -0.39 * M_PI / 180.0 - 0.01, 37.11 * M_PI / 180.0,
92 (-0.39 + 1.0) * M_PI / 180.0, (37.11 - 1.0) * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -080093
Brianef030df2017-03-05 15:06:04 -080094 static constexpr double kTurretEncoderCountsPerRevolution = 256 * 4;
95 static constexpr double kTurretEncoderRatio = 11.0 / 94.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080096 static constexpr double kMaxTurretEncoderPulsesPerSecond =
Austin Schuhd5ccb862017-03-11 22:06:36 -080097 control_loops::superstructure::column::kTurretFreeSpeed *
98 control_loops::superstructure::column::kTurretOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080099 constants::Values::kTurretEncoderRatio *
100 kTurretEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800101
Brianef030df2017-03-05 15:06:04 -0800102 static constexpr double kIndexerEncoderCountsPerRevolution = 256 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800103 static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0);
104 static constexpr double kIndexerEncoderIndexDifference =
105 2.0 * M_PI * kIndexerEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -0800106 static constexpr double kMaxIndexerEncoderPulsesPerSecond =
Austin Schuhd5ccb862017-03-11 22:06:36 -0800107 control_loops::superstructure::column::kIndexerFreeSpeed *
108 control_loops::superstructure::column::kIndexerOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -0800109 constants::Values::kIndexerEncoderRatio *
Brianef030df2017-03-05 15:06:04 -0800110 kIndexerEncoderCountsPerRevolution;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800111 static constexpr ::frc971::constants::Range kTurretRange{
112 -460.0 / 2.0 * M_PI / 180.0, 460.0 / 2.0 * M_PI / 180.0,
113 -450.0 / 2.0 * M_PI / 180.0, 450.0 / 2.0 * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -0800114
115 double drivetrain_max_speed;
116
117 Intake intake;
118
Austin Schuh55934032017-03-11 12:45:27 -0800119 Column column;
120
Ed Jordan8683f432017-02-12 00:13:26 +0000121 Hood hood;
122
Diana Vandenberg223703d2017-01-28 17:39:53 -0800123 double down_error;
Ed Jordan8683f432017-02-12 00:13:26 +0000124 const char *vision_name;
Austin Schuh25db1262017-04-05 19:39:55 -0700125
126 double vision_error;
Philipp Schrader9a833362017-04-09 22:56:16 +0000127
Parker Schuh94d56792017-04-13 20:32:50 -0700128 struct ShotParams {
129 double angle;
130 double power;
131 double indexer_velocity;
132
133 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2);
134 };
Tyler Chatow6107aba2017-01-22 01:39:40 +0000135};
136
137// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
138// returns a reference to it.
139const Values &GetValues();
140
141// Creates Values instances for each team number it is called with and returns
142// them.
143const Values &GetValuesForTeam(uint16_t team_number);
144
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -0800145} // namespace y2017::constants
Tyler Chatow6107aba2017-01-22 01:39:40 +0000146
147#endif // Y2017_CONSTANTS_H_