blob: 64153af45f188962eb75bbb3f3215869ccaccce3 [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#ifndef Y2023_CONSTANTS_H_
2#define Y2023_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 "y2023/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
milind-u37385182023-02-20 15:07:28 -080012#include "y2023/control_loops/superstructure/arm/arm_constants.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080013
14namespace y2023 {
15namespace constants {
16
17constexpr uint16_t kCompTeamNumber = 971;
18constexpr uint16_t kPracticeTeamNumber = 9971;
19constexpr uint16_t kCodingRobotTeamNumber = 7971;
20
21struct Values {
22 static const int kZeroingSampleSize = 200;
23
Ravago Jones2060ee62023-02-03 18:12:24 -080024 static const int kDrivetrainWriterPriority = 35;
25 static const int kDrivetrainTxPriority = 36;
26 static const int kDrivetrainRxPriority = 36;
27
Maxwell Hendersonad312342023-01-10 12:07:47 -080028 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
Ravago Jones2060ee62023-02-03 18:12:24 -080040 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
41 static constexpr double kDrivetrainStatorCurrentLimit() { return 40.0; }
42
Maxwell Hendersonad312342023-01-10 12:07:47 -080043 static double DrivetrainEncoderToMeters(int32_t in) {
44 return ((static_cast<double>(in) /
45 kDrivetrainEncoderCountsPerRevolution()) *
46 (2.0 * M_PI)) *
47 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
48 }
49
Ravago Jones2060ee62023-02-03 18:12:24 -080050 static double DrivetrainCANEncoderToMeters(double rotations) {
51 return (rotations * (2.0 * M_PI)) *
52 control_loops::drivetrain::kHighOutputRatio *
53 control_loops::drivetrain::kWheelRadius;
54 }
milind-u37385182023-02-20 15:07:28 -080055 static constexpr double kProximalEncoderCountsPerRevolution() {
56 return 4096.0;
57 }
58 static constexpr double kProximalEncoderRatio() { return (15.0 / 95.0); }
59 static constexpr double kMaxProximalEncoderPulsesPerSecond() {
60 return control_loops::superstructure::arm::kArmConstants.free_speed /
61 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 /
62 kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution();
63 }
64 static constexpr double kProximalPotRatio() {
65 return (24.0 / 36.0) * (24.0 / 58.0) * (15.0 / 95.0);
66 }
67
68 static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; }
69 static constexpr double kDistalEncoderRatio() { return (15.0 / 95.0); }
70 static constexpr double kMaxDistalEncoderPulsesPerSecond() {
71 return control_loops::superstructure::arm::kArmConstants.free_speed /
72 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g2 /
73 kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution();
74 }
75 static constexpr double kDistalPotRatio() {
76 return (24.0 / 36.0) * (18.0 / 66.0) * (15.0 / 95.0);
77 }
Ravago Jones2060ee62023-02-03 18:12:24 -080078
Maxwell Hendersonad312342023-01-10 12:07:47 -080079 struct PotConstants {
80 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
81 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
82 subsystem_params;
83 double potentiometer_offset;
84 };
85
86 struct PotAndAbsEncoderConstants {
87 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
88 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
89 subsystem_params;
90 double potentiometer_offset;
91 };
milind-u37385182023-02-20 15:07:28 -080092
93 struct ArmJointConstants {
94 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
95 double potentiometer_offset;
96 };
97
98 ArmJointConstants arm_proximal;
99 ArmJointConstants arm_distal;
Maxwell Hendersonad312342023-01-10 12:07:47 -0800100};
101
102// Creates and returns a Values instance for the constants.
103// Should be called before realtime because this allocates memory.
104// Only the first call to either of these will be used.
105Values MakeValues(uint16_t team);
106
107// Calls MakeValues with aos::network::GetTeamNumber()
108Values MakeValues();
109
110} // namespace constants
111} // namespace y2023
112
113#endif // Y2023_CONSTANTS_H_