blob: 9c0f3c2188f7076ced3b647b590bdde06c72e0d0 [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
Tyler Chatow6107aba2017-01-22 01:39:40 +000015namespace y2017 {
16namespace constants {
17
Brian Silvermandb8498a2017-02-11 17:16:09 -080018// 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.
Tyler Chatow6107aba2017-01-22 01:39:40 +000021
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).
Brian Silvermandb8498a2017-02-11 17:16:09 -080025//
26// All ratios are from the encoder shaft to the output units.
Tyler Chatow6107aba2017-01-22 01:39:40 +000027
Tyler Chatow6107aba2017-01-22 01:39:40 +000028struct Values {
Ed Jordan8683f432017-02-12 00:13:26 +000029 struct Intake {
30 double pot_offset;
Adam Snaider79900c22017-02-08 20:23:15 -080031 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000032 };
Ed Jordan8683f432017-02-12 00:13:26 +000033
Ed Jordan8683f432017-02-12 00:13:26 +000034 struct Hood {
35 double pot_offset;
Austin Schuh6a90cd92017-02-19 20:55:33 -080036 ::frc971::constants::EncoderPlusIndexZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000037 };
Brian Silvermandb8498a2017-02-11 17:16:09 -080038
Austin Schuh55934032017-03-11 12:45:27 -080039 struct Column {
40 ::frc971::constants::HallEffectZeroingConstants indexer_zeroing;
41 ::frc971::constants::HallEffectZeroingConstants turret_zeroing;
Austin Schuhd5ccb862017-03-11 22:06:36 -080042 // The max absolute value of the turret angle that we need to get to to be
43 // classified as zeroed. Otherwise, we may be ambiguous on which wrap we
44 // are on.
45 double turret_zeroed_distance;
Austin Schuh55934032017-03-11 12:45:27 -080046 };
47
Brian Silvermandb8498a2017-02-11 17:16:09 -080048 static const int kZeroingSampleSize = 200;
49
Brian Silverman052e69d2017-02-12 16:19:55 -080050 static constexpr double kDrivetrainCyclesPerRevolution = 256;
51 static constexpr double kDrivetrainEncoderCountsPerRevolution =
52 kDrivetrainCyclesPerRevolution * 4;
53 static constexpr double kDrivetrainEncoderRatio =
54 1.0 * control_loops::drivetrain::kWheelRadius;
55 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
56 control_loops::drivetrain::kFreeSpeed *
57 control_loops::drivetrain::kHighOutputRatio /
58 constants::Values::kDrivetrainEncoderRatio *
59 kDrivetrainEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080060
Brian Silverman052e69d2017-02-12 16:19:55 -080061 static constexpr double kShooterEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080062 static constexpr double kShooterEncoderRatio = 32.0 / 48.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080063 static constexpr double kMaxShooterEncoderPulsesPerSecond =
64 control_loops::superstructure::shooter::kFreeSpeed *
65 control_loops::superstructure::shooter::kOutputRatio /
66 constants::Values::kShooterEncoderRatio *
67 kShooterEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080068
Brian Silverman052e69d2017-02-12 16:19:55 -080069 static constexpr double kIntakeEncoderCountsPerRevolution = 1024 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080070 static constexpr double kIntakeEncoderRatio =
71 (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254;
72 static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254;
73 static constexpr double kIntakeEncoderIndexDifference =
74 2.0 * M_PI * kIntakeEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080075 static constexpr double kMaxIntakeEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080076 control_loops::superstructure::intake::kFreeSpeed *
77 control_loops::superstructure::intake::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080078 constants::Values::kIntakeEncoderRatio *
79 kIntakeEncoderCountsPerRevolution;
Austin Schuh53a2c452017-03-22 21:18:20 -070080 static constexpr ::frc971::constants::Range kIntakeRange{-0.01, 0.250, 0.01,
81 0.235};
Brian Silvermandb8498a2017-02-11 17:16:09 -080082
Brian Silverman052e69d2017-02-12 16:19:55 -080083 static constexpr double kHoodEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080084 static constexpr double kHoodEncoderRatio = 20.0 / 345.0;
Brian Silvermandb8498a2017-02-11 17:16:09 -080085 static constexpr double kHoodEncoderIndexDifference =
86 2.0 * M_PI * kHoodEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080087 static constexpr double kMaxHoodEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080088 control_loops::superstructure::hood::kFreeSpeed *
89 control_loops::superstructure::hood::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080090 constants::Values::kHoodEncoderRatio * kHoodEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080091 static constexpr ::frc971::constants::Range kHoodRange{
Tyler Chatowbf0609c2021-07-31 16:13:27 -070092 -0.39 * M_PI / 180.0 - 0.01, 37.11 * M_PI / 180.0,
93 (-0.39 + 1.0) * M_PI / 180.0, (37.11 - 1.0) * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -080094
Brianef030df2017-03-05 15:06:04 -080095 static constexpr double kTurretEncoderCountsPerRevolution = 256 * 4;
96 static constexpr double kTurretEncoderRatio = 11.0 / 94.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080097 static constexpr double kMaxTurretEncoderPulsesPerSecond =
Austin Schuhd5ccb862017-03-11 22:06:36 -080098 control_loops::superstructure::column::kTurretFreeSpeed *
99 control_loops::superstructure::column::kTurretOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -0800100 constants::Values::kTurretEncoderRatio *
101 kTurretEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800102
Brianef030df2017-03-05 15:06:04 -0800103 static constexpr double kIndexerEncoderCountsPerRevolution = 256 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800104 static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0);
105 static constexpr double kIndexerEncoderIndexDifference =
106 2.0 * M_PI * kIndexerEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -0800107 static constexpr double kMaxIndexerEncoderPulsesPerSecond =
Austin Schuhd5ccb862017-03-11 22:06:36 -0800108 control_loops::superstructure::column::kIndexerFreeSpeed *
109 control_loops::superstructure::column::kIndexerOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -0800110 constants::Values::kIndexerEncoderRatio *
Brianef030df2017-03-05 15:06:04 -0800111 kIndexerEncoderCountsPerRevolution;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800112 static constexpr ::frc971::constants::Range kTurretRange{
113 -460.0 / 2.0 * M_PI / 180.0, 460.0 / 2.0 * M_PI / 180.0,
114 -450.0 / 2.0 * M_PI / 180.0, 450.0 / 2.0 * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -0800115
116 double drivetrain_max_speed;
117
118 Intake intake;
119
Austin Schuh55934032017-03-11 12:45:27 -0800120 Column column;
121
Ed Jordan8683f432017-02-12 00:13:26 +0000122 Hood hood;
123
Diana Vandenberg223703d2017-01-28 17:39:53 -0800124 double down_error;
Ed Jordan8683f432017-02-12 00:13:26 +0000125 const char *vision_name;
Austin Schuh25db1262017-04-05 19:39:55 -0700126
127 double vision_error;
Philipp Schrader9a833362017-04-09 22:56:16 +0000128
Parker Schuh94d56792017-04-13 20:32:50 -0700129 struct ShotParams {
130 double angle;
131 double power;
132 double indexer_velocity;
133
134 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2);
135 };
Tyler Chatow6107aba2017-01-22 01:39:40 +0000136};
137
138// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
139// returns a reference to it.
140const Values &GetValues();
141
142// Creates Values instances for each team number it is called with and returns
143// them.
144const Values &GetValuesForTeam(uint16_t team_number);
145
146} // namespace constants
147} // namespace y2017
148
149#endif // Y2017_CONSTANTS_H_