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 * Time 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 TimeUnits { 015 /** 016 * Milliseconds 017 */ 018 MILLISECOND(.001), 019 /** 020 * Seconds 021 */ 022 SECOND(1.0), 023 /** 024 * Minutes 025 */ 026 MINUTE(60.0), 027 /** 028 * Hour 029 */ 030 HOUR(3600.0); 031 032 /** 033 * Seconds per unit (conversion l.t. 1 if smaller than a second) 034 */ 035 public final double conversionToSeconds; 036 037 /** 038 * 039 * @param secondsPerUnitTime Conversion factor for seconds to the unit 040 */ 041 TimeUnits(double secondsPerUnitTime) { 042 conversionToSeconds = secondsPerUnitTime; 043 } 044 045 /** 046 * Convert from the base unit to the given argument unit 047 * 048 * @param x double to be converted 049 * @param targetUnit target unit 050 * @return x converted to the target units 051 */ 052 public double convertX(double x, TimeUnits targetUnit) { 053 // convert to second argument unit 054 return x * conversionToSeconds / targetUnit.conversionToSeconds; 055 } 056}