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.units; 006 007import edu.wpi.first.units.measure.Current; 008 009/** 010 * Unit of electric current dimension. 011 * 012 * <p>This is the base type for units of current dimension. It is also used to specify the dimension 013 * for {@link Measure}: <code>Measure<CurrentUnit></code>. 014 * 015 * <p>Actual units (such as {@link Units#Amps} and {@link Units#Milliamps}) can be found in the 016 * {@link Units} class. 017 */ 018public final class CurrentUnit extends Unit { 019 CurrentUnit(CurrentUnit baseUnit, double baseUnitEquivalent, String name, String symbol) { 020 super(baseUnit, baseUnitEquivalent, name, symbol); 021 } 022 023 CurrentUnit( 024 CurrentUnit baseUnit, 025 UnaryFunction toBaseConverter, 026 UnaryFunction fromBaseConverter, 027 String name, 028 String symbol) { 029 super(baseUnit, toBaseConverter, fromBaseConverter, name, symbol); 030 } 031 032 @Override 033 public CurrentUnit getBaseUnit() { 034 return (CurrentUnit) super.getBaseUnit(); 035 } 036 037 /** 038 * Constructs a unit of power equivalent to this unit of electrical current multiplied by another 039 * unit of voltage. For example, {@code Amps.times(Volts)} will return a unit of power equivalent 040 * to one Watt; {@code Amps.times(Millivolts)} will return a unit of power equivalent to a 041 * milliwatt, and so on. 042 * 043 * @param voltage the voltage unit to multiply by 044 * @param name the name of the resulting unit of power 045 * @param symbol the symbol used to represent the unit of power 046 * @return the power unit 047 */ 048 public PowerUnit mult(VoltageUnit voltage, String name, String symbol) { 049 return Units.derive(PowerUnit.combine(voltage, this)).named(name).symbol(symbol).make(); 050 } 051 052 @Override 053 public Current of(double magnitude) { 054 return new Current(magnitude, toBaseUnits(magnitude), this); 055 } 056 057 @Override 058 public Current ofBaseUnits(double baseUnitMagnitude) { 059 return new Current(fromBaseUnits(baseUnitMagnitude), baseUnitMagnitude, this); 060 } 061 062 @Override 063 public Current zero() { 064 return (Current) super.zero(); 065 } 066 067 @Override 068 public Current one() { 069 return (Current) super.one(); 070 } 071 072 @Override 073 public VelocityUnit<CurrentUnit> per(TimeUnit time) { 074 return VelocityUnit.combine(this, time); 075 } 076 077 /** 078 * Creates a ratio unit between this unit and an arbitrary other unit. 079 * 080 * @param other the other unit 081 * @param <U> the type of the other unit 082 * @return the ratio unit 083 */ 084 public <U extends Unit> PerUnit<CurrentUnit, U> per(U other) { 085 return PerUnit.combine(this, other); 086 } 087 088 /** 089 * Converts a measurement value in terms of another current unit to this unit. 090 * 091 * @param magnitude the magnitude of the measurement in terms of the other current unit 092 * @param otherUnit the other current unit 093 * @return the value of the measurement in terms of this unit 094 */ 095 public double convertFrom(double magnitude, CurrentUnit otherUnit) { 096 return fromBaseUnits(otherUnit.toBaseUnits(magnitude)); 097 } 098}