mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[wpimath] Add miles per hour conversation methods (#8026)
This commit is contained in:
@@ -8,7 +8,9 @@ package edu.wpi.first.math.util;
|
||||
public final class Units {
|
||||
private static final double kInchesPerFoot = 12.0;
|
||||
private static final double kMetersPerInch = 0.0254;
|
||||
private static final double kMetersPerMile = 1609.344;
|
||||
private static final double kSecondsPerMinute = 60;
|
||||
private static final double kMinutesPerHour = 60;
|
||||
private static final double kMillisecondsPerSecond = 1000;
|
||||
private static final double kKilogramsPerLb = 0.453592;
|
||||
|
||||
@@ -137,6 +139,26 @@ public final class Units {
|
||||
return radiansPerSecond * (kSecondsPerMinute / 2) / Math.PI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts miles per hour to meters per second.
|
||||
*
|
||||
* @param mph The miles per hour to convert to meters per second.
|
||||
* @return Meters per second converted from miles per hour.
|
||||
*/
|
||||
public static double milesPerHourToMetersPerSecond(double mph) {
|
||||
return mph * kMetersPerMile / (kSecondsPerMinute * kMinutesPerHour);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts meters per second to miles per hour.
|
||||
*
|
||||
* @param metersPerSecond The meters per second to convert to from miles per hour.
|
||||
* @return Miles per hour converted from meters per second.
|
||||
*/
|
||||
public static double metersPerSecondToMilesPerHour(double metersPerSecond) {
|
||||
return metersPerSecond / kMetersPerMile * (kSecondsPerMinute * kMinutesPerHour);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts given milliseconds to seconds.
|
||||
*
|
||||
|
||||
@@ -50,17 +50,27 @@ class UnitsTest extends UtilityClassTest<Units> {
|
||||
}
|
||||
|
||||
@Test
|
||||
void radiansPerSecondToRotationsPerMinute() {
|
||||
void radiansPerSecondToRotationsPerMinuteTest() {
|
||||
assertEquals(76.39, Units.radiansPerSecondToRotationsPerMinute(8), 1e-2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void millisecondsToSeconds() {
|
||||
void milesPerHourToMetersPerSecondTest() {
|
||||
assertEquals(0.44704, Units.milesPerHourToMetersPerSecond(1), 1e-2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void metersPerSecondToMilesPerHourTest() {
|
||||
assertEquals(2.2369, Units.metersPerSecondToMilesPerHour(1), 1e-2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void millisecondsToSecondsTest() {
|
||||
assertEquals(0.5, Units.millisecondsToSeconds(500), 1e-2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void secondsToMilliseconds() {
|
||||
void secondsToMillisecondsTest() {
|
||||
assertEquals(1500, Units.secondsToMilliseconds(1.5), 1e-2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user