Skip to content

Commit 4134182

Browse files
committed
Merge branch 'pigeon'
2 parents b67ba9e + e6eb8b9 commit 4134182

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = 'org.strykeforce'
11-
version = '20.0.1'
11+
version = '20.1.0'
1212

1313
sourceCompatibility = JavaVersion.VERSION_11
1414
targetCompatibility = JavaVersion.VERSION_11
@@ -17,7 +17,7 @@ targetCompatibility = JavaVersion.VERSION_11
1717
def includeDesktopSupport = false
1818

1919
// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
20-
// Also defines JUnit 4.
20+
// Also defines JUnit 5.
2121
dependencies {
2222
implementation wpi.deps.wpilib()
2323
nativeZip wpi.deps.wpilibJni(wpi.platforms.roborio)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.strykeforce.thirdcoast.telemetry.item
2+
3+
import com.ctre.phoenix.sensors.PigeonIMU
4+
import edu.wpi.first.wpilibj.Servo
5+
import java.lang.IllegalArgumentException
6+
import java.util.function.DoubleSupplier
7+
8+
internal const val COMPASS_HEADING = "COMPASS_HEADING"
9+
internal const val ABS_COMPASS_HEADING = "ABS_COMPASS_HEADING"
10+
internal const val COMPASS_FIELD_STRENGTH = "COMPASS_FIELD_STRENGTH"
11+
internal const val YAW = "YAW"
12+
internal const val PITCH = "PITCH"
13+
internal const val ROLL = "ROLL"
14+
15+
/** Represents a [Servo] telemetry-enable `Measurable` item. */
16+
class PigeonIMUItem @JvmOverloads constructor(
17+
private val pigeon: PigeonIMU,
18+
override val description: String = "PigeonIMU ${pigeon.deviceID}"
19+
) : Measurable {
20+
21+
override val deviceId = pigeon.deviceID
22+
override val type = "pigeon"
23+
override val measures = setOf(
24+
Measure(COMPASS_HEADING, "Compass Heading"),
25+
Measure(ABS_COMPASS_HEADING, "Absolute Compass Heading"),
26+
Measure(COMPASS_FIELD_STRENGTH, "Compass Field Strength"),
27+
Measure(YAW, "Yaw"),
28+
Measure(PITCH, "Pitch"),
29+
Measure(ROLL, "Roll")
30+
)
31+
32+
override fun measurementFor(measure: Measure): DoubleSupplier {
33+
return when (measure.name) {
34+
COMPASS_HEADING -> DoubleSupplier { pigeon.compassHeading }
35+
ABS_COMPASS_HEADING -> DoubleSupplier { pigeon.absoluteCompassHeading }
36+
COMPASS_FIELD_STRENGTH -> DoubleSupplier { pigeon.compassFieldStrength }
37+
YAW -> DoubleSupplier {
38+
val ypr:DoubleArray = doubleArrayOf(0.0, 0.0, 0.0)
39+
pigeon.getYawPitchRoll(ypr)
40+
ypr[0]
41+
}
42+
PITCH -> DoubleSupplier {
43+
val ypr:DoubleArray = doubleArrayOf(0.0, 0.0, 0.0)
44+
pigeon.getYawPitchRoll(ypr)
45+
ypr[1]
46+
}
47+
ROLL -> DoubleSupplier {
48+
val ypr:DoubleArray = doubleArrayOf(0.0, 0.0, 0.0)
49+
pigeon.getYawPitchRoll(ypr)
50+
ypr[2]
51+
}
52+
else -> throw IllegalArgumentException(measure.name)
53+
}
54+
}
55+
56+
override fun equals(other: Any?): Boolean {
57+
if (this === other) return true
58+
if (javaClass != other?.javaClass) return false
59+
60+
other as PigeonIMUItem
61+
62+
if (deviceId != other.deviceId) return false
63+
64+
return true
65+
}
66+
67+
override fun hashCode() = deviceId
68+
}

0 commit comments

Comments
 (0)