blob: fb3089eb223c9197ec53521a21ba18aaa0065810 [file] [log] [blame]
Maxwell Henderson43684fa2023-11-06 11:08:06 -08001#ifndef Y2023_BOT3_CONSTANTS_H_
2#define Y2023_BOT3_CONSTANTS_H_
Ariv Diggi0af59c02023-10-07 13:15:39 -07003
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"
Maxwell Henderson43684fa2023-11-06 11:08:06 -080011#include "frc971/zeroing/pot_and_absolute_encoder.h"
Ariv Diggi0af59c02023-10-07 13:15:39 -070012#include "y2023_bot3/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Maxwell Henderson43684fa2023-11-06 11:08:06 -080013#include "y2023_bot3/control_loops/superstructure/pivot_joint/pivot_joint_plant.h"
Ariv Diggi0af59c02023-10-07 13:15:39 -070014namespace y2023_bot3 {
15namespace constants {
16
17constexpr uint16_t kThirdRobotTeamNumber = 8971;
18
19struct Values {
20 static const int kZeroingSampleSize = 200;
21
22 static const int kSuperstructureCANWriterPriority = 35;
23 static const int kDrivetrainWriterPriority = 35;
24 static const int kDrivetrainTxPriority = 36;
25 static const int kDrivetrainRxPriority = 36;
26
27 // TODO(max): Change these constants based on 3rd drivetrain CAD
28 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
29 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
30 return kDrivetrainCyclesPerRevolution() * 4;
31 }
32 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
33 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
34 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
35 control_loops::drivetrain::kHighOutputRatio /
36 constants::Values::kDrivetrainEncoderRatio() *
37 kDrivetrainEncoderCountsPerRevolution();
38 }
39
40 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
41 static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; }
42
Maxwell Henderson3772d282023-11-06 11:07:49 -080043 static constexpr double kRollerSupplyCurrentLimit() { return 30.0; }
44 static constexpr double kRollerStatorCurrentLimit() { return 100.0; }
45
Ariv Diggic892e922023-10-21 15:52:06 -070046 // timeout to ensure code doesn't get stuck after releasing the "intake"
47 // button
48 static constexpr std::chrono::milliseconds kExtraIntakingTime() {
49 return std::chrono::milliseconds{100};
50 }
51
Ariv Diggi0af59c02023-10-07 13:15:39 -070052 static double DrivetrainEncoderToMeters(int32_t in) {
53 return ((static_cast<double>(in) /
54 kDrivetrainEncoderCountsPerRevolution()) *
55 (2.0 * M_PI)) *
56 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
57 }
58
59 static double DrivetrainCANEncoderToMeters(double rotations) {
60 return (rotations * (2.0 * M_PI)) *
61 control_loops::drivetrain::kHighOutputRatio *
62 control_loops::drivetrain::kWheelRadius;
63 }
Maxwell Henderson43684fa2023-11-06 11:08:06 -080064
65 struct PotAndAbsEncoderConstants {
66 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
67 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
68 subsystem_params;
69 double potentiometer_offset;
70 };
71
72 // Pivot Joint (placeholders)
73 static constexpr double kPivotJointEncoderCountsPerRevolution() {
74 return 4096.0;
75 }
76
77 static constexpr double kPivotJointEncoderRatio() { return 1.0; }
78
79 static constexpr double kMaxPivotJointEncoderPulsesPerSecond() {
80 return control_loops::superstructure::pivot_joint::kFreeSpeed /
81 (2.0 * M_PI) *
82 control_loops::superstructure::pivot_joint::kOutputRatio /
83 kPivotJointEncoderRatio() * kPivotJointEncoderCountsPerRevolution();
84 }
85
86 static constexpr ::frc971::constants::Range kPivotJointRange() {
87 return ::frc971::constants::Range{
88 .lower_hard = -0.10, // Back Hard
89 .upper_hard = 4.90, // Front Hard
90 .lower = 0.0, // Back Soft
91 .upper = 4.0, // Front Soft
92 };
93 }
94
95 PotAndAbsEncoderConstants pivot_joint;
96
97 bool pivot_joint_flipped;
Ariv Diggi0af59c02023-10-07 13:15:39 -070098};
99
100// Creates and returns a Values instance for the constants.
101// Should be called before realtime because this allocates memory.
102// Only the first call to either of these will be used.
103Values MakeValues(uint16_t team);
104
105// Calls MakeValues with aos::network::GetTeamNumber()
106Values MakeValues();
107
108} // namespace constants
109} // namespace y2023_bot3
110
Maxwell Henderson43684fa2023-11-06 11:08:06 -0800111#endif // Y2023_BOT3_CONSTANTS_H_