WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
DCMotor.h
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/SymbolExports.h>
8
10#include "units/current.h"
11#include "units/impedance.h"
12#include "units/torque.h"
13#include "units/voltage.h"
14
15namespace frc {
16
17/**
18 * Holds the constants for a DC motor.
19 */
21 public:
23 units::unit_t<units::compound_unit<units::radians_per_second,
26 units::unit_t<units::compound_unit<units::newton_meters,
28
29 /// Voltage at which the motor constants were measured.
30 units::volt_t nominalVoltage;
31
32 /// Torque when stalled.
33 units::newton_meter_t stallTorque;
34
35 /// Current draw when stalled.
36 units::ampere_t stallCurrent;
37
38 /// Current draw under no load.
39 units::ampere_t freeCurrent;
40
41 /// Angular velocity under no load.
42 units::radians_per_second_t freeSpeed;
43
44 /// Motor internal resistance.
45 units::ohm_t R;
46
47 /// Motor velocity constant.
49
50 /// Motor torque constant.
52
53 /**
54 * Constructs a DC motor.
55 *
56 * @param nominalVoltage Voltage at which the motor constants were measured.
57 * @param stallTorque Torque when stalled.
58 * @param stallCurrent Current draw when stalled.
59 * @param freeCurrent Current draw under no load.
60 * @param freeSpeed Angular velocity under no load.
61 * @param numMotors Number of motors in a gearbox.
62 */
63 constexpr DCMotor(units::volt_t nominalVoltage,
64 units::newton_meter_t stallTorque,
65 units::ampere_t stallCurrent, units::ampere_t freeCurrent,
66 units::radians_per_second_t freeSpeed, int numMotors = 1)
67 : nominalVoltage(nominalVoltage),
68 stallTorque(stallTorque * numMotors),
69 stallCurrent(stallCurrent * numMotors),
70 freeCurrent(freeCurrent * numMotors),
71 freeSpeed(freeSpeed),
72 R(nominalVoltage / this->stallCurrent),
73 Kv(freeSpeed / (nominalVoltage - R * this->freeCurrent)),
74 Kt(this->stallTorque / this->stallCurrent) {}
75
76 /**
77 * Returns current drawn by motor with given speed and input voltage.
78 *
79 * @param speed The current angular velocity of the motor.
80 * @param inputVoltage The voltage being applied to the motor.
81 */
82 constexpr units::ampere_t Current(units::radians_per_second_t speed,
83 units::volt_t inputVoltage) const {
84 return -1.0 / Kv / R * speed + 1.0 / R * inputVoltage;
85 }
86
87 /**
88 * Returns current drawn by motor for a given torque.
89 *
90 * @param torque The torque produced by the motor.
91 */
92 constexpr units::ampere_t Current(units::newton_meter_t torque) const {
93 return torque / Kt;
94 }
95
96 /**
97 * Returns torque produced by the motor with a given current.
98 *
99 * @param current The current drawn by the motor.
100 */
101 constexpr units::newton_meter_t Torque(units::ampere_t current) const {
102 return current * Kt;
103 }
104
105 /**
106 * Returns the voltage provided to the motor for a given torque and
107 * angular velocity.
108 *
109 * @param torque The torque produced by the motor.
110 * @param speed The current angular velocity of the motor.
111 */
112 constexpr units::volt_t Voltage(units::newton_meter_t torque,
113 units::radians_per_second_t speed) const {
114 return 1.0 / Kv * speed + 1.0 / Kt * R * torque;
115 }
116
117 /**
118 * Returns the angular speed produced by the motor at a given torque and input
119 * voltage.
120 *
121 * @param torque The torque produced by the motor.
122 * @param inputVoltage The input voltage provided to the motor.
123 */
124 constexpr units::radians_per_second_t Speed(
125 units::newton_meter_t torque, units::volt_t inputVoltage) const {
126 return inputVoltage * Kv - 1.0 / Kt * torque * R * Kv;
127 }
128
129 /**
130 * Returns a copy of this motor with the given gearbox reduction applied.
131 *
132 * @param gearboxReduction The gearbox reduction.
133 */
134 constexpr DCMotor WithReduction(double gearboxReduction) {
135 return DCMotor(nominalVoltage, stallTorque * gearboxReduction, stallCurrent,
136 freeCurrent, freeSpeed / gearboxReduction);
137 }
138
139 /**
140 * Returns a gearbox of CIM motors.
141 */
142 static constexpr DCMotor CIM(int numMotors = 1) {
143 return DCMotor(12_V, 2.42_Nm, 133_A, 2.7_A, 5310_rpm, numMotors);
144 }
145
146 /**
147 * Returns a gearbox of MiniCIM motors.
148 */
149 static constexpr DCMotor MiniCIM(int numMotors = 1) {
150 return DCMotor(12_V, 1.41_Nm, 89_A, 3_A, 5840_rpm, numMotors);
151 }
152
153 /**
154 * Returns a gearbox of Bag motor motors.
155 */
156 static constexpr DCMotor Bag(int numMotors = 1) {
157 return DCMotor(12_V, 0.43_Nm, 53_A, 1.8_A, 13180_rpm, numMotors);
158 }
159
160 /**
161 * Returns a gearbox of Vex 775 Pro motors.
162 */
163 static constexpr DCMotor Vex775Pro(int numMotors = 1) {
164 return DCMotor(12_V, 0.71_Nm, 134_A, 0.7_A, 18730_rpm, numMotors);
165 }
166
167 /**
168 * Returns a gearbox of Andymark RS 775-125 motors.
169 */
170 static constexpr DCMotor RS775_125(int numMotors = 1) {
171 return DCMotor(12_V, 0.28_Nm, 18_A, 1.6_A, 5800_rpm, numMotors);
172 }
173
174 /**
175 * Returns a gearbox of Banebots RS 775 motors.
176 */
177 static constexpr DCMotor BanebotsRS775(int numMotors = 1) {
178 return DCMotor(12_V, 0.72_Nm, 97_A, 2.7_A, 13050_rpm, numMotors);
179 }
180
181 /**
182 * Returns a gearbox of Andymark 9015 motors.
183 */
184 static constexpr DCMotor Andymark9015(int numMotors = 1) {
185 return DCMotor(12_V, 0.36_Nm, 71_A, 3.7_A, 14270_rpm, numMotors);
186 }
187
188 /**
189 * Returns a gearbox of Banebots RS 550 motors.
190 */
191 static constexpr DCMotor BanebotsRS550(int numMotors = 1) {
192 return DCMotor(12_V, 0.38_Nm, 84_A, 0.4_A, 19000_rpm, numMotors);
193 }
194
195 /**
196 * Returns a gearbox of NEO brushless motors.
197 */
198 static constexpr DCMotor NEO(int numMotors = 1) {
199 return DCMotor(12_V, 2.6_Nm, 105_A, 1.8_A, 5676_rpm, numMotors);
200 }
201
202 /**
203 * Returns a gearbox of NEO 550 brushless motors.
204 */
205 static constexpr DCMotor NEO550(int numMotors = 1) {
206 return DCMotor(12_V, 0.97_Nm, 100_A, 1.4_A, 11000_rpm, numMotors);
207 }
208
209 /**
210 * Returns a gearbox of Falcon 500 brushless motors.
211 */
212 static constexpr DCMotor Falcon500(int numMotors = 1) {
213 return DCMotor(12_V, 4.69_Nm, 257_A, 1.5_A, 6380_rpm, numMotors);
214 }
215
216 /**
217 * Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control)
218 * enabled.
219 */
220 static constexpr DCMotor Falcon500FOC(int numMotors = 1) {
221 // https://store.ctr-electronics.com/falcon-500-powered-by-talon-fx/
222 return DCMotor(12_V, 5.84_Nm, 304_A, 1.5_A, 6080_rpm, numMotors);
223 }
224
225 /**
226 * Return a gearbox of Romi/TI_RSLK MAX motors.
227 */
228 static constexpr DCMotor RomiBuiltIn(int numMotors = 1) {
229 // From https://www.pololu.com/product/1520/specs
230 return DCMotor(4.5_V, 0.1765_Nm, 1.25_A, 0.13_A, 150_rpm, numMotors);
231 }
232
233 /**
234 * Return a gearbox of Kraken X60 brushless motors.
235 */
236 static constexpr DCMotor KrakenX60(int numMotors = 1) {
237 // From https://store.ctr-electronics.com/announcing-kraken-x60/
238 return DCMotor(12_V, 7.09_Nm, 366_A, 2_A, 6000_rpm, numMotors);
239 }
240
241 /**
242 * Return a gearbox of Kraken X60 brushless motors with FOC (Field-Oriented
243 * Control) enabled.
244 */
245 static constexpr DCMotor KrakenX60FOC(int numMotors = 1) {
246 // From https://store.ctr-electronics.com/announcing-kraken-x60/
247 return DCMotor(12_V, 9.37_Nm, 483_A, 2_A, 5800_rpm, numMotors);
248 }
249
250 /**
251 * Return a gearbox of Neo Vortex brushless motors.
252 */
253 static constexpr DCMotor NeoVortex(int numMotors = 1) {
254 // From https://www.revrobotics.com/next-generation-spark-neo/
255 return DCMotor(12_V, 3.60_Nm, 211_A, 3.615_A, 6784_rpm, numMotors);
256 }
257};
258
259} // namespace frc
260
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Holds the constants for a DC motor.
Definition DCMotor.h:20
static constexpr DCMotor Falcon500(int numMotors=1)
Returns a gearbox of Falcon 500 brushless motors.
Definition DCMotor.h:212
constexpr units::newton_meter_t Torque(units::ampere_t current) const
Returns torque produced by the motor with a given current.
Definition DCMotor.h:101
units::radians_per_second_t freeSpeed
Angular velocity under no load.
Definition DCMotor.h:42
constexpr units::volt_t Voltage(units::newton_meter_t torque, units::radians_per_second_t speed) const
Returns the voltage provided to the motor for a given torque and angular velocity.
Definition DCMotor.h:112
static constexpr DCMotor Falcon500FOC(int numMotors=1)
Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control) enabled.
Definition DCMotor.h:220
static constexpr DCMotor Bag(int numMotors=1)
Returns a gearbox of Bag motor motors.
Definition DCMotor.h:156
static constexpr DCMotor Andymark9015(int numMotors=1)
Returns a gearbox of Andymark 9015 motors.
Definition DCMotor.h:184
static constexpr DCMotor BanebotsRS775(int numMotors=1)
Returns a gearbox of Banebots RS 775 motors.
Definition DCMotor.h:177
static constexpr DCMotor KrakenX60(int numMotors=1)
Return a gearbox of Kraken X60 brushless motors.
Definition DCMotor.h:236
units::ampere_t freeCurrent
Current draw under no load.
Definition DCMotor.h:39
static constexpr DCMotor Vex775Pro(int numMotors=1)
Returns a gearbox of Vex 775 Pro motors.
Definition DCMotor.h:163
constexpr DCMotor(units::volt_t nominalVoltage, units::newton_meter_t stallTorque, units::ampere_t stallCurrent, units::ampere_t freeCurrent, units::radians_per_second_t freeSpeed, int numMotors=1)
Constructs a DC motor.
Definition DCMotor.h:63
static constexpr DCMotor CIM(int numMotors=1)
Returns a gearbox of CIM motors.
Definition DCMotor.h:142
constexpr DCMotor WithReduction(double gearboxReduction)
Returns a copy of this motor with the given gearbox reduction applied.
Definition DCMotor.h:134
static constexpr DCMotor NEO(int numMotors=1)
Returns a gearbox of NEO brushless motors.
Definition DCMotor.h:198
units::ampere_t stallCurrent
Current draw when stalled.
Definition DCMotor.h:36
static constexpr DCMotor RS775_125(int numMotors=1)
Returns a gearbox of Andymark RS 775-125 motors.
Definition DCMotor.h:170
constexpr units::ampere_t Current(units::newton_meter_t torque) const
Returns current drawn by motor for a given torque.
Definition DCMotor.h:92
units::newton_meter_t stallTorque
Torque when stalled.
Definition DCMotor.h:33
radians_per_second_per_volt_t Kv
Motor velocity constant.
Definition DCMotor.h:48
static constexpr DCMotor NeoVortex(int numMotors=1)
Return a gearbox of Neo Vortex brushless motors.
Definition DCMotor.h:253
constexpr units::radians_per_second_t Speed(units::newton_meter_t torque, units::volt_t inputVoltage) const
Returns the angular speed produced by the motor at a given torque and input voltage.
Definition DCMotor.h:124
static constexpr DCMotor RomiBuiltIn(int numMotors=1)
Return a gearbox of Romi/TI_RSLK MAX motors.
Definition DCMotor.h:228
constexpr units::ampere_t Current(units::radians_per_second_t speed, units::volt_t inputVoltage) const
Returns current drawn by motor with given speed and input voltage.
Definition DCMotor.h:82
static constexpr DCMotor NEO550(int numMotors=1)
Returns a gearbox of NEO 550 brushless motors.
Definition DCMotor.h:205
units::volt_t nominalVoltage
Voltage at which the motor constants were measured.
Definition DCMotor.h:30
units::ohm_t R
Motor internal resistance.
Definition DCMotor.h:45
static constexpr DCMotor KrakenX60FOC(int numMotors=1)
Return a gearbox of Kraken X60 brushless motors with FOC (Field-Oriented Control) enabled.
Definition DCMotor.h:245
static constexpr DCMotor MiniCIM(int numMotors=1)
Returns a gearbox of MiniCIM motors.
Definition DCMotor.h:149
static constexpr DCMotor BanebotsRS550(int numMotors=1)
Returns a gearbox of Banebots RS 550 motors.
Definition DCMotor.h:191
newton_meters_per_ampere_t Kt
Motor torque constant.
Definition DCMotor.h:51
typename units::detail::inverse_impl< U >::type inverse
represents the inverse unit type of class U.
Definition base.h:1138
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition base.h:1438
Definition CAN.h:11