blob: 6927567281ebd19064efc300d4b52cf7d5bfb1c7 [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"
Yash Chainani997a7492022-01-29 15:48:56 -080012#include "y2022/control_loops/superstructure/intake/intake_plant.h"
milind-u086d7262022-01-19 20:44:18 -080013
14namespace y2022 {
15namespace constants {
16
17struct Values {
18 static const int kZeroingSampleSize = 200;
19
20 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
21 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
22 return kDrivetrainCyclesPerRevolution() * 4;
23 }
Griffin Bui6f27af22022-01-30 13:47:28 -080024 static constexpr double kDrivetrainEncoderRatio() {
25 return (14.0 / 54.0) * (22.0 / 56.0);
26 }
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)) *
38 kDrivetrainEncoderRatio() *
39 control_loops::drivetrain::kWheelRadius;
40 }
41
milind-u086d7262022-01-19 20:44:18 -080042 static constexpr double kRollerSupplyCurrentLimit() { return 30.0; }
43 static constexpr double kRollerStatorCurrentLimit() { return 40.0; }
44
Yash Chainani997a7492022-01-29 15:48:56 -080045 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
46 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
47 intake;
48
49 // TODO (Yash): Constants need to be tuned
50 static constexpr ::frc971::constants::Range kIntakeRange() {
51 return ::frc971::constants::Range{
52 .lower_hard = -0.5, // Back Hard
53 .upper_hard = 2.85 + 0.05, // Front Hard
54 .lower = -0.300, // Back Soft
55 .upper = 2.725 // Front Soft
56 };
57 }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080058
milind-u086d7262022-01-19 20:44:18 -080059 // Climber
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080060 static constexpr ::frc971::constants::Range kClimberRange() {
61 return ::frc971::constants::Range{
62 .lower_hard = -0.01,
63 .upper_hard = 0.6,
64 .lower = 0.0,
65 .upper = 0.5
66 };
67 }
68 static constexpr double kClimberPotMetersPerRevolution() {
69 return 22 * 0.25 * 0.0254;
70 }
71 static constexpr double kClimberPotRatio() { return 1.0; }
72
73 struct PotConstants {
74 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
75 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
76 subsystem_params;
77 double potentiometer_offset;
78 };
79
80 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080081
82 // Intake
83 // two encoders with same gear ratio for intake
84 static constexpr double kIntakeEncoderCountsPerRevolution() { return 512.0; }
85
86 static constexpr double kIntakeEncoderRatio() {
87 return ((16.0 / 60.0) * (18.0 / 62.0));
88 }
89
90 // TODO(Milo): Also need to add specific PPR (Pulse per revolution)
milind-u086d7262022-01-19 20:44:18 -080091};
92
93// Creates (once) a Values instance for ::aos::network::GetTeamNumber(). Should
94// be called before realtime because this allocates memory.
95void InitValues();
96
97// Returns a reference to the Values instance for
98// ::aos::network::GetTeamNumber(). Values must be initialized through
99// InitValues() before calling this.
100const Values &GetValues();
101
102} // namespace constants
103} // namespace y2022
104
105#endif // Y2022_CONSTANTS_H_