001/**
002 * Copyright 2024 The Space Cookies : Girl Scout Troop #62868 and FRC Team #1868
003 * Open Source Software; you may modify and/or share it under the terms of
004 * the 3-Clause BSD License found in the root directory of this project.
005 */
006
007package tagalong.units;
008
009/**
010 * Velocity units enum identifiers.
011 * Used for configuration and robot setup instead of the WPILib Java units to
012 * avoid reallocations and garbage collections in match.
013 */
014public enum VelocityUnits {
015  /* -------- Common Aliases -------- */
016  /**
017   * Meter per Second aka MPS aka meter/second
018   */
019  MPS(DistanceUnits.METER, TimeUnits.SECOND),
020  /**
021   * Rotations per Second aka RPS aka rotations/second
022   */
023  ROTPS(DistanceUnits.ROTATION, TimeUnits.SECOND),
024  /**
025   * Rotations per Second aka RPS aka rotations/second
026   */
027  RPS(DistanceUnits.ROTATION, TimeUnits.SECOND),
028  /**
029   * Radians per Second aka RadPS aka radians/second
030   */
031  RADPS(DistanceUnits.RADIAN, TimeUnits.SECOND),
032  /**
033   * Degrees per Second aka DegPS aka deg/second
034   */
035  DEGPS(DistanceUnits.DEGREE, TimeUnits.SECOND),
036  /* -------- Meters -------- */
037  /**
038   * Meter per Millisecond aka meter/millisecond
039   */
040  METERS_PER_MILLISECOND(DistanceUnits.METER, TimeUnits.MILLISECOND),
041  /**
042   * Meter per Second aka MPS aka meter/second
043   */
044  METERS_PER_SECOND(DistanceUnits.METER, TimeUnits.SECOND),
045  /**
046   * Meter per Minute aka meter/minute
047   */
048  METERS_PER_MINUTE(DistanceUnits.METER, TimeUnits.MINUTE),
049  /**
050   * Meter per Hour aka meter/hour
051   */
052  METERS_PER_HOUR(DistanceUnits.METER, TimeUnits.HOUR),
053  /* -------- Feet -------- */
054  /**
055   * Feet per Millisecond aka feet/millisecond
056   */
057  FEET_PER_MILLISECOND(DistanceUnits.FEET, TimeUnits.MILLISECOND),
058  /**
059   * Feet per Second aka FPS aka feet/second
060   */
061  FEET_PER_SECOND(DistanceUnits.FEET, TimeUnits.SECOND),
062  /**
063   * Feet per Minute aka feet/minute
064   */
065  FEET_PER_MINUTE(DistanceUnits.FEET, TimeUnits.MINUTE),
066  /**
067   * Feet per Hour aka feet/hour
068   */
069  FEET_PER_HOUR(DistanceUnits.FEET, TimeUnits.HOUR),
070  /* -------- Inches -------- */
071  /**
072   * Inches per Millisecond aka feet/millisecond
073   */
074  INCHES_PER_MILLISECOND(DistanceUnits.INCH, TimeUnits.MILLISECOND),
075  /**
076   * Inches per Second aka inch/second
077   */
078  INCHES_PER_SECOND(DistanceUnits.INCH, TimeUnits.SECOND),
079  /**
080   * Inches per Minute aka inch/minute
081   */
082  INCHES_PER_MINUTE(DistanceUnits.INCH, TimeUnits.MINUTE),
083  /**
084   * Inches per Hour aka inch/hour
085   */
086  INCHES_PER_HOUR(DistanceUnits.INCH, TimeUnits.HOUR),
087  /* -------- Rotations -------- */
088  /**
089   * Rotations per Millisecond aka rotations/Millisecond
090   */
091  ROTATIONS_PER_MILLISECOND(DistanceUnits.ROTATION, TimeUnits.MILLISECOND),
092  /**
093   * Rotations per Second aka RPS aka rotations/second
094   */
095  ROTATIONS_PER_SECOND(DistanceUnits.ROTATION, TimeUnits.SECOND),
096  /**
097   * Rotations per Minute aka RPM aka rotations/minute
098   */
099  ROTATIONS_PER_MINUTE(DistanceUnits.ROTATION, TimeUnits.MINUTE),
100  /**
101   * Rotations per Hour aka rotations/hour
102   */
103  ROTATIONS_PER_HOUR(DistanceUnits.ROTATION, TimeUnits.HOUR),
104  /* -------- Radians -------- */
105  /**
106   * Radians per Millisecond aka radians/millisecond
107   */
108  RADIANS_PER_MILLISECOND(DistanceUnits.RADIAN, TimeUnits.MILLISECOND),
109  /**
110   * Radians per Second aka radians/second
111   */
112  RADIANS_PER_SECOND(DistanceUnits.RADIAN, TimeUnits.SECOND),
113  /**
114   * Radians per Minute aka radians/minute
115   */
116  RADIANS_PER_MINUTE(DistanceUnits.RADIAN, TimeUnits.MINUTE),
117  /**
118   * Radians per Hour aka radians/hour
119   */
120  RADIANS_PER_HOUR(DistanceUnits.RADIAN, TimeUnits.HOUR),
121  /* -------- Degrees -------- */
122  /**
123   * Degrees per Millisecond aka deg/millisecond
124   */
125  DEGREES_PER_MILLISECOND(DistanceUnits.DEGREE, TimeUnits.MILLISECOND),
126  /**
127   * Degrees per Second aka DegPS aka deg/second
128   */
129  DEGREES_PER_SECOND(DistanceUnits.DEGREE, TimeUnits.SECOND),
130  /**
131   * Degrees per Minute aka deg/minute
132   */
133  DEGREES_PER_MINUTE(DistanceUnits.DEGREE, TimeUnits.MINUTE),
134  /**
135   * Degrees per Hour aka deg/hour
136   */
137  DEGREES_PER_HOUR(DistanceUnits.DEGREE, TimeUnits.HOUR);
138
139  /**
140   * The distance portion of the velocity unit
141   */
142  public final DistanceUnits distanceUnit;
143  /**
144   * The time portion of the velocity unit
145   */
146  public final TimeUnits timeUnit;
147
148  /**
149   * @param distanceUnit desired distance unit
150   * @param timeUnit     desired time unit
151   */
152  VelocityUnits(DistanceUnits distanceUnit, TimeUnits timeUnit) {
153    this.distanceUnit = distanceUnit;
154    this.timeUnit = timeUnit;
155  }
156
157  /**
158   * Convert from base class' unit to the targetUnit type
159   *
160   * @param x          double value to be converted
161   * @param targetUnit target unit
162   * @return x converted to the target units
163   */
164  public double convertX(double x, VelocityUnits targetUnit) {
165    return distanceUnit.convertX(x, targetUnit.distanceUnit)
166        / timeUnit.convertX(1.0, targetUnit.timeUnit);
167  }
168}