blob: 8bc5fbc4b4e00373b642d9af651c83d241da1209 [file] [log] [blame]
Austin Schuh2a3e0632018-02-19 16:24:49 -08001#ifndef Y2018_CONSTANTS_H_
2#define Y2018_CONSTANTS_H_
3
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cmath>
5#include <cstdint>
Austin Schuh2a3e0632018-02-19 16:24:49 -08006
7#include "frc971/constants.h"
Maxwell Henderson8f0e07f2023-02-08 21:10:58 -08008#include "frc971/control_loops/double_jointed_arm/dynamics.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07009#include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Maxwell Henderson8f0e07f2023-02-08 21:10:58 -080010#include "y2018/control_loops/superstructure/arm/arm_constants.h"
Austin Schuh2a3e0632018-02-19 16:24:49 -080011#include "y2018/control_loops/superstructure/intake/intake_plant.h"
12
13namespace y2018 {
14namespace constants {
15
16// Has all of our "constants", except the ones that come from other places. The
17// ones which change between robots are put together with a workable way to
18// retrieve the values for the current robot.
19
20// Everything is in SI units (volts, radians, meters, seconds, etc).
21// Some of these values are related to the conversion between raw values
22// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
23//
24// All ratios are from the encoder shaft to the output units.
25
26struct Values {
Sabina Davis8d20ca82018-02-19 13:17:45 -080027 static constexpr size_t kZeroingSampleSize() { return 200; }
Austin Schuh2a3e0632018-02-19 16:24:49 -080028
29 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
30 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
31 return kDrivetrainCyclesPerRevolution() * 4;
32 }
33 static constexpr double kDrivetrainEncoderRatio() {
34 return (20.0 / 48.0) * (30.0 / 36.0);
35 }
36 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
37 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
38 control_loops::drivetrain::kHighOutputRatio /
39 constants::Values::kDrivetrainEncoderRatio() *
40 kDrivetrainEncoderCountsPerRevolution();
41 }
42
Austin Schuh17dd0892018-03-02 20:06:31 -080043 static constexpr double kDrivetrainShifterPotMaxVoltage() { return 3.63; }
44 static constexpr double kDrivetrainShifterPotMinVoltage() { return 1.94; }
Austin Schuh2a3e0632018-02-19 16:24:49 -080045
Tyler Chatowbf0609c2021-07-31 16:13:27 -070046 static constexpr double kProximalEncoderCountsPerRevolution() {
47 return 4096.0;
48 }
Austin Schuh2a3e0632018-02-19 16:24:49 -080049 static constexpr double kProximalEncoderRatio() {
50 return (12.0 / 60.0) * (18.0 / 84.0);
51 }
52 static constexpr double kMaxProximalEncoderPulsesPerSecond() {
Maxwell Henderson8f0e07f2023-02-08 21:10:58 -080053 return control_loops::superstructure::arm::kArmConstants.free_speed /
milind-u0a7d28d2023-02-20 17:44:37 -080054 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g0 /
Austin Schuh2a3e0632018-02-19 16:24:49 -080055 kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution();
56 }
57 static constexpr double kProximalPotRatio() { return (12.0 / 60.0); }
58
59 static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; }
60 static constexpr double kDistalEncoderRatio() { return (12.0 / 60.0); }
61 static constexpr double kMaxDistalEncoderPulsesPerSecond() {
Maxwell Henderson8f0e07f2023-02-08 21:10:58 -080062 return control_loops::superstructure::arm::kArmConstants.free_speed /
milind-u0a7d28d2023-02-20 17:44:37 -080063 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 /
Austin Schuh2a3e0632018-02-19 16:24:49 -080064 kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution();
65 }
66 static constexpr double kDistalPotRatio() {
67 return (12.0 / 60.0) * (36.0 / 40.0);
68 }
69
70 static constexpr double kIntakeSpringRatio() {
71 return (10.0 * 0.080) / (2.0 * 1.5 * M_PI);
72 }
Austin Schuh6829f762018-03-02 21:36:01 -080073 static constexpr double kIntakeMotorEncoderCountsPerRevolution() {
74 return 4096.0;
75 }
Austin Schuh2a3e0632018-02-19 16:24:49 -080076 static constexpr double kIntakeMotorEncoderRatio() {
77 return (18.0 / 68.0) * (18.0 / 50.0);
78 }
79 static constexpr double kIntakeMotorPotRatio() { return (14.0 / 68.0); }
80 static constexpr double kMaxIntakeMotorEncoderPulsesPerSecond() {
81 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
82 control_loops::superstructure::intake::kGearRatio /
83 kIntakeMotorEncoderRatio() *
84 kIntakeMotorEncoderCountsPerRevolution();
85 }
86
Sabina Davis8d20ca82018-02-19 13:17:45 -080087 static constexpr ::frc971::constants::Range kIntakeRange() {
Austin Schuh6829f762018-03-02 21:36:01 -080088 // TODO(austin) Sort this out.
Tyler Chatowbf0609c2021-07-31 16:13:27 -070089 return ::frc971::constants::Range{-3.7, (1.25 * M_PI), -3.3, M_PI};
Sabina Davis8d20ca82018-02-19 13:17:45 -080090 }
91
92 struct IntakeSide {
93 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
94 double potentiometer_offset;
95 double spring_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -080096 };
Sabina Davis8d20ca82018-02-19 13:17:45 -080097 IntakeSide left_intake;
98 IntakeSide right_intake;
Austin Schuh2a3e0632018-02-19 16:24:49 -080099
100 struct Proximal {
Sabina Davis8d20ca82018-02-19 13:17:45 -0800101 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
102 double potentiometer_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800103 };
Austin Schuhcb091712018-02-21 20:01:55 -0800104 Proximal arm_proximal;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800105
106 struct Distal {
Sabina Davis8d20ca82018-02-19 13:17:45 -0800107 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
108 double potentiometer_offset;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800109 };
Austin Schuhcb091712018-02-21 20:01:55 -0800110 Distal arm_distal;
Austin Schuh2a3e0632018-02-19 16:24:49 -0800111
Austin Schuh2a3e0632018-02-19 16:24:49 -0800112 const char *vision_name;
113
114 double vision_error;
115};
116
117// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
118// returns a reference to it.
119const Values &GetValues();
120
121// Creates Values instances for each team number it is called with and returns
122// them.
123const Values &GetValuesForTeam(uint16_t team_number);
124
125} // namespace constants
126} // namespace y2018
127
128#endif // Y2018_CONSTANTS_H_