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 * Acceleration 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 AccelerationUnits {
015  /* -------- Common Aliases -------- */
016  /**
017   * Meters per second per second
018   */
019  MPS2(DistanceUnits.METER, TimeUnits.SECOND),
020  /**
021   * Rotations per second per second
022   */
023  ROTPS2(DistanceUnits.ROTATION, TimeUnits.SECOND),
024  /**
025   * Rotations per second per second
026   */
027  RPS2(DistanceUnits.ROTATION, TimeUnits.SECOND),
028  /**
029   * Radians per second per second
030   */
031  RADPS2(DistanceUnits.RADIAN, TimeUnits.SECOND),
032  /**
033   * Degrees per second per second AKA degrees per second^2
034   */
035  DEGPS2(DistanceUnits.DEGREE, TimeUnits.SECOND),
036  /* -------- Meters -------- */
037  /**
038   * Meters per millisecond per millisecond
039   */
040  METERS_PER_MILLISECOND2(DistanceUnits.METER, TimeUnits.MILLISECOND),
041  /**
042   * Meters per second per second
043   */
044  METERS_PER_SECOND2(DistanceUnits.METER, TimeUnits.SECOND),
045  /**
046   * Meters per minute per minute
047   */
048  METERS_PER_MINUTE2(DistanceUnits.METER, TimeUnits.MINUTE),
049  /**
050   * Meters per hour per hour
051   */
052  METERS_PER_HOUR2(DistanceUnits.METER, TimeUnits.HOUR),
053  /* -------- Feet -------- */
054  /**
055   * Feet per millisecond per millisecond
056   */
057  FEET_PER_MILLISECOND2(DistanceUnits.FEET, TimeUnits.MILLISECOND),
058  /**
059   * Feet per second per second
060   */
061  FEET_PER_SECOND2(DistanceUnits.FEET, TimeUnits.SECOND),
062  /**
063   * Feet per minute per minute
064   */
065  FEET_PER_MINUTE2(DistanceUnits.FEET, TimeUnits.MINUTE),
066  /**
067   * Feet per hour per hour
068   */
069  FEET_PER_HOUR2(DistanceUnits.FEET, TimeUnits.HOUR),
070  /* -------- Inches -------- */
071  /**
072   * Inches per millisecond per millisecond
073   */
074  INCHES_PER_MILLISECOND2(DistanceUnits.INCH, TimeUnits.MILLISECOND),
075  /**
076   * Inches per second per second
077   */
078  INCHES_PER_SECOND2(DistanceUnits.INCH, TimeUnits.SECOND),
079  /**
080   * Inches per minute per minute
081   */
082  INCHES_PER_MINUTE2(DistanceUnits.INCH, TimeUnits.MINUTE),
083  /**
084   * Inches per hour per hour
085   */
086  INCHES_PER_HOUR2(DistanceUnits.INCH, TimeUnits.HOUR),
087  /* -------- Rotations -------- */
088  /**
089   * Rotations per millisecond per millisecond
090   */
091  ROTATIONS_PER_MILLISECOND2(DistanceUnits.ROTATION, TimeUnits.MILLISECOND),
092  /**
093   * Rotations per second per second
094   */
095  ROTATIONS_PER_SECOND2(DistanceUnits.ROTATION, TimeUnits.SECOND),
096  /**
097   * Rotations per minute per minute
098   */
099  ROTATIONS_PER_MINUTE2(DistanceUnits.ROTATION, TimeUnits.MINUTE),
100  /**
101   * Rotations per hour per hour
102   */
103  ROTATIONS_PER_HOUR2(DistanceUnits.ROTATION, TimeUnits.HOUR),
104  /* -------- Radians -------- */
105  /**
106   * Radians per millisecond per millisecond
107   */
108  RADIANS_PER_MILLISECOND2(DistanceUnits.RADIAN, TimeUnits.MILLISECOND),
109  /**
110   * Radians per second per second
111   */
112  RADIANS_PER_SECOND2(DistanceUnits.RADIAN, TimeUnits.SECOND),
113  /**
114   * Radians per minute per minute
115   */
116  RADIANS_PER_MINUTE2(DistanceUnits.RADIAN, TimeUnits.MINUTE),
117  /**
118   * Radians per hour per hour
119   */
120  RADIANS_PER_HOUR2(DistanceUnits.RADIAN, TimeUnits.HOUR),
121  /* -------- Degrees -------- */
122  /**
123   * Degrees per millisecond per millisecond
124   */
125  DEGREES_PER_MILLISECOND2(DistanceUnits.DEGREE, TimeUnits.MILLISECOND),
126  /**
127   * Degrees per second per second
128   */
129  DEGREES_PER_SECOND2(DistanceUnits.DEGREE, TimeUnits.SECOND),
130  /**
131   * Degrees per minute per minute
132   */
133  DEGREES_PER_MINUTE2(DistanceUnits.DEGREE, TimeUnits.MINUTE),
134  /**
135   * Degrees per hour per hour
136   */
137  DEGREES_PER_HOUR2(DistanceUnits.DEGREE, TimeUnits.HOUR);
138
139  /**
140   * Unit of distance
141   */
142  public final DistanceUnits distanceUnit;
143  /**
144   * Unit of time
145   */
146  public final TimeUnits timeUnit;
147
148  /**
149   *
150   * @param distanceUnit desired distance unit
151   * @param timeUnit     desired time unit
152   */
153  AccelerationUnits(DistanceUnits distanceUnit, TimeUnits timeUnit) {
154    this.distanceUnit = distanceUnit;
155    this.timeUnit = timeUnit;
156  }
157
158  /**
159   *
160   * @param x          double to be converted
161   * @param targetUnit target unit
162   * @return x converted to the target units
163   */
164  public double convertX(double x, AccelerationUnits targetUnit) {
165    // convert to second argument unit
166    return distanceUnit.convertX(x, targetUnit.distanceUnit)
167        / timeUnit.convertX(timeUnit.convertX(1.0, targetUnit.timeUnit), targetUnit.timeUnit);
168  }
169}