blob: bf25990abcaf4bbc472bd1d70befbccabfaacefe [file] [log] [blame]
Tyler Chatow6107aba2017-01-22 01:39:40 +00001#ifndef Y2017_CONSTANTS_H_
2#define Y2017_CONSTANTS_H_
3
4#include <stdint.h>
Ed Jordan8683f432017-02-12 00:13:26 +00005#include <math.h>
6
7#include "frc971/constants.h"
Philipp Schrader9a833362017-04-09 22:56:16 +00008#include "frc971/shooter_interpolation/interpolation.h"
Tyler Chatow6107aba2017-01-22 01:39:40 +00009
Brian Silverman052e69d2017-02-12 16:19:55 -080010#include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Austin Schuhd5ccb862017-03-11 22:06:36 -080011#include "y2017/control_loops/superstructure/column/column_plant.h"
Brian Silverman052e69d2017-02-12 16:19:55 -080012#include "y2017/control_loops/superstructure/hood/hood_plant.h"
Austin Schuhd5ccb862017-03-11 22:06:36 -080013#include "y2017/control_loops/superstructure/intake/intake_plant.h"
14#include "y2017/control_loops/superstructure/shooter/shooter_plant.h"
Brian Silverman052e69d2017-02-12 16:19:55 -080015
Tyler Chatow6107aba2017-01-22 01:39:40 +000016namespace y2017 {
17namespace constants {
18
Brian Silvermandb8498a2017-02-11 17:16:09 -080019// Has all of our "constants", except the ones that come from other places. The
20// ones which change between robots are put together with a workable way to
21// retrieve the values for the current robot.
Tyler Chatow6107aba2017-01-22 01:39:40 +000022
23// Everything is in SI units (volts, radians, meters, seconds, etc).
24// Some of these values are related to the conversion between raw values
25// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
Brian Silvermandb8498a2017-02-11 17:16:09 -080026//
27// All ratios are from the encoder shaft to the output units.
Tyler Chatow6107aba2017-01-22 01:39:40 +000028
Tyler Chatow6107aba2017-01-22 01:39:40 +000029struct Values {
Ed Jordan8683f432017-02-12 00:13:26 +000030 struct Intake {
31 double pot_offset;
Adam Snaider79900c22017-02-08 20:23:15 -080032 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000033 };
Ed Jordan8683f432017-02-12 00:13:26 +000034
Ed Jordan8683f432017-02-12 00:13:26 +000035 struct Hood {
36 double pot_offset;
Austin Schuh6a90cd92017-02-19 20:55:33 -080037 ::frc971::constants::EncoderPlusIndexZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000038 };
Brian Silvermandb8498a2017-02-11 17:16:09 -080039
Austin Schuh55934032017-03-11 12:45:27 -080040 struct Column {
41 ::frc971::constants::HallEffectZeroingConstants indexer_zeroing;
42 ::frc971::constants::HallEffectZeroingConstants turret_zeroing;
Austin Schuhd5ccb862017-03-11 22:06:36 -080043 // The max absolute value of the turret angle that we need to get to to be
44 // classified as zeroed. Otherwise, we may be ambiguous on which wrap we
45 // are on.
46 double turret_zeroed_distance;
Austin Schuh55934032017-03-11 12:45:27 -080047 };
48
Brian Silvermandb8498a2017-02-11 17:16:09 -080049 static const int kZeroingSampleSize = 200;
50
Brian Silverman052e69d2017-02-12 16:19:55 -080051 static constexpr double kDrivetrainCyclesPerRevolution = 256;
52 static constexpr double kDrivetrainEncoderCountsPerRevolution =
53 kDrivetrainCyclesPerRevolution * 4;
54 static constexpr double kDrivetrainEncoderRatio =
55 1.0 * control_loops::drivetrain::kWheelRadius;
56 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
57 control_loops::drivetrain::kFreeSpeed *
58 control_loops::drivetrain::kHighOutputRatio /
59 constants::Values::kDrivetrainEncoderRatio *
60 kDrivetrainEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080061
Brian Silverman052e69d2017-02-12 16:19:55 -080062 static constexpr double kShooterEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080063 static constexpr double kShooterEncoderRatio = 32.0 / 48.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080064 static constexpr double kMaxShooterEncoderPulsesPerSecond =
65 control_loops::superstructure::shooter::kFreeSpeed *
66 control_loops::superstructure::shooter::kOutputRatio /
67 constants::Values::kShooterEncoderRatio *
68 kShooterEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080069
Brian Silverman052e69d2017-02-12 16:19:55 -080070 static constexpr double kIntakeEncoderCountsPerRevolution = 1024 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080071 static constexpr double kIntakeEncoderRatio =
72 (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254;
73 static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254;
74 static constexpr double kIntakeEncoderIndexDifference =
75 2.0 * M_PI * kIntakeEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080076 static constexpr double kMaxIntakeEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080077 control_loops::superstructure::intake::kFreeSpeed *
78 control_loops::superstructure::intake::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080079 constants::Values::kIntakeEncoderRatio *
80 kIntakeEncoderCountsPerRevolution;
Austin Schuh53a2c452017-03-22 21:18:20 -070081 static constexpr ::frc971::constants::Range kIntakeRange{-0.01, 0.250, 0.01,
82 0.235};
Brian Silvermandb8498a2017-02-11 17:16:09 -080083
Brian Silverman052e69d2017-02-12 16:19:55 -080084 static constexpr double kHoodEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080085 static constexpr double kHoodEncoderRatio = 20.0 / 345.0;
Brian Silvermandb8498a2017-02-11 17:16:09 -080086 static constexpr double kHoodEncoderIndexDifference =
87 2.0 * M_PI * kHoodEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080088 static constexpr double kMaxHoodEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080089 control_loops::superstructure::hood::kFreeSpeed *
90 control_loops::superstructure::hood::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080091 constants::Values::kHoodEncoderRatio * kHoodEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080092 static constexpr ::frc971::constants::Range kHoodRange{
Austin Schuh53a2c452017-03-22 21:18:20 -070093 -0.39 * M_PI / 180.0 - 0.01, 37.11 * M_PI / 180.0, (-0.39 + 1.0) * M_PI / 180.0,
Adam Snaider79900c22017-02-08 20:23:15 -080094 (37.11 - 1.0) * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -080095
Brianef030df2017-03-05 15:06:04 -080096 static constexpr double kTurretEncoderCountsPerRevolution = 256 * 4;
97 static constexpr double kTurretEncoderRatio = 11.0 / 94.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080098 static constexpr double kMaxTurretEncoderPulsesPerSecond =
Austin Schuhd5ccb862017-03-11 22:06:36 -080099 control_loops::superstructure::column::kTurretFreeSpeed *
100 control_loops::superstructure::column::kTurretOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -0800101 constants::Values::kTurretEncoderRatio *
102 kTurretEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800103
Brianef030df2017-03-05 15:06:04 -0800104 static constexpr double kIndexerEncoderCountsPerRevolution = 256 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800105 static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0);
106 static constexpr double kIndexerEncoderIndexDifference =
107 2.0 * M_PI * kIndexerEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -0800108 static constexpr double kMaxIndexerEncoderPulsesPerSecond =
Austin Schuhd5ccb862017-03-11 22:06:36 -0800109 control_loops::superstructure::column::kIndexerFreeSpeed *
110 control_loops::superstructure::column::kIndexerOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -0800111 constants::Values::kIndexerEncoderRatio *
Brianef030df2017-03-05 15:06:04 -0800112 kIndexerEncoderCountsPerRevolution;
Austin Schuhd5ccb862017-03-11 22:06:36 -0800113 static constexpr ::frc971::constants::Range kTurretRange{
114 -460.0 / 2.0 * M_PI / 180.0, 460.0 / 2.0 * M_PI / 180.0,
115 -450.0 / 2.0 * M_PI / 180.0, 450.0 / 2.0 * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -0800116
117 double drivetrain_max_speed;
118
119 Intake intake;
120
Austin Schuh55934032017-03-11 12:45:27 -0800121 Column column;
122
Ed Jordan8683f432017-02-12 00:13:26 +0000123 Hood hood;
124
Diana Vandenberg223703d2017-01-28 17:39:53 -0800125 double down_error;
Ed Jordan8683f432017-02-12 00:13:26 +0000126 const char *vision_name;
Austin Schuh25db1262017-04-05 19:39:55 -0700127
128 double vision_error;
Philipp Schrader9a833362017-04-09 22:56:16 +0000129
Parker Schuh94d56792017-04-13 20:32:50 -0700130 struct ShotParams {
131 double angle;
132 double power;
133 double indexer_velocity;
134
135 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2);
136 };
137
138 ::frc971::shooter_interpolation::InterpolationTable<ShotParams> shot_interpolation_table;
Tyler Chatow6107aba2017-01-22 01:39:40 +0000139};
140
141// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
142// returns a reference to it.
143const Values &GetValues();
144
145// Creates Values instances for each team number it is called with and returns
146// them.
147const Values &GetValuesForTeam(uint16_t team_number);
148
149} // namespace constants
150} // namespace y2017
151
152#endif // Y2017_CONSTANTS_H_