2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
sensor_conversions.h
Go to the documentation of this file.
1
4
5#pragma once
6#include <units/acceleration.h>
7#include <units/angle.h>
8#include <units/angular_velocity.h>
9#include <units/length.h>
10#include <units/time.h>
11#include <units/velocity.h>
12
13#include <numbers>
14
15#include "custom_units.h"
16
18 namespace swerve_drive {
19
20 namespace turn {
21 constexpr double sensorConversionFactor =
22 360.0 / 4096;
23 constexpr double ToSensorUnit(const units::degree_t degrees) {
24 return degrees.to<double>() / sensorConversionFactor;
25 }
26 constexpr units::degree_t ToAngle(const double sensorunit) {
27 return units::make_unit<units::degree_t>(sensorunit * sensorConversionFactor);
28 }
29 } // namespace turn
30 namespace drive {
31 constexpr auto wheelDiameter = 3.5_in;
32 constexpr auto wheelCircumference = wheelDiameter * std::numbers::pi;
33 constexpr double sensorUnitsPerMotorRevolution = 2048;
34 constexpr double driveGearRatio = 36000.0 / 5880.0;
35
36 constexpr units::inch_t ToDistance(const double sensorunit) {
38 }
39 constexpr double ToSensorPosition(const units::inch_t distance) {
41 }
42
43 constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity) {
44 return ToDistance(sensorVelocity) / units::decisecond_t{1};
45 }
46 constexpr double ToSensorVelocity(const units::inches_per_second_t velocity) {
47 return ToSensorPosition(velocity * units::decisecond_t{1});
48 }
49 } // namespace drive
50 } // namespace swerve_drive
51
52 namespace lifter {
53 namespace arm_extension {
54 constexpr double sensorToMotorRevolution = 1.0 / 2048;
55 constexpr double gearboxReduction = 1.0 / 12.0;
56 constexpr double driveSprocketTeeth = 15.0;
57 constexpr double extensionInchesPerTooth = 0.375 / 1;
58 constexpr double absEncoderReduction = 1.0 / 10;
59 constexpr units::inch_t extensionPerEncoderRevolution =
60 units::make_unit<units::inch_t>((extensionInchesPerTooth * driveSprocketTeeth) / absEncoderReduction);
61
62 constexpr units::inch_t ToExtension(const double sensorUnit) {
63 return units::make_unit<units::inch_t>(sensorUnit * sensorToMotorRevolution * gearboxReduction *
65 }
66 constexpr double ToSensorUnit(const units::inch_t extension) {
67 return extension.to<double>() / sensorToMotorRevolution / gearboxReduction / driveSprocketTeeth /
69 }
70
71 constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity) {
72 return units::inches_per_second_t{ToExtension(sensorVelocity) / units::decisecond_t{1}};
73 }
74 constexpr double ToSensorVelocity(const units::inches_per_second_t velocity) {
75 return ToSensorUnit(velocity * units::decisecond_t{1});
76 }
77
78 // * David I'm sorry in advance for this math
79
83 constexpr units::inch_t ExtensionFromRotation(const units::degree_t angle) {
85 units::make_unit<units::dimensionless::scalar_t>((angle.to<double>() / 360.0));
86 }
87 } // namespace arm_extension
88 namespace wrist {
89 constexpr double sensorUnitsPerRevolution = 2048.0;
90 constexpr double gearBoxReduction = 9.0;
91 constexpr double extraReduction = 60.0 / 20.0;
92 constexpr double sensorConversionFactor =
94 extraReduction); // Scalar for getting angle in degrees from encoder
95 constexpr units::degree_t ToAngle(const double sensorUnit) {
96 return units::make_unit<units::degree_t>(sensorUnit * sensorConversionFactor);
97 }
98
99 constexpr double ToSensorUnit(const units::degree_t degrees) {
100 return degrees.to<double>() / sensorConversionFactor;
101 }
102
103 constexpr units::degrees_per_second_t ToVelocity(const double sensorVelocity) {
104 return units::degrees_per_second_t{ToAngle(sensorVelocity) / units::decisecond_t{1}};
105 }
106 constexpr double ToSensorVelocity(const units::degrees_per_second_t velocity) {
107 return ToSensorUnit(velocity * units::decisecond_t{1});
108 }
109
110 } // namespace wrist
111 namespace shoulder {
112 constexpr double sensorConversionFactor =
113 360.0 / 4096;
114 constexpr double ToSensorUnit(const units::degree_t degrees) {
115 return degrees.to<double>() / sensorConversionFactor;
116 }
117 constexpr units::degree_t ToAngle(const double sensorUnit) {
118 return units::degree_t(sensorUnit * sensorConversionFactor);
119 }
120
121 constexpr units::degrees_per_second_t ToVelocity(const double sensorVelocity) {
122 return units::degrees_per_second_t{ToAngle(sensorVelocity) / units::decisecond_t{1}};
123 }
124 constexpr double ToSensorVelocity(const units::degrees_per_second_t velocity) {
125 return ToSensorUnit(velocity * units::decisecond_t{1});
126 }
127 } // namespace shoulder
128 namespace shoulder_actuator {
129 constexpr double sensorToMotorRev = 1.0 / 2048;
130 constexpr double beltReduction = 30.0 / 18.0;
131 constexpr double extensionMillimetersPerRevolution = 4.0;
132 constexpr double fudgeFactor = 0.992;
133
134 constexpr double ToSensorUnit(const units::inch_t extension) {
135 return (units::millimeter_t(extension) / extensionMillimetersPerRevolution / beltReduction / sensorToMotorRev /
137 .to<double>();
138 }
139
140 constexpr units::inch_t ToExtension(const double sensorUnits) {
141 return units::millimeter_t(sensorUnits * sensorToMotorRev * beltReduction * extensionMillimetersPerRevolution *
143 }
144
145 constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity) {
146 return units::inches_per_second_t{ToExtension(sensorVelocity) / units::decisecond_t{1}};
147 }
148 constexpr double ToSensorVelocity(const units::inches_per_second_t velocity) {
149 return ToSensorUnit(velocity * units::decisecond_t{1});
150 }
151 } // namespace shoulder_actuator
152 } // namespace lifter
153 namespace bashguard {
154 constexpr double sensorToMotorRevolution = 1.0 / 2048;
155 constexpr double gearboxReduction = 1.0 / 5;
156 constexpr double driveSprocketTeeth = 15.0;
157 constexpr double extensionInchesPerTooth = 0.375 / 1;
158 constexpr units::inch_t ToExtension(const double sensorUnit) {
159 return units::make_unit<units::inch_t>(sensorUnit * sensorToMotorRevolution * gearboxReduction *
161 }
162 constexpr double ToSensorUnit(const units::inch_t extension) {
163 return extension.to<double>() / sensorToMotorRevolution / gearboxReduction / driveSprocketTeeth /
165 }
166
167 constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity) {
168 return units::inches_per_second_t{ToExtension(sensorVelocity) / units::decisecond_t{1}};
169 }
170 constexpr double ToSensorVelocity(const units::inches_per_second_t velocity) {
171 return ToSensorUnit(velocity * units::decisecond_t{1});
172 }
173 } // namespace bashguard
174
175 namespace oui_oui_place {
176
177 constexpr double sensorConversionFactor = 360.0 / 2048;
178 constexpr double gearboxReduction = 1.0 / 15.0;
179
180 constexpr double ToSensorUnit(const units::degree_t angle) {
181 return angle.to<double>() / sensorConversionFactor / gearboxReduction;
182 }
183
184 constexpr units::degree_t ToAngle(const double sensorUnits) {
185 return units::degree_t(sensorUnits * sensorConversionFactor * gearboxReduction);
186 }
187
188 constexpr units::degrees_per_second_t ToVelocity(const double sensorVelocity) {
189 return units::degrees_per_second_t{ToAngle(sensorVelocity) / units::decisecond_t{1}};
190 }
191
192 constexpr double ToSensorVelocity(const units::degrees_per_second_t velocity) {
193 return ToSensorUnit(velocity * units::decisecond_t{1});
194 }
195 } // namespace oui_oui_place
196} // namespace sensor_conversions
constexpr double gearboxReduction
Definition sensor_conversions.h:155
constexpr double ToSensorVelocity(const units::inches_per_second_t velocity)
Definition sensor_conversions.h:170
constexpr double sensorToMotorRevolution
Definition sensor_conversions.h:154
constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:167
constexpr double ToSensorUnit(const units::inch_t extension)
Definition sensor_conversions.h:162
constexpr double extensionInchesPerTooth
Definition sensor_conversions.h:157
constexpr double driveSprocketTeeth
Definition sensor_conversions.h:156
constexpr units::inch_t ToExtension(const double sensorUnit)
Definition sensor_conversions.h:158
constexpr double driveSprocketTeeth
Definition sensor_conversions.h:56
constexpr double gearboxReduction
Definition sensor_conversions.h:55
constexpr units::inch_t ToExtension(const double sensorUnit)
Definition sensor_conversions.h:62
constexpr units::inch_t ExtensionFromRotation(const units::degree_t angle)
Find the travel of the extension given a rotation "angle" of the CANCoder.
Definition sensor_conversions.h:83
constexpr double ToSensorVelocity(const units::inches_per_second_t velocity)
Definition sensor_conversions.h:74
constexpr double absEncoderReduction
Definition sensor_conversions.h:58
constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:71
constexpr double extensionInchesPerTooth
Definition sensor_conversions.h:57
constexpr double ToSensorUnit(const units::inch_t extension)
Definition sensor_conversions.h:66
constexpr double sensorToMotorRevolution
Definition sensor_conversions.h:54
constexpr units::inch_t extensionPerEncoderRevolution
Definition sensor_conversions.h:59
constexpr double sensorToMotorRev
Definition sensor_conversions.h:129
constexpr double fudgeFactor
This seems to be due to some discrepancy on comp bot.
Definition sensor_conversions.h:132
constexpr double beltReduction
Definition sensor_conversions.h:130
constexpr double ToSensorVelocity(const units::inches_per_second_t velocity)
Definition sensor_conversions.h:148
constexpr double ToSensorUnit(const units::inch_t extension)
Definition sensor_conversions.h:134
constexpr double extensionMillimetersPerRevolution
Definition sensor_conversions.h:131
constexpr units::inch_t ToExtension(const double sensorUnits)
Definition sensor_conversions.h:140
constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:145
constexpr units::degrees_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:121
constexpr units::degree_t ToAngle(const double sensorUnit)
Definition sensor_conversions.h:117
constexpr double sensorConversionFactor
multiply to convert raw sensor units to module degrees
Definition sensor_conversions.h:112
constexpr double ToSensorUnit(const units::degree_t degrees)
Definition sensor_conversions.h:114
constexpr double ToSensorVelocity(const units::degrees_per_second_t velocity)
Definition sensor_conversions.h:124
constexpr double sensorUnitsPerRevolution
Definition sensor_conversions.h:89
constexpr units::degrees_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:103
constexpr double ToSensorUnit(const units::degree_t degrees)
Definition sensor_conversions.h:99
constexpr units::degree_t ToAngle(const double sensorUnit)
Definition sensor_conversions.h:95
constexpr double extraReduction
Definition sensor_conversions.h:91
constexpr double gearBoxReduction
Definition sensor_conversions.h:90
constexpr double ToSensorVelocity(const units::degrees_per_second_t velocity)
Definition sensor_conversions.h:106
constexpr double sensorConversionFactor
Definition sensor_conversions.h:92
constexpr double sensorConversionFactor
multiply to convert raw sensor units to module degrees
Definition sensor_conversions.h:177
constexpr double ToSensorUnit(const units::degree_t angle)
Definition sensor_conversions.h:180
constexpr double gearboxReduction
Definition sensor_conversions.h:178
constexpr units::degrees_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:188
constexpr double ToSensorVelocity(const units::degrees_per_second_t velocity)
Definition sensor_conversions.h:192
constexpr units::degree_t ToAngle(const double sensorUnits)
Definition sensor_conversions.h:184
constexpr auto wheelCircumference
Definition sensor_conversions.h:32
constexpr double ToSensorVelocity(const units::inches_per_second_t velocity)
Definition sensor_conversions.h:46
constexpr double sensorUnitsPerMotorRevolution
Definition sensor_conversions.h:33
constexpr auto wheelDiameter
Definition sensor_conversions.h:31
constexpr double ToSensorPosition(const units::inch_t distance)
Definition sensor_conversions.h:39
constexpr units::inch_t ToDistance(const double sensorunit)
Definition sensor_conversions.h:36
constexpr double driveGearRatio
Definition sensor_conversions.h:34
constexpr units::inches_per_second_t ToVelocity(const double sensorVelocity)
Definition sensor_conversions.h:43
constexpr double ToSensorUnit(const units::degree_t degrees)
Definition sensor_conversions.h:23
constexpr double sensorConversionFactor
multiply to convert raw sensor units to module degrees
Definition sensor_conversions.h:21
constexpr units::degree_t ToAngle(const double sensorunit)
Definition sensor_conversions.h:26
Definition sensor_conversions.h:17