WPILibC++ 2024.3.2
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 torque produced by the motor with a given current.
89 *
90 * @param current The current drawn by the motor.
91 */
92 constexpr units::newton_meter_t Torque(units::ampere_t current) const {
93 return current * Kt;
94 }
95
96 /**
97 * Returns the voltage provided to the motor for a given torque and
98 * angular velocity.
99 *
100 * @param torque The torque produced by the motor.
101 * @param speed The current angular velocity of the motor.
102 */
103 constexpr units::volt_t Voltage(units::newton_meter_t torque,
104 units::radians_per_second_t speed) const {
105 return 1.0 / Kv * speed + 1.0 / Kt * R * torque;
106 }
107
108 /**
109 * Returns the angular speed produced by the motor at a given torque and input
110 * voltage.
111 *
112 * @param torque The torque produced by the motor.
113 * @param inputVoltage The input voltage provided to the motor.
114 */
115 constexpr units::radians_per_second_t Speed(
116 units::newton_meter_t torque, units::volt_t inputVoltage) const {
117 return inputVoltage * Kv - 1.0 / Kt * torque * R * Kv;
118 }
119
120 /**
121 * Returns a copy of this motor with the given gearbox reduction applied.
122 *
123 * @param gearboxReduction The gearbox reduction.
124 */
125 constexpr DCMotor WithReduction(double gearboxReduction) {
126 return DCMotor(nominalVoltage, stallTorque * gearboxReduction, stallCurrent,
127 freeCurrent, freeSpeed / gearboxReduction);
128 }
129
130 /**
131 * Returns a gearbox of CIM motors.
132 */
133 static constexpr DCMotor CIM(int numMotors = 1) {
134 return DCMotor(12_V, 2.42_Nm, 133_A, 2.7_A, 5310_rpm, numMotors);
135 }
136
137 /**
138 * Returns a gearbox of MiniCIM motors.
139 */
140 static constexpr DCMotor MiniCIM(int numMotors = 1) {
141 return DCMotor(12_V, 1.41_Nm, 89_A, 3_A, 5840_rpm, numMotors);
142 }
143
144 /**
145 * Returns a gearbox of Bag motor motors.
146 */
147 static constexpr DCMotor Bag(int numMotors = 1) {
148 return DCMotor(12_V, 0.43_Nm, 53_A, 1.8_A, 13180_rpm, numMotors);
149 }
150
151 /**
152 * Returns a gearbox of Vex 775 Pro motors.
153 */
154 static constexpr DCMotor Vex775Pro(int numMotors = 1) {
155 return DCMotor(12_V, 0.71_Nm, 134_A, 0.7_A, 18730_rpm, numMotors);
156 }
157
158 /**
159 * Returns a gearbox of Andymark RS 775-125 motors.
160 */
161 static constexpr DCMotor RS775_125(int numMotors = 1) {
162 return DCMotor(12_V, 0.28_Nm, 18_A, 1.6_A, 5800_rpm, numMotors);
163 }
164
165 /**
166 * Returns a gearbox of Banebots RS 775 motors.
167 */
168 static constexpr DCMotor BanebotsRS775(int numMotors = 1) {
169 return DCMotor(12_V, 0.72_Nm, 97_A, 2.7_A, 13050_rpm, numMotors);
170 }
171
172 /**
173 * Returns a gearbox of Andymark 9015 motors.
174 */
175 static constexpr DCMotor Andymark9015(int numMotors = 1) {
176 return DCMotor(12_V, 0.36_Nm, 71_A, 3.7_A, 14270_rpm, numMotors);
177 }
178
179 /**
180 * Returns a gearbox of Banebots RS 550 motors.
181 */
182 static constexpr DCMotor BanebotsRS550(int numMotors = 1) {
183 return DCMotor(12_V, 0.38_Nm, 84_A, 0.4_A, 19000_rpm, numMotors);
184 }
185
186 /**
187 * Returns a gearbox of NEO brushless motors.
188 */
189 static constexpr DCMotor NEO(int numMotors = 1) {
190 return DCMotor(12_V, 2.6_Nm, 105_A, 1.8_A, 5676_rpm, numMotors);
191 }
192
193 /**
194 * Returns a gearbox of NEO 550 brushless motors.
195 */
196 static constexpr DCMotor NEO550(int numMotors = 1) {
197 return DCMotor(12_V, 0.97_Nm, 100_A, 1.4_A, 11000_rpm, numMotors);
198 }
199
200 /**
201 * Returns a gearbox of Falcon 500 brushless motors.
202 */
203 static constexpr DCMotor Falcon500(int numMotors = 1) {
204 return DCMotor(12_V, 4.69_Nm, 257_A, 1.5_A, 6380_rpm, numMotors);
205 }
206
207 /**
208 * Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control)
209 * enabled.
210 */
211 static constexpr DCMotor Falcon500FOC(int numMotors = 1) {
212 // https://store.ctr-electronics.com/falcon-500-powered-by-talon-fx/
213 return DCMotor(12_V, 5.84_Nm, 304_A, 1.5_A, 6080_rpm, numMotors);
214 }
215
216 /**
217 * Return a gearbox of Romi/TI_RSLK MAX motors.
218 */
219 static constexpr DCMotor RomiBuiltIn(int numMotors = 1) {
220 // From https://www.pololu.com/product/1520/specs
221 return DCMotor(4.5_V, 0.1765_Nm, 1.25_A, 0.13_A, 150_rpm, numMotors);
222 }
223
224 /**
225 * Return a gearbox of Kraken X60 brushless motors.
226 */
227 static constexpr DCMotor KrakenX60(int numMotors = 1) {
228 // From https://store.ctr-electronics.com/announcing-kraken-x60/
229 return DCMotor(12_V, 7.09_Nm, 366_A, 2_A, 6000_rpm, numMotors);
230 }
231
232 /**
233 * Return a gearbox of Kraken X60 brushless motors with FOC (Field-Oriented
234 * Control) enabled.
235 */
236 static constexpr DCMotor KrakenX60FOC(int numMotors = 1) {
237 // From https://store.ctr-electronics.com/announcing-kraken-x60/
238 return DCMotor(12_V, 9.37_Nm, 483_A, 2_A, 5800_rpm, numMotors);
239 }
240
241 /**
242 * Return a gearbox of Neo Vortex brushless motors.
243 */
244 static constexpr DCMotor NeoVortex(int numMotors = 1) {
245 // From https://www.revrobotics.com/next-generation-spark-neo/
246 return DCMotor(12_V, 3.60_Nm, 211_A, 3.615_A, 6784_rpm, numMotors);
247 }
248};
249
250} // namespace frc
251
#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:203
constexpr units::newton_meter_t Torque(units::ampere_t current) const
Returns torque produced by the motor with a given current.
Definition: DCMotor.h:92
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:103
static constexpr DCMotor Falcon500FOC(int numMotors=1)
Return a gearbox of Falcon 500 motors with FOC (Field-Oriented Control) enabled.
Definition: DCMotor.h:211
static constexpr DCMotor Bag(int numMotors=1)
Returns a gearbox of Bag motor motors.
Definition: DCMotor.h:147
static constexpr DCMotor Andymark9015(int numMotors=1)
Returns a gearbox of Andymark 9015 motors.
Definition: DCMotor.h:175
static constexpr DCMotor BanebotsRS775(int numMotors=1)
Returns a gearbox of Banebots RS 775 motors.
Definition: DCMotor.h:168
static constexpr DCMotor KrakenX60(int numMotors=1)
Return a gearbox of Kraken X60 brushless motors.
Definition: DCMotor.h:227
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:154
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:133
constexpr DCMotor WithReduction(double gearboxReduction)
Returns a copy of this motor with the given gearbox reduction applied.
Definition: DCMotor.h:125
static constexpr DCMotor NEO(int numMotors=1)
Returns a gearbox of NEO brushless motors.
Definition: DCMotor.h:189
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:161
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:244
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:115
static constexpr DCMotor RomiBuiltIn(int numMotors=1)
Return a gearbox of Romi/TI_RSLK MAX motors.
Definition: DCMotor.h:219
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:196
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:236
static constexpr DCMotor MiniCIM(int numMotors=1)
Returns a gearbox of MiniCIM motors.
Definition: DCMotor.h:140
static constexpr DCMotor BanebotsRS550(int numMotors=1)
Returns a gearbox of Banebots RS 550 motors.
Definition: DCMotor.h:182
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:1134
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition: base.h:1434
Definition: AprilTagPoseEstimator.h:15
static constexpr const unit_t< compound_unit< energy::joules, inverse< temperature::kelvin >, inverse< substance::moles > > > R(8.3144598)
Gas constant.