blob: 160da1e8412627f38508c5bc0e9ac1836f3d98a4 [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 }
James Kuszmaulc2b2a802022-02-25 21:59:31 -080026 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
milind-u086d7262022-01-19 20:44:18 -080027 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
28 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
29 control_loops::drivetrain::kHighOutputRatio /
30 constants::Values::kDrivetrainEncoderRatio() *
31 kDrivetrainEncoderCountsPerRevolution();
32 }
James Kuszmaul53507e12022-02-12 18:36:40 -080033
34 static double DrivetrainEncoderToMeters(int32_t in) {
35 return ((static_cast<double>(in) /
36 kDrivetrainEncoderCountsPerRevolution()) *
37 (2.0 * M_PI)) *
Henry Speiser55aa3ba2022-02-21 23:21:12 -080038 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
Yash Chainani997a7492022-01-29 15:48:56 -080039 }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080040
milind-u086d7262022-01-19 20:44:18 -080041 // Climber
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080042 static constexpr ::frc971::constants::Range kClimberRange() {
43 return ::frc971::constants::Range{
Henry Speiser55aa3ba2022-02-21 23:21:12 -080044 .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5};
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080045 }
46 static constexpr double kClimberPotMetersPerRevolution() {
47 return 22 * 0.25 * 0.0254;
48 }
49 static constexpr double kClimberPotRatio() { return 1.0; }
50
51 struct PotConstants {
52 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
53 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
54 subsystem_params;
55 double potentiometer_offset;
56 };
57
58 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080059
60 // Intake
61 // two encoders with same gear ratio for intake
Henry Speiser55aa3ba2022-02-21 23:21:12 -080062 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
Milo Lin6b5e4582022-01-29 14:51:37 -080063
64 static constexpr double kIntakeEncoderRatio() {
Henry Speiser55aa3ba2022-02-21 23:21:12 -080065 return (16.0 / 64.0) * (20.0 / 50.0);
Milo Lin6b5e4582022-01-29 14:51:37 -080066 }
67
Henry Speiser55aa3ba2022-02-21 23:21:12 -080068 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
69
70 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
71 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
72 control_loops::superstructure::intake::kOutputRatio /
73 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
74 }
75
76 struct PotAndAbsEncoderConstants {
77 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
78 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
79 subsystem_params;
80 double potentiometer_offset;
81 };
82
83 PotAndAbsEncoderConstants intake_front;
84 PotAndAbsEncoderConstants intake_back;
85
86 // TODO (Yash): Constants need to be tuned
87 static constexpr ::frc971::constants::Range kIntakeRange() {
88 return ::frc971::constants::Range{
89 .lower_hard = -0.5, // Back Hard
90 .upper_hard = 2.85 + 0.05, // Front Hard
91 .lower = -0.300, // Back Soft
92 .upper = 2.725 // Front Soft
93 };
94 }
95
96 // Intake rollers
97 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; }
98 static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; }
99
100 // Turret
101 PotAndAbsEncoderConstants turret;
102
103 // TODO (Yash): Constants need to be tuned
104 static constexpr ::frc971::constants::Range kTurretRange() {
105 return ::frc971::constants::Range{
106 .lower_hard = -3.45, // Back Hard
107 .upper_hard = 3.45, // Front Hard
108 .lower = -3.3, // Back Soft
109 .upper = 3.3 // Front Soft
110 };
111 }
112
113 // Turret
114 static constexpr double kTurretPotRatio() { return 27.0 / 110.0; }
115 static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); }
116 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
117
118 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
119 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
120 control_loops::superstructure::turret::kOutputRatio /
121 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
122 }
Griffin Buibcbef482022-02-23 15:32:10 -0800123
124 // Flipper arms
125 static constexpr double kFlipperArmSupplyCurrentLimit() { return 30.0; }
126 static constexpr double kFlipperArmStatorCurrentLimit() { return 40.0; }
127
128 // TODO: (Griffin) this needs to be set
129 static constexpr ::frc971::constants::Range kFlipperArmRange() {
130 return ::frc971::constants::Range{
131 .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5};
132 }
133
134 static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; }
135
136 PotConstants flipper_arm_left;
137 PotConstants flipper_arm_right;
milind-u086d7262022-01-19 20:44:18 -0800138};
139
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800140// Creates and returns a Values instance for the constants.
141// Should be called before realtime because this allocates memory.
142// Only the first call to either of these will be used.
143Values MakeValues(uint16_t team);
milind-u086d7262022-01-19 20:44:18 -0800144
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800145// Calls MakeValues with aos::network::GetTeamNumber()
146Values MakeValues();
milind-u086d7262022-01-19 20:44:18 -0800147
148} // namespace constants
149} // namespace y2022
150
151#endif // Y2022_CONSTANTS_H_