WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
DCMotor.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include "wpi/units/angular_velocity.hpp"
8#include "wpi/units/current.hpp"
9#include "wpi/units/impedance.hpp"
10#include "wpi/units/torque.hpp"
11#include "wpi/units/voltage.hpp"
13
14namespace wpi::math {
15
16/**
17 * Holds the constants for a DC motor.
18 */
20 public:
21 using radians_per_second_per_volt_t = wpi::units::unit_t<
22 wpi::units::compound_unit<wpi::units::radians_per_second,
23 wpi::units::inverse<wpi::units::volt>>>;
25 wpi::units::unit_t<wpi::units::compound_unit<
26 wpi::units::newton_meters, wpi::units::inverse<wpi::units::ampere>>>;
27
28 /// Voltage at which the motor constants were measured.
29 wpi::units::volt_t nominalVoltage;
30
31 /// Torque when stalled.
32 wpi::units::newton_meter_t stallTorque;
33
34 /// Current draw when stalled.
35 wpi::units::ampere_t stallCurrent;
36
37 /// Current draw under no load.
38 wpi::units::ampere_t freeCurrent;
39
40 /// Angular velocity under no load.
41 wpi::units::radians_per_second_t freeSpeed;
42
43 /// Motor internal resistance.
44 wpi::units::ohm_t R;
45
46 /// Motor velocity constant.
48
49 /// Motor torque constant.
51
52 /**
53 * Constructs a DC motor.
54 *
55 * @param nominalVoltage Voltage at which the motor constants were measured.
56 * @param stallTorque Torque when stalled.
57 * @param stallCurrent Current draw when stalled.
58 * @param freeCurrent Current draw under no load.
59 * @param freeSpeed Angular velocity under no load.
60 * @param numMotors Number of motors in a gearbox.
61 */
62 constexpr DCMotor(wpi::units::volt_t nominalVoltage,
63 wpi::units::newton_meter_t stallTorque,
64 wpi::units::ampere_t stallCurrent,
65 wpi::units::ampere_t freeCurrent,
66 wpi::units::radians_per_second_t freeSpeed,
67 int numMotors = 1)
69 stallTorque(stallTorque * numMotors),
70 stallCurrent(stallCurrent * numMotors),
71 freeCurrent(freeCurrent * numMotors),
75 Kt(this->stallTorque / this->stallCurrent) {}
76
77 /**
78 * Returns current drawn by motor with given velocity and input voltage.
79 *
80 * @param velocity The current angular velocity of the motor.
81 * @param inputVoltage The voltage being applied to the motor.
82 */
83 constexpr wpi::units::ampere_t Current(
84 wpi::units::radians_per_second_t velocity,
85 wpi::units::volt_t inputVoltage) const {
86 return -1.0 / Kv / R * velocity + 1.0 / R * inputVoltage;
87 }
88
89 /**
90 * Returns current drawn by motor for a given torque.
91 *
92 * @param torque The torque produced by the motor.
93 */
94 constexpr wpi::units::ampere_t Current(
95 wpi::units::newton_meter_t torque) const {
96 return torque / Kt;
97 }
98
99 /**
100 * Returns torque produced by the motor with a given current.
101 *
102 * @param current The current drawn by the motor.
103 */
104 constexpr wpi::units::newton_meter_t Torque(
105 wpi::units::ampere_t current) const {
106 return current * Kt;
107 }
108
109 /**
110 * Returns the voltage provided to the motor for a given torque and
111 * angular velocity.
112 *
113 * @param torque The torque produced by the motor.
114 * @param velocity The current angular velocity of the motor.
115 */
116 constexpr wpi::units::volt_t Voltage(
117 wpi::units::newton_meter_t torque,
118 wpi::units::radians_per_second_t velocity) const {
119 return 1.0 / Kv * velocity + 1.0 / Kt * R * torque;
120 }
121
122 /**
123 * Returns the angular velocity produced by the motor at a given torque and
124 * input voltage.
125 *
126 * @param torque The torque produced by the motor.
127 * @param inputVoltage The input voltage provided to the motor.
128 */
129 constexpr wpi::units::radians_per_second_t Velocity(
130 wpi::units::newton_meter_t torque,
131 wpi::units::volt_t inputVoltage) const {
132 return inputVoltage * Kv - 1.0 / Kt * torque * R * Kv;
133 }
134
135 /**
136 * Returns a copy of this motor with the given gearbox reduction applied.
137 *
138 * @param gearboxReduction The gearbox reduction.
139 */
140 constexpr DCMotor WithReduction(double gearboxReduction) {
141 return DCMotor(nominalVoltage, stallTorque * gearboxReduction, stallCurrent,
142 freeCurrent, freeSpeed / gearboxReduction);
143 }
144
145 /**
146 * Returns a gearbox of CIM motors.
147 */
148 static constexpr DCMotor CIM(int numMotors = 1) {
149 return DCMotor(12_V, 2.42_Nm, 133_A, 2.7_A, 5310_rpm, numMotors);
150 }
151
152 /**
153 * Returns a gearbox of MiniCIM motors.
154 */
155 static constexpr DCMotor MiniCIM(int numMotors = 1) {
156 return DCMotor(12_V, 1.41_Nm, 89_A, 3_A, 5840_rpm, numMotors);
157 }
158
159 /**
160 * Returns a gearbox of Bag motor motors.
161 */
162 static constexpr DCMotor Bag(int numMotors = 1) {
163 return DCMotor(12_V, 0.43_Nm, 53_A, 1.8_A, 13180_rpm, numMotors);
164 }
165
166 /**
167 * Returns a gearbox of Vex 775 Pro motors.
168 */
169 static constexpr DCMotor Vex775Pro(int numMotors = 1) {
170 return DCMotor(12_V, 0.71_Nm, 134_A, 0.7_A, 18730_rpm, numMotors);
171 }
172
173 /**
174 * Returns a gearbox of Andymark RS 775-125 motors.
175 */
176 static constexpr DCMotor RS775_125(int numMotors = 1) {
177 return DCMotor(12_V, 0.28_Nm, 18_A, 1.6_A, 5800_rpm, numMotors);
178 }
179
180 /**
181 * Returns a gearbox of Banebots RS 775 motors.
182 */
183 static constexpr DCMotor BanebotsRS775(int numMotors = 1) {
184 return DCMotor(12_V, 0.72_Nm, 97_A, 2.7_A, 13050_rpm, numMotors);
185 }
186
187 /**
188 * Returns a gearbox of Andymark 9015 motors.
189 */
190 static constexpr DCMotor Andymark9015(int numMotors = 1) {
191 return DCMotor(12_V, 0.36_Nm, 71_A, 3.7_A, 14270_rpm, numMotors);
192 }
193
194 /**
195 * Returns a gearbox of Banebots RS 550 motors.
196 */
197 static constexpr DCMotor BanebotsRS550(int numMotors = 1) {
198 return DCMotor(12_V, 0.38_Nm, 84_A, 0.4_A, 19000_rpm, numMotors);
199 }
200
201 /**
202 * Returns a gearbox of NEO brushless motors.
203 */
204 static constexpr DCMotor NEO(int numMotors = 1) {
205 return DCMotor(12_V, 2.6_Nm, 105_A, 1.8_A, 5676_rpm, numMotors);
206 }
207
208 /**
209 * Returns a gearbox of NEO 550 brushless motors.
210 */
211 static constexpr DCMotor NEO550(int numMotors = 1) {
212 return DCMotor(12_V, 0.97_Nm, 100_A, 1.4_A, 11000_rpm, numMotors);
213 }
214
215 /**
216 * Returns a gearbox of Falcon 500 brushless motors.
217 */
218 static constexpr DCMotor Falcon500(int numMotors = 1) {
219 return DCMotor(12_V, 4.69_Nm, 257_A, 1.5_A, 6380_rpm, numMotors);
220 }
221
222 /**
223 * Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control)
224 * enabled.
225 */
226 static constexpr DCMotor Falcon500FOC(int numMotors = 1) {
227 // https://store.ctr-electronics.com/falcon-500-powered-by-talon-fx/
228 return DCMotor(12_V, 5.84_Nm, 304_A, 1.5_A, 6080_rpm, numMotors);
229 }
230
231 /**
232 * Return a gearbox of Romi/TI_RSLK MAX motors.
233 */
234 static constexpr DCMotor RomiBuiltIn(int numMotors = 1) {
235 // From https://www.pololu.com/product/1520/specs
236 return DCMotor(4.5_V, 0.1765_Nm, 1.25_A, 0.13_A, 150_rpm, numMotors);
237 }
238
239 /**
240 * Return a gearbox of Kraken X60 brushless motors.
241 */
242 static constexpr DCMotor KrakenX60(int numMotors = 1) {
243 // From https://store.ctr-electronics.com/announcing-kraken-x60/
244 return DCMotor(12_V, 7.09_Nm, 366_A, 2_A, 6000_rpm, numMotors);
245 }
246
247 /**
248 * Return a gearbox of Kraken X60 brushless motors with FOC (Field-Oriented
249 * Control) enabled.
250 */
251 static constexpr DCMotor KrakenX60FOC(int numMotors = 1) {
252 // From https://store.ctr-electronics.com/announcing-kraken-x60/
253 return DCMotor(12_V, 9.37_Nm, 483_A, 2_A, 5800_rpm, numMotors);
254 }
255
256 /**
257 * Return a gearbox of Kraken X44 brushless motors.
258 */
259 static constexpr DCMotor KrakenX44(int numMotors = 1) {
260 // From https://motors.ctr-electronics.com/dyno/dynometer-testing/
261 return DCMotor(12_V, 4.11_Nm, 279_A, 2_A, 7758_rpm, numMotors);
262 }
263
264 /**
265 * Return a gearbox of Kraken X44 brushless motors with FOC (Field-Oriented
266 * Control) enabled.
267 */
268 static constexpr DCMotor KrakenX44FOC(int numMotors = 1) {
269 // From https://motors.ctr-electronics.com/dyno/dynometer-testing/
270 return DCMotor(12_V, 5.01_Nm, 329_A, 2_A, 7368_rpm, numMotors);
271 }
272
273 /**
274 * Return a gearbox of Minion brushless motors.
275 */
276 static constexpr DCMotor Minion(int numMotors = 1) {
277 // From https://motors.ctr-electronics.com/dyno/dynometer-testing/
278 return DCMotor(12_V, 3.17_Nm, 211_A, 2_A, 7704_rpm, numMotors);
279 }
280
281 /**
282 * Return a gearbox of Neo Vortex brushless motors.
283 */
284 static constexpr DCMotor NeoVortex(int numMotors = 1) {
285 // From https://www.revrobotics.com/next-generation-spark-neo/
286 return DCMotor(12_V, 3.60_Nm, 211_A, 3.615_A, 6784_rpm, numMotors);
287 }
288};
289
290} // namespace wpi::math
291
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
wpi::units::volt_t nominalVoltage
Voltage at which the motor constants were measured.
Definition DCMotor.hpp:29
wpi::units::newton_meter_t stallTorque
Torque when stalled.
Definition DCMotor.hpp:32
static constexpr DCMotor Falcon500FOC(int numMotors=1)
Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control) enabled.
Definition DCMotor.hpp:226
static constexpr DCMotor NeoVortex(int numMotors=1)
Return a gearbox of Neo Vortex brushless motors.
Definition DCMotor.hpp:284
radians_per_second_per_volt_t Kv
Motor velocity constant.
Definition DCMotor.hpp:47
static constexpr DCMotor MiniCIM(int numMotors=1)
Returns a gearbox of MiniCIM motors.
Definition DCMotor.hpp:155
static constexpr DCMotor Falcon500(int numMotors=1)
Returns a gearbox of Falcon 500 brushless motors.
Definition DCMotor.hpp:218
static constexpr DCMotor Andymark9015(int numMotors=1)
Returns a gearbox of Andymark 9015 motors.
Definition DCMotor.hpp:190
wpi::units::ampere_t freeCurrent
Current draw under no load.
Definition DCMotor.hpp:38
newton_meters_per_ampere_t Kt
Motor torque constant.
Definition DCMotor.hpp:50
static constexpr DCMotor NEO(int numMotors=1)
Returns a gearbox of NEO brushless motors.
Definition DCMotor.hpp:204
static constexpr DCMotor KrakenX60FOC(int numMotors=1)
Return a gearbox of Kraken X60 brushless motors with FOC (Field-Oriented Control) enabled.
Definition DCMotor.hpp:251
wpi::units::unit_t< wpi::units::compound_unit< wpi::units::radians_per_second, wpi::units::inverse< wpi::units::volt > > > radians_per_second_per_volt_t
Definition DCMotor.hpp:21
static constexpr DCMotor NEO550(int numMotors=1)
Returns a gearbox of NEO 550 brushless motors.
Definition DCMotor.hpp:211
constexpr wpi::units::volt_t Voltage(wpi::units::newton_meter_t torque, wpi::units::radians_per_second_t velocity) const
Returns the voltage provided to the motor for a given torque and angular velocity.
Definition DCMotor.hpp:116
static constexpr DCMotor Vex775Pro(int numMotors=1)
Returns a gearbox of Vex 775 Pro motors.
Definition DCMotor.hpp:169
constexpr wpi::units::newton_meter_t Torque(wpi::units::ampere_t current) const
Returns torque produced by the motor with a given current.
Definition DCMotor.hpp:104
static constexpr DCMotor Bag(int numMotors=1)
Returns a gearbox of Bag motor motors.
Definition DCMotor.hpp:162
constexpr wpi::units::ampere_t Current(wpi::units::radians_per_second_t velocity, wpi::units::volt_t inputVoltage) const
Returns current drawn by motor with given velocity and input voltage.
Definition DCMotor.hpp:83
static constexpr DCMotor CIM(int numMotors=1)
Returns a gearbox of CIM motors.
Definition DCMotor.hpp:148
wpi::units::ampere_t stallCurrent
Current draw when stalled.
Definition DCMotor.hpp:35
constexpr wpi::units::ampere_t Current(wpi::units::newton_meter_t torque) const
Returns current drawn by motor for a given torque.
Definition DCMotor.hpp:94
wpi::units::ohm_t R
Motor internal resistance.
Definition DCMotor.hpp:44
static constexpr DCMotor RomiBuiltIn(int numMotors=1)
Return a gearbox of Romi/TI_RSLK MAX motors.
Definition DCMotor.hpp:234
wpi::units::unit_t< wpi::units::compound_unit< wpi::units::newton_meters, wpi::units::inverse< wpi::units::ampere > > > newton_meters_per_ampere_t
Definition DCMotor.hpp:24
static constexpr DCMotor RS775_125(int numMotors=1)
Returns a gearbox of Andymark RS 775-125 motors.
Definition DCMotor.hpp:176
constexpr wpi::units::radians_per_second_t Velocity(wpi::units::newton_meter_t torque, wpi::units::volt_t inputVoltage) const
Returns the angular velocity produced by the motor at a given torque and input voltage.
Definition DCMotor.hpp:129
static constexpr DCMotor KrakenX60(int numMotors=1)
Return a gearbox of Kraken X60 brushless motors.
Definition DCMotor.hpp:242
static constexpr DCMotor KrakenX44FOC(int numMotors=1)
Return a gearbox of Kraken X44 brushless motors with FOC (Field-Oriented Control) enabled.
Definition DCMotor.hpp:268
static constexpr DCMotor BanebotsRS775(int numMotors=1)
Returns a gearbox of Banebots RS 775 motors.
Definition DCMotor.hpp:183
constexpr DCMotor WithReduction(double gearboxReduction)
Returns a copy of this motor with the given gearbox reduction applied.
Definition DCMotor.hpp:140
static constexpr DCMotor Minion(int numMotors=1)
Return a gearbox of Minion brushless motors.
Definition DCMotor.hpp:276
static constexpr DCMotor KrakenX44(int numMotors=1)
Return a gearbox of Kraken X44 brushless motors.
Definition DCMotor.hpp:259
constexpr DCMotor(wpi::units::volt_t nominalVoltage, wpi::units::newton_meter_t stallTorque, wpi::units::ampere_t stallCurrent, wpi::units::ampere_t freeCurrent, wpi::units::radians_per_second_t freeSpeed, int numMotors=1)
Constructs a DC motor.
Definition DCMotor.hpp:62
wpi::units::radians_per_second_t freeSpeed
Angular velocity under no load.
Definition DCMotor.hpp:41
static constexpr DCMotor BanebotsRS550(int numMotors=1)
Returns a gearbox of Banebots RS 550 motors.
Definition DCMotor.hpp:197
Definition LinearSystem.hpp:20