-
Notifications
You must be signed in to change notification settings - Fork 607
/
DCMotor.java
241 lines (219 loc) · 7.74 KB
/
DCMotor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.math.system.plant;
import edu.wpi.first.math.util.Units;
/** Holds the constants for a DC motor. */
public class DCMotor {
public final double nominalVoltageVolts;
public final double stallTorqueNewtonMeters;
public final double stallCurrentAmps;
public final double freeCurrentAmps;
public final double freeSpeedRadPerSec;
public final double rOhms;
public final double KvRadPerSecPerVolt;
public final double KtNMPerAmp;
/**
* Constructs a DC motor.
*
* @param nominalVoltageVolts Voltage at which the motor constants were measured.
* @param stallTorqueNewtonMeters Current draw when stalled.
* @param stallCurrentAmps Current draw when stalled.
* @param freeCurrentAmps Current draw under no load.
* @param freeSpeedRadPerSec Angular velocity under no load.
* @param numMotors Number of motors in a gearbox.
*/
public DCMotor(
double nominalVoltageVolts,
double stallTorqueNewtonMeters,
double stallCurrentAmps,
double freeCurrentAmps,
double freeSpeedRadPerSec,
int numMotors) {
this.nominalVoltageVolts = nominalVoltageVolts;
this.stallTorqueNewtonMeters = stallTorqueNewtonMeters * numMotors;
this.stallCurrentAmps = stallCurrentAmps * numMotors;
this.freeCurrentAmps = freeCurrentAmps * numMotors;
this.freeSpeedRadPerSec = freeSpeedRadPerSec;
this.rOhms = nominalVoltageVolts / this.stallCurrentAmps;
this.KvRadPerSecPerVolt =
freeSpeedRadPerSec / (nominalVoltageVolts - rOhms * this.freeCurrentAmps);
this.KtNMPerAmp = this.stallTorqueNewtonMeters / this.stallCurrentAmps;
}
/**
* Estimate the current being drawn by this motor.
*
* @param speedRadiansPerSec The speed of the motor.
* @param voltageInputVolts The input voltage.
* @return The estimated current.
*/
public double getCurrent(double speedRadiansPerSec, double voltageInputVolts) {
return -1.0 / KvRadPerSecPerVolt / rOhms * speedRadiansPerSec + 1.0 / rOhms * voltageInputVolts;
}
/**
* Calculate the torque produced by the motor for a given current.
*
* @param currentAmpere The current drawn by the motor.
* @return The torque produced.
*/
public double getTorque(double currentAmpere) {
return currentAmpere * KtNMPerAmp;
}
/**
* Calculate the voltage provided to the motor at a given torque and angular velocity.
*
* @param torqueNm The torque produced by the motor.
* @param speedRadiansPerSec The speed of the motor.
* @return The voltage of the motor.
*/
public double getVoltage(double torqueNm, double speedRadiansPerSec) {
return 1.0 / KvRadPerSecPerVolt * speedRadiansPerSec + 1.0 / KtNMPerAmp * rOhms * torqueNm;
}
/**
* Calculate the speed of the motor at a given torque and input voltage.
*
* @param torqueNm The torque produced by the motor.
* @param voltageInputVolts The voltage applied to the motor.
* @return The speed of the motor.
*/
public double getSpeed(double torqueNm, double voltageInputVolts) {
return voltageInputVolts * KvRadPerSecPerVolt
- 1.0 / KtNMPerAmp * torqueNm * rOhms * KvRadPerSecPerVolt;
}
/**
* Returns a copy of this motor with the given gearbox reduction applied.
*
* @param gearboxReduction The gearbox reduction.
* @return A motor with the gearbox reduction applied.
*/
public DCMotor withReduction(double gearboxReduction) {
return new DCMotor(
nominalVoltageVolts,
stallTorqueNewtonMeters * gearboxReduction,
stallCurrentAmps,
freeCurrentAmps,
freeSpeedRadPerSec / gearboxReduction,
1);
}
/**
* Return a gearbox of CIM motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of CIM motors.
*/
public static DCMotor getCIM(int numMotors) {
return new DCMotor(
12, 2.42, 133, 2.7, Units.rotationsPerMinuteToRadiansPerSecond(5310), numMotors);
}
/**
* Return a gearbox of 775Pro motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of 775Pro motors.
*/
public static DCMotor getVex775Pro(int numMotors) {
return new DCMotor(
12, 0.71, 134, 0.7, Units.rotationsPerMinuteToRadiansPerSecond(18730), numMotors);
}
/**
* Return a gearbox of NEO motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of NEO motors.
*/
public static DCMotor getNEO(int numMotors) {
return new DCMotor(
12, 2.6, 105, 1.8, Units.rotationsPerMinuteToRadiansPerSecond(5676), numMotors);
}
/**
* Return a gearbox of MiniCIM motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of MiniCIM motors.
*/
public static DCMotor getMiniCIM(int numMotors) {
return new DCMotor(
12, 1.41, 89, 3, Units.rotationsPerMinuteToRadiansPerSecond(5840), numMotors);
}
/**
* Return a gearbox of Bag motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Bag motors.
*/
public static DCMotor getBag(int numMotors) {
return new DCMotor(
12, 0.43, 53, 1.8, Units.rotationsPerMinuteToRadiansPerSecond(13180), numMotors);
}
/**
* Return a gearbox of Andymark RS775-125 motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Andymark RS775-125 motors.
*/
public static DCMotor getAndymarkRs775_125(int numMotors) {
return new DCMotor(
12, 0.28, 18, 1.6, Units.rotationsPerMinuteToRadiansPerSecond(5800.0), numMotors);
}
/**
* Return a gearbox of Banebots RS775 motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Banebots RS775 motors.
*/
public static DCMotor getBanebotsRs775(int numMotors) {
return new DCMotor(
12, 0.72, 97, 2.7, Units.rotationsPerMinuteToRadiansPerSecond(13050.0), numMotors);
}
/**
* Return a gearbox of Andymark 9015 motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Andymark 9015 motors.
*/
public static DCMotor getAndymark9015(int numMotors) {
return new DCMotor(
12, 0.36, 71, 3.7, Units.rotationsPerMinuteToRadiansPerSecond(14270.0), numMotors);
}
/**
* Return a gearbox of Banebots RS 550 motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Banebots RS 550 motors.
*/
public static DCMotor getBanebotsRs550(int numMotors) {
return new DCMotor(
12, 0.38, 84, 0.4, Units.rotationsPerMinuteToRadiansPerSecond(19000.0), numMotors);
}
/**
* Return a gearbox of NEO 550 motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of NEO 550 motors.
*/
public static DCMotor getNeo550(int numMotors) {
return new DCMotor(
12, 0.97, 100, 1.4, Units.rotationsPerMinuteToRadiansPerSecond(11000.0), numMotors);
}
/**
* Return a gearbox of Falcon 500 motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Falcon 500 motors.
*/
public static DCMotor getFalcon500(int numMotors) {
return new DCMotor(
12, 4.69, 257, 1.5, Units.rotationsPerMinuteToRadiansPerSecond(6380.0), numMotors);
}
/**
* Return a gearbox of Romi/TI_RSLK MAX motors.
*
* @param numMotors Number of motors in the gearbox.
* @return A gearbox of Romi/TI_RSLK MAX motors.
*/
public static DCMotor getRomiBuiltIn(int numMotors) {
// From https://www.pololu.com/product/1520/specs
return new DCMotor(
4.5, 0.1765, 1.25, 0.13, Units.rotationsPerMinuteToRadiansPerSecond(150.0), numMotors);
}
}