blob: 65aad44ee24c3150bd4b8ba877c51b6419489619 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#ifndef Y2022_CONSTANTS_H_
2#define Y2022_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 "y2022/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080012#include "y2022/control_loops/superstructure/climber/climber_plant.h"
Yash Chainani997a7492022-01-29 15:48:56 -080013#include "y2022/control_loops/superstructure/intake/intake_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080014#include "y2022/control_loops/superstructure/turret/turret_plant.h"
milind-u086d7262022-01-19 20:44:18 -080015
16namespace y2022 {
17namespace constants {
18
19struct Values {
20 static const int kZeroingSampleSize = 200;
21
22 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
23 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
24 return kDrivetrainCyclesPerRevolution() * 4;
25 }
Griffin Bui6f27af22022-01-30 13:47:28 -080026 static constexpr double kDrivetrainEncoderRatio() {
27 return (14.0 / 54.0) * (22.0 / 56.0);
28 }
milind-u086d7262022-01-19 20:44:18 -080029 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 }
James Kuszmaul53507e12022-02-12 18:36:40 -080035
36 static double DrivetrainEncoderToMeters(int32_t in) {
37 return ((static_cast<double>(in) /
38 kDrivetrainEncoderCountsPerRevolution()) *
39 (2.0 * M_PI)) *
Henry Speiser55aa3ba2022-02-21 23:21:12 -080040 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
Yash Chainani997a7492022-01-29 15:48:56 -080041 }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080042
milind-u086d7262022-01-19 20:44:18 -080043 // Climber
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080044 static constexpr ::frc971::constants::Range kClimberRange() {
45 return ::frc971::constants::Range{
Henry Speiser55aa3ba2022-02-21 23:21:12 -080046 .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5};
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080047 }
48 static constexpr double kClimberPotMetersPerRevolution() {
49 return 22 * 0.25 * 0.0254;
50 }
51 static constexpr double kClimberPotRatio() { return 1.0; }
52
53 struct PotConstants {
54 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
55 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
56 subsystem_params;
57 double potentiometer_offset;
58 };
59
60 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080061
62 // Intake
63 // two encoders with same gear ratio for intake
Henry Speiser55aa3ba2022-02-21 23:21:12 -080064 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
Milo Lin6b5e4582022-01-29 14:51:37 -080065
66 static constexpr double kIntakeEncoderRatio() {
Henry Speiser55aa3ba2022-02-21 23:21:12 -080067 return (16.0 / 64.0) * (20.0 / 50.0);
Milo Lin6b5e4582022-01-29 14:51:37 -080068 }
69
Henry Speiser55aa3ba2022-02-21 23:21:12 -080070 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
71
72 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
73 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
74 control_loops::superstructure::intake::kOutputRatio /
75 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
76 }
77
78 struct PotAndAbsEncoderConstants {
79 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
80 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
81 subsystem_params;
82 double potentiometer_offset;
83 };
84
85 PotAndAbsEncoderConstants intake_front;
86 PotAndAbsEncoderConstants intake_back;
87
88 // TODO (Yash): Constants need to be tuned
89 static constexpr ::frc971::constants::Range kIntakeRange() {
90 return ::frc971::constants::Range{
91 .lower_hard = -0.5, // Back Hard
92 .upper_hard = 2.85 + 0.05, // Front Hard
93 .lower = -0.300, // Back Soft
94 .upper = 2.725 // Front Soft
95 };
96 }
97
98 // Intake rollers
99 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; }
100 static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; }
101
102 // Turret
103 PotAndAbsEncoderConstants turret;
104
105 // TODO (Yash): Constants need to be tuned
106 static constexpr ::frc971::constants::Range kTurretRange() {
107 return ::frc971::constants::Range{
108 .lower_hard = -3.45, // Back Hard
109 .upper_hard = 3.45, // Front Hard
110 .lower = -3.3, // Back Soft
111 .upper = 3.3 // Front Soft
112 };
113 }
114
115 // Turret
116 static constexpr double kTurretPotRatio() { return 27.0 / 110.0; }
117 static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); }
118 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
119
120 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
121 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
122 control_loops::superstructure::turret::kOutputRatio /
123 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
124 }
milind-u086d7262022-01-19 20:44:18 -0800125};
126
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800127// Creates and returns a Values instance for the constants.
128// Should be called before realtime because this allocates memory.
129// Only the first call to either of these will be used.
130Values MakeValues(uint16_t team);
milind-u086d7262022-01-19 20:44:18 -0800131
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800132// Calls MakeValues with aos::network::GetTeamNumber()
133Values MakeValues();
milind-u086d7262022-01-19 20:44:18 -0800134
135} // namespace constants
136} // namespace y2022
137
138#endif // Y2022_CONSTANTS_H_