blob: 2ced38d60d5b84b95c4f1364e0af3cf006eb8fe5 [file] [log] [blame]
Henry Speiser354d2782022-07-22 13:56:48 -07001#ifndef Y2022_BOT3_CONSTANTS_H_
2#define Y2022_BOT3_CONSTANTS_H_
3
4#include <array>
5#include <cmath>
6#include <cstdint>
7
8#include "frc971/constants.h"
9#include "frc971/control_loops/pose.h"
10#include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
11#include "frc971/shooter_interpolation/interpolation.h"
12#include "y2022_bot3/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Thiago Monteiroa47ae662022-08-27 16:05:54 -070013#include "y2022_bot3/control_loops/superstructure/climber/climber_plant.h"
14#include "y2022_bot3/control_loops/superstructure/intake/intake_plant.h"
Henry Speiser354d2782022-07-22 13:56:48 -070015
16using ::frc971::shooter_interpolation::InterpolationTable;
17
18namespace y2022_bot3 {
19namespace constants {
20
21struct Values {
22 static const int kZeroingSampleSize = 200;
23
24 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
25 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
26 return kDrivetrainCyclesPerRevolution() * 4;
27 }
28 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
29 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
30 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
31 control_loops::drivetrain::kHighOutputRatio /
32 constants::Values::kDrivetrainEncoderRatio() *
33 kDrivetrainEncoderCountsPerRevolution();
34 }
35
36 static double DrivetrainEncoderToMeters(int32_t in) {
37 return ((static_cast<double>(in) /
38 kDrivetrainEncoderCountsPerRevolution()) *
39 (2.0 * M_PI)) *
40 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
41 }
42
43 struct PotAndAbsEncoderConstants {
44 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
45 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
46 subsystem_params;
47 double potentiometer_offset;
48 };
Nikita Narang869ebf32022-08-20 13:09:49 -070049
Nikita Narang869ebf32022-08-20 13:09:49 -070050 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; }
51 static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; }
52
Thiago Monteiroa47ae662022-08-27 16:05:54 -070053 // Intake
54 // TODO (Logan): Constants need to be tuned
55 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
56
57 static constexpr double kIntakeEncoderRatio() {
58 return (16.0 / 64.0) * (18.0 / 62.0);
59 }
60
61 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
62
63 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
64 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
65 control_loops::superstructure::intake::kOutputRatio /
66 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
67 }
68 PotAndAbsEncoderConstants intake;
69
70 static constexpr ::frc971::constants::Range kIntakeRange() {
71 return ::frc971::constants::Range{
72 .lower_hard = -0.85, // Back Hard
73 .upper_hard = 1.85, // Front Hard
74 .lower = -0.400, // Back Soft
75 .upper = 1.57 // Front Soft
76 };
77 }
78
79 // Climber
80 // TODO (Logan): Constants need to be tuned
81 static constexpr double kClimberEncoderCountsPerRevolution() {
82 return 4096.0;
83 }
84
85 static constexpr double kClimberEncoderRatio() {
86 return (16.0 / 64.0) * (18.0 / 62.0);
87 }
88
89 static constexpr double kClimberEncoderMetersPerRevolution() { return 1.0; }
90
91 static constexpr double kClimberPotMetersPerRevolution() { return 0.125; }
92
93 static constexpr double kClimberPotRatio() { return 16.0 / 64.0; }
94
95 static constexpr double kMaxClimberEncoderPulsesPerSecond() {
96 return control_loops::superstructure::climber::kFreeSpeed / (2.0 * M_PI) *
97 control_loops::superstructure::climber::kOutputRatio /
98 kClimberEncoderRatio() * kClimberEncoderCountsPerRevolution();
99 }
100 PotAndAbsEncoderConstants climber_left;
101 PotAndAbsEncoderConstants climber_right;
102
103 static constexpr ::frc971::constants::Range kClimberRange() {
104 return ::frc971::constants::Range{
105 .lower_hard = -0.01, // Back Hard
106 .upper_hard = 0.59, // Front Hard
107 .lower = 0.003, // Back Soft
108 .upper = 0.555 // Front Soft
109 };
110 }
Henry Speiser354d2782022-07-22 13:56:48 -0700111};
Nikita Narang869ebf32022-08-20 13:09:49 -0700112
Henry Speiser354d2782022-07-22 13:56:48 -0700113// Creates and returns a Values instance for the constants.
114// Should be called before realtime because this allocates memory.
115// Only the first call to either of these will be used.
116Values MakeValues(uint16_t team);
117
118// Calls MakeValues with aos::network::GetTeamNumber()
119Values MakeValues();
120
121} // namespace constants
122} // namespace y2022_bot3
123
uid8253b0a2022-10-12 20:43:29 -0700124#endif // Y2022_BOT3_CONSTANTS_H_