001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math.system.plant;
006
007import edu.wpi.first.math.util.Units;
008
009/** Holds the constants for a DC motor. */
010public class DCMotor {
011  @SuppressWarnings("MemberName")
012  public final double nominalVoltageVolts;
013
014  @SuppressWarnings("MemberName")
015  public final double stallTorqueNewtonMeters;
016
017  @SuppressWarnings("MemberName")
018  public final double stallCurrentAmps;
019
020  @SuppressWarnings("MemberName")
021  public final double freeCurrentAmps;
022
023  @SuppressWarnings("MemberName")
024  public final double freeSpeedRadPerSec;
025
026  @SuppressWarnings("MemberName")
027  public final double rOhms;
028
029  @SuppressWarnings("MemberName")
030  public final double KvRadPerSecPerVolt;
031
032  @SuppressWarnings("MemberName")
033  public final double KtNMPerAmp;
034
035  /**
036   * Constructs a DC motor.
037   *
038   * @param nominalVoltageVolts Voltage at which the motor constants were measured.
039   * @param stallTorqueNewtonMeters Current draw when stalled.
040   * @param stallCurrentAmps Current draw when stalled.
041   * @param freeCurrentAmps Current draw under no load.
042   * @param freeSpeedRadPerSec Angular velocity under no load.
043   * @param numMotors Number of motors in a gearbox.
044   */
045  public DCMotor(
046      double nominalVoltageVolts,
047      double stallTorqueNewtonMeters,
048      double stallCurrentAmps,
049      double freeCurrentAmps,
050      double freeSpeedRadPerSec,
051      int numMotors) {
052    this.nominalVoltageVolts = nominalVoltageVolts;
053    this.stallTorqueNewtonMeters = stallTorqueNewtonMeters * numMotors;
054    this.stallCurrentAmps = stallCurrentAmps * numMotors;
055    this.freeCurrentAmps = freeCurrentAmps * numMotors;
056    this.freeSpeedRadPerSec = freeSpeedRadPerSec;
057
058    this.rOhms = nominalVoltageVolts / this.stallCurrentAmps;
059    this.KvRadPerSecPerVolt =
060        freeSpeedRadPerSec / (nominalVoltageVolts - rOhms * this.freeCurrentAmps);
061    this.KtNMPerAmp = this.stallTorqueNewtonMeters / this.stallCurrentAmps;
062  }
063
064  /**
065   * Estimate the current being drawn by this motor.
066   *
067   * @param speedRadiansPerSec The speed of the rotor.
068   * @param voltageInputVolts The input voltage.
069   * @return The estimated current.
070   */
071  public double getCurrent(double speedRadiansPerSec, double voltageInputVolts) {
072    return -1.0 / KvRadPerSecPerVolt / rOhms * speedRadiansPerSec + 1.0 / rOhms * voltageInputVolts;
073  }
074
075  /**
076   * Return a gearbox of CIM motors.
077   *
078   * @param numMotors Number of motors in the gearbox.
079   * @return A gearbox of CIM motors.
080   */
081  public static DCMotor getCIM(int numMotors) {
082    return new DCMotor(
083        12, 2.42, 133, 2.7, Units.rotationsPerMinuteToRadiansPerSecond(5310), numMotors);
084  }
085
086  /**
087   * Return a gearbox of 775Pro motors.
088   *
089   * @param numMotors Number of motors in the gearbox.
090   * @return A gearbox of 775Pro motors.
091   */
092  public static DCMotor getVex775Pro(int numMotors) {
093    return new DCMotor(
094        12, 0.71, 134, 0.7, Units.rotationsPerMinuteToRadiansPerSecond(18730), numMotors);
095  }
096
097  /**
098   * Return a gearbox of NEO motors.
099   *
100   * @param numMotors Number of motors in the gearbox.
101   * @return A gearbox of NEO motors.
102   */
103  public static DCMotor getNEO(int numMotors) {
104    return new DCMotor(
105        12, 2.6, 105, 1.8, Units.rotationsPerMinuteToRadiansPerSecond(5676), numMotors);
106  }
107
108  /**
109   * Return a gearbox of MiniCIM motors.
110   *
111   * @param numMotors Number of motors in the gearbox.
112   * @return A gearbox of MiniCIM motors.
113   */
114  public static DCMotor getMiniCIM(int numMotors) {
115    return new DCMotor(
116        12, 1.41, 89, 3, Units.rotationsPerMinuteToRadiansPerSecond(5840), numMotors);
117  }
118
119  /**
120   * Return a gearbox of Bag motors.
121   *
122   * @param numMotors Number of motors in the gearbox.
123   * @return A gearbox of Bag motors.
124   */
125  public static DCMotor getBag(int numMotors) {
126    return new DCMotor(
127        12, 0.43, 53, 1.8, Units.rotationsPerMinuteToRadiansPerSecond(13180), numMotors);
128  }
129
130  /**
131   * Return a gearbox of Andymark RS775-125 motors.
132   *
133   * @param numMotors Number of motors in the gearbox.
134   * @return A gearbox of Andymark RS775-125 motors.
135   */
136  public static DCMotor getAndymarkRs775_125(int numMotors) {
137    return new DCMotor(
138        12, 0.28, 18, 1.6, Units.rotationsPerMinuteToRadiansPerSecond(5800.0), numMotors);
139  }
140
141  /**
142   * Return a gearbox of Banebots RS775 motors.
143   *
144   * @param numMotors Number of motors in the gearbox.
145   * @return A gearbox of Banebots RS775 motors.
146   */
147  public static DCMotor getBanebotsRs775(int numMotors) {
148    return new DCMotor(
149        12, 0.72, 97, 2.7, Units.rotationsPerMinuteToRadiansPerSecond(13050.0), numMotors);
150  }
151
152  /**
153   * Return a gearbox of Andymark 9015 motors.
154   *
155   * @param numMotors Number of motors in the gearbox.
156   * @return A gearbox of Andymark 9015 motors.
157   */
158  public static DCMotor getAndymark9015(int numMotors) {
159    return new DCMotor(
160        12, 0.36, 71, 3.7, Units.rotationsPerMinuteToRadiansPerSecond(14270.0), numMotors);
161  }
162
163  /**
164   * Return a gearbox of Banebots RS 550 motors.
165   *
166   * @param numMotors Number of motors in the gearbox.
167   * @return A gearbox of Banebots RS 550 motors.
168   */
169  public static DCMotor getBanebotsRs550(int numMotors) {
170    return new DCMotor(
171        12, 0.38, 84, 0.4, Units.rotationsPerMinuteToRadiansPerSecond(19000.0), numMotors);
172  }
173
174  /**
175   * Return a gearbox of NEO 550 motors.
176   *
177   * @param numMotors Number of motors in the gearbox.
178   * @return A gearbox of NEO 550 motors.
179   */
180  public static DCMotor getNeo550(int numMotors) {
181    return new DCMotor(
182        12, 0.97, 100, 1.4, Units.rotationsPerMinuteToRadiansPerSecond(11000.0), numMotors);
183  }
184
185  /**
186   * Return a gearbox of Falcon 500 motors.
187   *
188   * @param numMotors Number of motors in the gearbox.
189   * @return A gearbox of Falcon 500 motors.
190   */
191  public static DCMotor getFalcon500(int numMotors) {
192    return new DCMotor(
193        12, 4.69, 257, 1.5, Units.rotationsPerMinuteToRadiansPerSecond(6380.0), numMotors);
194  }
195
196  /**
197   * Return a gearbox of Romi/TI_RSLK MAX motors.
198   *
199   * @param numMotors Number of motors in the gearbox.
200   * @return A gearbox of Romi/TI_RSLK MAX motors.
201   */
202  public static DCMotor getRomiBuiltIn(int numMotors) {
203    // From https://www.pololu.com/product/1520/specs
204    return new DCMotor(
205        4.5, 0.1765, 1.25, 0.13, Units.rotationsPerMinuteToRadiansPerSecond(150.0), numMotors);
206  }
207}