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