blob: 49b7afa7b7f7fdd35028c464e3bdbc8863ba286a [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"
Tyler Chatow6107aba2017-01-22 01:39:40 +00008
Brian Silverman052e69d2017-02-12 16:19:55 -08009#include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
10#include "y2017/control_loops/superstructure/shooter/shooter_plant.h"
11#include "y2017/control_loops/superstructure/intake/intake_plant.h"
12#include "y2017/control_loops/superstructure/turret/turret_plant.h"
13#include "y2017/control_loops/superstructure/indexer/indexer_plant.h"
14#include "y2017/control_loops/superstructure/hood/hood_plant.h"
15
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
35 struct Turret {
36 double pot_offset;
Adam Snaider79900c22017-02-08 20:23:15 -080037 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000038 };
Ed Jordan8683f432017-02-12 00:13:26 +000039
40 struct Hood {
41 double pot_offset;
Austin Schuh6a90cd92017-02-19 20:55:33 -080042 ::frc971::constants::EncoderPlusIndexZeroingConstants zeroing;
Ed Jordan8683f432017-02-12 00:13:26 +000043 };
Brian Silvermandb8498a2017-02-11 17:16:09 -080044
45 static const int kZeroingSampleSize = 200;
46
Brian Silverman052e69d2017-02-12 16:19:55 -080047 static constexpr double kDrivetrainCyclesPerRevolution = 256;
48 static constexpr double kDrivetrainEncoderCountsPerRevolution =
49 kDrivetrainCyclesPerRevolution * 4;
50 static constexpr double kDrivetrainEncoderRatio =
51 1.0 * control_loops::drivetrain::kWheelRadius;
52 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
53 control_loops::drivetrain::kFreeSpeed *
54 control_loops::drivetrain::kHighOutputRatio /
55 constants::Values::kDrivetrainEncoderRatio *
56 kDrivetrainEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080057
Brian Silverman052e69d2017-02-12 16:19:55 -080058 static constexpr double kShooterEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080059 static constexpr double kShooterEncoderRatio = 32.0 / 48.0;
Brian Silverman052e69d2017-02-12 16:19:55 -080060 static constexpr double kMaxShooterEncoderPulsesPerSecond =
61 control_loops::superstructure::shooter::kFreeSpeed *
62 control_loops::superstructure::shooter::kOutputRatio /
63 constants::Values::kShooterEncoderRatio *
64 kShooterEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080065
Brian Silverman052e69d2017-02-12 16:19:55 -080066 static constexpr double kIntakeEncoderCountsPerRevolution = 1024 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080067 static constexpr double kIntakeEncoderRatio =
68 (16.0 * 0.25) * (20.0 / 40.0) / (2.0 * M_PI) * 0.0254;
69 static constexpr double kIntakePotRatio = (16 * 0.25) / (2.0 * M_PI) * 0.0254;
70 static constexpr double kIntakeEncoderIndexDifference =
71 2.0 * M_PI * kIntakeEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080072 static constexpr double kMaxIntakeEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080073 control_loops::superstructure::intake::kFreeSpeed *
74 control_loops::superstructure::intake::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080075 constants::Values::kIntakeEncoderRatio *
76 kIntakeEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080077 static constexpr ::frc971::constants::Range kIntakeRange{
Brian Silverman052e69d2017-02-12 16:19:55 -080078 -0.29878633 * 0.0254, 9.23012063 * 0.0254, (-0.29878633 + 0.125) * 0.0254,
79 (9.23012063 - 0.125) * 0.0254};
Brian Silvermandb8498a2017-02-11 17:16:09 -080080
Brian Silverman052e69d2017-02-12 16:19:55 -080081 static constexpr double kHoodEncoderCountsPerRevolution = 2048 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080082 static constexpr double kHoodEncoderRatio = 20.0 / 345.0;
Brian Silvermandb8498a2017-02-11 17:16:09 -080083 static constexpr double kHoodEncoderIndexDifference =
84 2.0 * M_PI * kHoodEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080085 static constexpr double kMaxHoodEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080086 control_loops::superstructure::hood::kFreeSpeed *
87 control_loops::superstructure::hood::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -080088 constants::Values::kHoodEncoderRatio * kHoodEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -080089 static constexpr ::frc971::constants::Range kHoodRange{
Adam Snaider79900c22017-02-08 20:23:15 -080090 -0.39 * M_PI / 180.0, 37.11 * M_PI / 180.0, (-0.39 + 1.0) * M_PI / 180.0,
91 (37.11 - 1.0) * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -080092
Brian Silverman052e69d2017-02-12 16:19:55 -080093 static constexpr double kTurretEncoderCountsPerRevolution = 1024 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -080094 static constexpr double kTurretEncoderRatio = 16.0 / 92.0;
95 static constexpr double kTurretPotRatio = 16.0 / 92.0;
96 static constexpr double kTurretEncoderIndexDifference =
97 2.0 * M_PI * kTurretEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -080098 static constexpr double kMaxTurretEncoderPulsesPerSecond =
Ojas Upadhye3abe8862017-02-11 17:06:53 -080099 control_loops::superstructure::turret::kFreeSpeed *
100 control_loops::superstructure::turret::kOutputRatio /
Brian Silverman052e69d2017-02-12 16:19:55 -0800101 constants::Values::kTurretEncoderRatio *
102 kTurretEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800103 static constexpr ::frc971::constants::Range kTurretRange{
Brian Silverman052e69d2017-02-12 16:19:55 -0800104 -460.0 / 2.0 * M_PI / 180.0, 460.0 / 2.0 * M_PI / 180.0,
105 -450.0 / 2.0 * M_PI / 180.0, 450.0 / 2.0 * M_PI / 180.0};
Brian Silvermandb8498a2017-02-11 17:16:09 -0800106
Brian Silverman052e69d2017-02-12 16:19:55 -0800107 static constexpr double kMaxIndexerEncoderCountsPerRevolution = 256 * 4;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800108 static constexpr double kIndexerEncoderRatio = (18.0 / 36.0) * (12.0 / 84.0);
109 static constexpr double kIndexerEncoderIndexDifference =
110 2.0 * M_PI * kIndexerEncoderRatio;
Brian Silverman052e69d2017-02-12 16:19:55 -0800111 static constexpr double kMaxIndexerEncoderPulsesPerSecond =
112 control_loops::superstructure::indexer::kFreeSpeed *
113 control_loops::superstructure::indexer::kOutputRatio /
114 constants::Values::kIndexerEncoderRatio *
115 kMaxIndexerEncoderCountsPerRevolution;
Brian Silvermandb8498a2017-02-11 17:16:09 -0800116
117 double drivetrain_max_speed;
118
119 Intake intake;
120
121 Turret turret;
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;
Tyler Chatow6107aba2017-01-22 01:39:40 +0000127};
128
129// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
130// returns a reference to it.
131const Values &GetValues();
132
133// Creates Values instances for each team number it is called with and returns
134// them.
135const Values &GetValuesForTeam(uint16_t team_number);
136
137} // namespace constants
138} // namespace y2017
139
140#endif // Y2017_CONSTANTS_H_