blob: ba7267c96f04af3f6a866c1e181022bb25799cda [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
Maxwell Henderson20fa0692023-12-22 15:37:38 -080017constexpr uint16_t kThirdRobotTeamNumber = 9984;
Ariv Diggi0af59c02023-10-07 13:15:39 -070018
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
Filip Kujawa35b5aad2023-11-14 21:53:19 -080046 static constexpr double kPivotSupplyCurrentLimit() { return 40.0; }
47 static constexpr double kPivotStatorCurrentLimit() { return 200.0; }
48
Ariv Diggic892e922023-10-21 15:52:06 -070049 // timeout to ensure code doesn't get stuck after releasing the "intake"
50 // button
51 static constexpr std::chrono::milliseconds kExtraIntakingTime() {
52 return std::chrono::milliseconds{100};
53 }
54
Ariv Diggi0af59c02023-10-07 13:15:39 -070055 static double DrivetrainEncoderToMeters(int32_t in) {
56 return ((static_cast<double>(in) /
57 kDrivetrainEncoderCountsPerRevolution()) *
58 (2.0 * M_PI)) *
59 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
60 }
61
62 static double DrivetrainCANEncoderToMeters(double rotations) {
63 return (rotations * (2.0 * M_PI)) *
Maxwell Hendersonf1cfe7f2023-12-26 10:48:26 -080064 control_loops::drivetrain::kHighOutputRatio;
Ariv Diggi0af59c02023-10-07 13:15:39 -070065 }
Maxwell Henderson43684fa2023-11-06 11:08:06 -080066
Filip Kujawa35b5aad2023-11-14 21:53:19 -080067 // Pivot Joint
Maxwell Henderson43684fa2023-11-06 11:08:06 -080068 static constexpr double kPivotJointEncoderCountsPerRevolution() {
69 return 4096.0;
70 }
71
Filip Kujawa35b5aad2023-11-14 21:53:19 -080072 static constexpr double kPivotJointEncoderRatio() {
73 return (24.0 / 64.0) * (15.0 / 60.0);
74 }
Maxwell Henderson0d220772023-11-06 11:09:58 -080075
Filip Kujawa35b5aad2023-11-14 21:53:19 -080076 static constexpr double kPivotJointPotRatio() {
77 return (24.0 / 64.0) * (15.0 / 60.0);
78 }
Maxwell Henderson0d220772023-11-06 11:09:58 -080079
80 static constexpr double kPivotJointPotRadiansPerVolt() {
Filip Kujawa35b5aad2023-11-14 21:53:19 -080081 return kPivotJointPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) *
Maxwell Henderson0d220772023-11-06 11:09:58 -080082 (2 * M_PI /*radians*/);
83 }
Maxwell Henderson43684fa2023-11-06 11:08:06 -080084
85 static constexpr double kMaxPivotJointEncoderPulsesPerSecond() {
86 return control_loops::superstructure::pivot_joint::kFreeSpeed /
87 (2.0 * M_PI) *
88 control_loops::superstructure::pivot_joint::kOutputRatio /
89 kPivotJointEncoderRatio() * kPivotJointEncoderCountsPerRevolution();
90 }
91
92 static constexpr ::frc971::constants::Range kPivotJointRange() {
93 return ::frc971::constants::Range{
Filip Kujawa35b5aad2023-11-14 21:53:19 -080094 .lower_hard = -1.78879503977269, // Back Hard
95 .upper_hard = 1.76302285774785, // Front Hard
96 .lower = -1.77156498873494, // Back Soft
97 .upper = 1.76555657862879, // Front Soft
Maxwell Henderson43684fa2023-11-06 11:08:06 -080098 };
99 }
100
Maxwell Henderson0d220772023-11-06 11:09:58 -0800101 struct PotAndAbsEncoderConstants {
102 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
103 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
104 subsystem_params;
105 double potentiometer_offset;
106 };
107
Maxwell Henderson43684fa2023-11-06 11:08:06 -0800108 PotAndAbsEncoderConstants pivot_joint;
109
110 bool pivot_joint_flipped;
Ariv Diggi0af59c02023-10-07 13:15:39 -0700111};
112
113// Creates and returns a Values instance for the constants.
114// Should be called before realtime because this allocates memory.
115// Only the first call to either of these will be used.
116Values MakeValues(uint16_t team);
117
118// Calls MakeValues with aos::network::GetTeamNumber()
119Values MakeValues();
120
121} // namespace constants
122} // namespace y2023_bot3
123
Maxwell Henderson43684fa2023-11-06 11:08:06 -0800124#endif // Y2023_BOT3_CONSTANTS_H_