Skip to content

Commit

Permalink
1.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
sswadkar committed Feb 9, 2023
1 parent 0ee5466 commit 63c02cd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ publishing {
release(MavenPublication) {
groupId = 'org.team4099'
artifactId = 'falconutils'
version = '1.1.10'
version = '1.1.11'

from(components["kotlin"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import org.team4099.lib.units.base.seconds
import edu.wpi.first.math.trajectory.TrapezoidProfile as WPITrapezoidProfile

class TrapezoidProfile<U : UnitKey>(
constraints: Constraints<U>,
goal: State<U>,
initial: State<U>
val constraints: Constraints<U>,
val goal: State<U>,
val initial: State<U>
) {
val trapezoidProfile =
WPITrapezoidProfile(constraints.wpiConstraints, goal.wpiState, initial.wpiState)
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/org/team4099/lib/units/Value.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.team4099.lib.units

import java.util.function.Supplier
import kotlin.math.absoluteValue
import kotlin.math.sign

Expand All @@ -21,8 +20,7 @@ value class Value<T : UnitKey>(val value: Double) : Comparable<Value<T>> {
inline val cubed: Value<Cubed<T>>
get() = Value(value * value * value)

inline val asSupplier: Supplier<Value<T>>
get() = Supplier { Value(value) }
inline fun epsilonEquals(o: Value<T>): Boolean = (value - o.value).absoluteValue <= 1E-9

inline operator fun plus(o: Value<T>): Value<T> = Value(value + o.value)
inline operator fun minus(o: Value<T>): Value<T> = Value(value - o.value)
Expand Down
15 changes: 3 additions & 12 deletions src/main/kotlin/org/team4099/lib/units/derived/GearRatio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,17 @@ typealias Driving = Unitless
typealias Driven = Unitless

// Reductions are < 1
inline val Double.reduction
get() = GearRatio(1 / this)

inline val Double.overdrive
inline val Double.gearRatio
get() = GearRatio(this)

inline val Number.reduction
get() = this.toDouble().reduction

inline val Number.overdrive
get() = this.toDouble().overdrive

inline val Double.driving
get() = Value<Driving>(this)

inline val Double.driven
get() = Value<Driven>(this)

inline val GearRatio.asDrivingOverDriven
get() = 1 / value
get() = value

inline val GearRatio.asDrivenOverDriving
get() = value
get() = 1 / value
12 changes: 5 additions & 7 deletions src/main/kotlin/org/team4099/lib/units/derived/Inertia.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.team4099.lib.units.derived

import org.team4099.lib.units.Product
import org.team4099.lib.units.Squared
import org.team4099.lib.units.UnitKey
import org.team4099.lib.units.Value
import org.team4099.lib.units.base.Kilogram
import org.team4099.lib.units.base.Meter
Expand All @@ -10,11 +11,8 @@ typealias Inertia = Product<Kilogram, Squared<Meter>>

typealias MomentOfInertia = Value<Inertia>

inline val Double.momentOfInertia
get() = MomentOfInertia(this)

inline val Number.momentOfInertia
get() = MomentOfInertia(this.toDouble())

inline val MomentOfInertia.asKilogramsPerMeterSquared
inline val MomentOfInertia.inKilogramsMeterSquared
get() = value

inline val <K : UnitKey> Value<K>.meterSquared
get() = Value<Product<K, Squared<Meter>>>(value)
13 changes: 7 additions & 6 deletions src/test/kotlin/team4099/units/GearRatioTest.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package team4099.units

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.team4099.lib.units.derived.asDrivenOverDriving
import org.team4099.lib.units.derived.asDrivingOverDriven
import org.team4099.lib.units.derived.driven
import org.team4099.lib.units.derived.driving
import org.team4099.lib.units.derived.overdrive
import org.team4099.lib.units.derived.reduction
import org.team4099.lib.units.derived.gearRatio

class GearRatioTest {

private val kEpsilon = 1E-9

@Test
fun testGearRatio() {
val reductionRatio = (18.0.driving / 72.0.driven).reduction
val overdriveRatio = (18.0.driving / 72.0.driven).overdrive
println(reductionRatio.asDrivenOverDriving) // 4.0
println(overdriveRatio.asDrivenOverDriving) // 0.25
val reductionRatio = (72.0.driven / 18.0.driving).gearRatio

assertEquals(reductionRatio.asDrivenOverDriving, 0.25)
assertEquals(reductionRatio.asDrivingOverDriven, 4.0)
}
}
12 changes: 8 additions & 4 deletions src/test/kotlin/team4099/units/InertiaTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package team4099.units

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.team4099.lib.units.base.grams
import org.team4099.lib.units.base.inches
import org.team4099.lib.units.derived.MomentOfInertia
import org.team4099.lib.units.derived.asKilogramsPerMeterSquared
import org.team4099.lib.units.derived.inKilogramsMeterSquared
import org.team4099.lib.units.derived.meterSquared
import org.team4099.lib.units.kilo

class InertiaTest {
Expand All @@ -13,7 +14,10 @@ class InertiaTest {

@Test
fun testInertia() {
val inertia: MomentOfInertia = 1.0.kilo.grams * 3.0.inches.squared
println(inertia.asKilogramsPerMeterSquared)
val inertia = 1.0.kilo.grams * 3.0.inches.squared
val inertiaDefinition = 1.0.kilo.grams.meterSquared

assertEquals(1.0, inertiaDefinition.inKilogramsMeterSquared)
assertEquals(0.00580644, inertia.inKilogramsMeterSquared, kEpsilon)
}
}

0 comments on commit 63c02cd

Please sign in to comment.