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