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 * Mass 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 MassUnits { 015 /* Commonly used units in FRC */ 016 /** 017 * Grams 018 */ 019 GRAMS(0.001), 020 /** 021 * Kilograms 022 */ 023 KILOGRAMS(1.0), 024 /** 025 * Pounds 026 */ 027 POUNDS(0.45359237), 028 /** 029 * Ounces 030 */ 031 OUNCES(0.45359237 / 16.0); 032 033 /** 034 * Kilograms per unit (conversion l.t. 1 if less than a kilogram) 035 */ 036 public final double conversionToKgs; 037 038 /** 039 * 040 * @param kilogramsPerUnitMass Conversion factor for kilograms to the unit 041 */ 042 MassUnits(double kilogramsPerUnitMass) { 043 conversionToKgs = kilogramsPerUnitMass; 044 } 045 046 /** 047 * Convert from the base unit to the given argument unit 048 * 049 * @param x double to be converted 050 * @param targetUnit target unit 051 * @return x converted to the target units 052 */ 053 public double convertX(double x, MassUnits targetUnit) { 054 return x * conversionToKgs / targetUnit.conversionToKgs; 055 } 056}