Skip to content

Commit 9af09ea

Browse files
style: apply ktlint formatting [bot]
1 parent fd09934 commit 9af09ea

9 files changed

Lines changed: 96 additions & 98 deletions

File tree

TeamCode/src/main/kotlin/pioneer/Constants.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ object Camera {
132132
private const val PITCH_DEG = 0.0
133133
private const val ROLL_DEG = 0.0
134134

135-
//Lens Intrinsics
135+
// Lens Intrinsics
136136
const val fx = 955.23
137137
const val fy = 962.92
138138
const val cx = 330.05
@@ -146,4 +146,3 @@ object Camera {
146146
val ORIENTATION_RAD: YawPitchRollAngles
147147
get() = YawPitchRollAngles(AngleUnit.RADIANS, YAW_DEG * DEG_TO_RAD, PITCH_DEG * DEG_TO_RAD, ROLL_DEG * DEG_TO_RAD, 0)
148148
}
149-

TeamCode/src/main/kotlin/pioneer/hardware/Camera.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,30 @@ import org.firstinspires.ftc.vision.apriltag.AprilTagGameDatabase
1313
import org.firstinspires.ftc.vision.apriltag.AprilTagLibrary
1414
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor
1515
import pioneer.constants.HardwareNames
16-
import pioneer.constants.Camera as CameraConstants
1716
import kotlin.jvm.java
17+
import pioneer.constants.Camera as CameraConstants
1818

1919
class Camera(
2020
private val hardwareMap: HardwareMap,
2121
private val cameraName: String = HardwareNames.WEBCAM,
2222
val processors: Array<VisionProcessor> = emptyArray(),
2323
) : HardwareComponent {
24-
2524
override val name = "Camera"
2625

2726
private lateinit var portal: VisionPortal
2827

2928
override fun init() {
30-
portal =
31-
VisionPortal
32-
.Builder()
33-
.setCamera(hardwareMap.get(WebcamName::class.java, cameraName))
34-
.setCameraResolution(Size(640, 480))
35-
.enableLiveView(true)
36-
.apply {
37-
if (processors.isNotEmpty()) {
38-
addProcessors(*processors)
39-
}
40-
}.build()
29+
portal =
30+
VisionPortal
31+
.Builder()
32+
.setCamera(hardwareMap.get(WebcamName::class.java, cameraName))
33+
.setCameraResolution(Size(640, 480))
34+
.enableLiveView(true)
35+
.apply {
36+
if (processors.isNotEmpty()) {
37+
addProcessors(*processors)
38+
}
39+
}.build()
4140
}
4241

4342
// Helper function to get a specific processor by type

TeamCode/src/main/kotlin/pioneer/helpers/Indexer.kt

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,54 @@ interface Indexer {
55
var index: Int
66

77
fun next()
8+
89
fun previous()
10+
911
fun peek(): Any?
12+
1013
fun isEmpty(): Boolean
14+
1115
fun size(): Int
16+
1217
fun pop(): Any?
18+
1319
fun push(item: Any): Boolean
20+
1421
fun toList(): List<Any>
1522
}
1623

1724
/**
1825
* SpinDexer - A circular indexer implementation that wraps around when advancing or retreating
1926
* @param maxSize Optional maximum size limit for the bin. If null, no limit is enforced.
2027
*/
21-
class SpinDexer(private val maxSize: Int? = null, private val initialItems: List<Any> = emptyList()) : Indexer {
28+
class SpinDexer(
29+
private val maxSize: Int? = null,
30+
private val initialItems: List<Any> = emptyList(),
31+
) : Indexer {
2232
override var bin: List<Any> = initialItems
2333
override var index: Int = 0
2434

2535
/**
2636
* Calculate the next index in a circular manner
2737
*/
28-
private fun nextIndex(): Int {
29-
return if (bin.isEmpty()) 0 else (index + 1) % bin.size
30-
}
38+
private fun nextIndex(): Int = if (bin.isEmpty()) 0 else (index + 1) % bin.size
3139

3240
/**
3341
* Calculate the previous index in a circular manner
3442
*/
35-
private fun previousIndex(): Int {
36-
return if (bin.isEmpty()) 0 else if (index - 1 < 0) bin.size - 1 else index - 1
37-
}
43+
private fun previousIndex(): Int =
44+
if (bin.isEmpty()) {
45+
0
46+
} else if (index - 1 < 0) {
47+
bin.size - 1
48+
} else {
49+
index - 1
50+
}
3851

3952
/**
4053
* Calculate a circular index offset from the current position
4154
*/
42-
private fun circularIndex(offset: Int): Int {
43-
return if (bin.isEmpty()) 0 else (index + offset) % bin.size
44-
}
55+
private fun circularIndex(offset: Int): Int = if (bin.isEmpty()) 0 else (index + offset) % bin.size
4556

4657
/**
4758
* Normalize the current index after bin modification
@@ -57,9 +68,7 @@ class SpinDexer(private val maxSize: Int? = null, private val initialItems: List
5768
/**
5869
* Check if there's capacity to add more items
5970
*/
60-
private fun hasCapacity(): Boolean {
61-
return maxSize == null || bin.size < maxSize
62-
}
71+
private fun hasCapacity(): Boolean = maxSize == null || bin.size < maxSize
6372

6473
/**
6574
* Move to the next position in a circular manner
@@ -82,30 +91,22 @@ class SpinDexer(private val maxSize: Int? = null, private val initialItems: List
8291
/**
8392
* Peek at the current item without removing it
8493
*/
85-
override fun peek(): Any? {
86-
return bin.getOrNull(index)
87-
}
94+
override fun peek(): Any? = bin.getOrNull(index)
8895

8996
/**
9097
* Check if the bin is empty
9198
*/
92-
override fun isEmpty(): Boolean {
93-
return bin.isEmpty()
94-
}
99+
override fun isEmpty(): Boolean = bin.isEmpty()
95100

96101
/**
97102
* Get the number of items in the bin
98103
*/
99-
override fun size(): Int {
100-
return bin.size
101-
}
104+
override fun size(): Int = bin.size
102105

103106
/**
104107
* Check if the bin is full (only applicable if maxSize is set)
105108
*/
106-
fun isFull(): Boolean {
107-
return !hasCapacity()
108-
}
109+
fun isFull(): Boolean = !hasCapacity()
109110

110111
/**
111112
* Remove and return the current item
@@ -124,21 +125,20 @@ class SpinDexer(private val maxSize: Int? = null, private val initialItems: List
124125
* @param item The item to add to the bin
125126
* @return true if the item was added successfully, false if the bin is full
126127
*/
127-
override fun push(item: Any): Boolean {
128-
return if (hasCapacity()) {
128+
override fun push(item: Any): Boolean =
129+
if (hasCapacity()) {
129130
bin = bin + item
130131
true
131132
} else {
132133
false
133134
}
134-
}
135135

136136
/**
137137
* Get the items as a list in order starting from the current position
138138
*/
139139
override fun toList(): List<Any> {
140140
if (bin.isEmpty()) return emptyList()
141-
141+
142142
return List(bin.size) { i ->
143143
bin[circularIndex(i)]
144144
}
@@ -149,20 +149,21 @@ class SpinDexer(private val maxSize: Int? = null, private val initialItems: List
149149
*/
150150
override fun toString(): String {
151151
if (bin.isEmpty()) return "SpinDexer[]"
152-
152+
153153
val prevIdx = previousIndex()
154154
val nextIdx = nextIndex()
155-
156-
val items = bin.mapIndexed { idx, item ->
157-
val marker = when (idx) {
158-
index -> "(curr)"
159-
nextIdx -> "(next)"
160-
prevIdx -> "(prev)"
161-
else -> ""
155+
156+
val items =
157+
bin.mapIndexed { idx, item ->
158+
val marker =
159+
when (idx) {
160+
index -> "(curr)"
161+
nextIdx -> "(next)"
162+
prevIdx -> "(prev)"
163+
else -> ""
164+
}
165+
"$item$marker"
162166
}
163-
"$item$marker"
164-
}
165167
return "SpinDexer[${items.joinToString(", ")}]"
166168
}
167-
168169
}

TeamCode/src/main/kotlin/pioneer/opmodes/BaseOpMode.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import pioneer.Bot
66
import pioneer.hardware.MecanumBase
77
import pioneer.helpers.Chrono
88
import pioneer.helpers.FileLogger
9-
import pioneer.localization.Localizer
109
import pioneer.localization.localizers.Pinpoint
1110

1211
// Base OpMode class to be extended by all user-defined OpModes

TeamCode/src/main/kotlin/pioneer/opmodes/other/AprilTagsTest.kt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import kotlin.math.*
1010

1111
@TeleOp(name = "April Tags Test")
1212
class AprilTagsTest : BaseOpMode() {
13-
private val processor : AprilTagProcessor = Camera.createAprilTagProcessor()
13+
private val processor: AprilTagProcessor = Camera.createAprilTagProcessor()
1414

1515
override fun onInit() {
16-
bot = Bot.builder()
17-
.add(Pinpoint(hardwareMap))
18-
.add(Camera(hardwareMap, processors = arrayOf(processor)))
19-
.build()
16+
bot =
17+
Bot
18+
.builder()
19+
.add(Pinpoint(hardwareMap))
20+
.add(Camera(hardwareMap, processors = arrayOf(processor)))
21+
.build()
2022
}
2123

2224
override fun onLoop() {
@@ -27,16 +29,31 @@ class AprilTagsTest : BaseOpMode() {
2729

2830
private fun fieldPosition() {
2931
val detections = processor.detections
30-
//TODO: Avg position if given multiple tags?
32+
// TODO: Avg position if given multiple tags?
3133
for (detection in detections) {
32-
val tagPosition = listOf(detection.metadata.fieldPosition[0], detection.metadata.fieldPosition[1], detection.metadata.fieldPosition[2])
33-
val fieldPositionWithTag = listOf((tagPosition[0]+detection.ftcPose.x).toFloat(), (tagPosition[1]+detection.ftcPose.y).toFloat(), (tagPosition[1]+detection.ftcPose.z).toFloat())
34+
val tagPosition =
35+
listOf(detection.metadata.fieldPosition[0], detection.metadata.fieldPosition[1], detection.metadata.fieldPosition[2])
36+
val fieldPositionWithTag =
37+
listOf(
38+
(tagPosition[0] + detection.ftcPose.x).toFloat(),
39+
(tagPosition[1] + detection.ftcPose.y).toFloat(),
40+
(
41+
tagPosition[1] +
42+
detection.ftcPose.z
43+
).toFloat(),
44+
)
3445

35-
telemetry.addLine("--Field Position From Tag (x, y, z): (%.2f, %.2f, %.2f)".format(fieldPositionWithTag[0], fieldPositionWithTag[1], fieldPositionWithTag[2]))
46+
telemetry.addLine(
47+
"--Field Position From Tag (x, y, z): (%.2f, %.2f, %.2f)".format(
48+
fieldPositionWithTag[0],
49+
fieldPositionWithTag[1],
50+
fieldPositionWithTag[2],
51+
),
52+
)
3653
telemetry.addLine("--Bot Position (x, y): (%.2f, %.2f)".format(bot.pinpoint?.pose?.x, bot.pinpoint?.pose?.y))
37-
3854
}
3955
}
56+
4057
@Deprecated("ts sucks just use the library")
4158
private fun calculateAprilTag() {
4259
val detections = processor.detections
@@ -88,5 +105,4 @@ class AprilTagsTest : BaseOpMode() {
88105
}
89106
}
90107
}
91-
92108
}

TeamCode/src/main/kotlin/pioneer/opmodes/other/ObeliskTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package pioneer.opmodes.other
22

33
import com.qualcomm.robotcore.eventloop.opmode.TeleOp
44
import pioneer.Bot
5-
import pioneer.hardware.Camera
65
import pioneer.decode.Obelisk
76
import pioneer.general.AllianceColor
7+
import pioneer.hardware.Camera
88
import pioneer.opmodes.BaseOpMode
99

1010
@TeleOp(name = "Obelisk Test")

TeamCode/src/main/kotlin/pioneer/vision/ColorBlob.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@ import org.firstinspires.ftc.vision.opencv.ColorRange
1111
import org.firstinspires.ftc.vision.opencv.ImageRegion
1212

1313
class ColorBlob(
14-
targetColor: ColorRange? = null, // null = detects ALL blobs
14+
targetColor: ColorRange? = null, // null = detects ALL blobs
1515
draw: Boolean = false,
1616
) : Processor {
1717
override val processor: ColorBlobLocatorProcessor =
1818
ColorBlobLocatorProcessor
1919
.Builder()
20-
.apply { targetColor?.let { setTargetColorRange(it) } } // Only set if provided
20+
.apply { targetColor?.let { setTargetColorRange(it) } } // Only set if provided
2121
.setContourMode(ContourMode.EXTERNAL_ONLY)
22-
23-
.setBlurSize(10) // Smooth the transitions between different colors in image
24-
.setDilateSize(15) // Expand blobs to fill any divots on the edges
25-
.setErodeSize(15) // Shrink blobs back to original size
22+
.setBlurSize(10) // Smooth the transitions between different colors in image
23+
.setDilateSize(15) // Expand blobs to fill any divots on the edges
24+
.setErodeSize(15) // Shrink blobs back to original size
2625
.setMorphOperationType(MorphOperationType.CLOSING)
27-
2826
.setRoi(ImageRegion.asUnityCenterCoordinates(-0.9, 0.9, 0.9, -0.9)) // Eliminate detection near edges
2927
.setDrawContours(draw)
30-
.setBoxFitColor(0) // Disable the drawing of rectangles
28+
.setBoxFitColor(0) // Disable the drawing of rectangles
3129
.setCircleFitColor(Color.rgb(255, 255, 0)) // Draw a circle
3230
.build()
3331

TeamCode/src/main/kotlin/pioneer/vision/MultiColorBlob.kt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.firstinspires.ftc.vision.opencv.ColorBlobLocatorProcessor.Blob
44
import org.firstinspires.ftc.vision.opencv.ColorBlobLocatorProcessor.BlobCriteria
55
import org.firstinspires.ftc.vision.opencv.ColorRange
66

7-
87
/**
98
* Manages multiple ColorBlob processors to detect multiple colors simultaneously.
109
* Each color gets its own processor for optimal detection.
@@ -21,16 +20,12 @@ class MultiColorBlob(
2120
/**
2221
* Get all detected blobs from all color processors combined.
2322
*/
24-
fun getAllBlobs(): List<Blob> {
25-
return vps.flatMap { it.getBlobs() }
26-
}
23+
fun getAllBlobs(): List<Blob> = vps.flatMap { it.getBlobs() }
2724

2825
/**
2926
* Get blobs for a specific color by index (0-based).
3027
*/
31-
fun getBlobsForColor(colorIndex: Int): List<Blob> {
32-
return vps.getOrNull(colorIndex)?.getBlobs() ?: emptyList()
33-
}
28+
fun getBlobsForColor(colorIndex: Int): List<Blob> = vps.getOrNull(colorIndex)?.getBlobs() ?: emptyList()
3429

3530
/**
3631
* Get blobs filtered by criteria across all colors.
@@ -39,28 +34,20 @@ class MultiColorBlob(
3934
criteria: BlobCriteria,
4035
minValue: Double,
4136
maxValue: Double,
42-
): List<Blob> {
43-
return vps.flatMap { it.getBlobsByCriteria(criteria, minValue, maxValue) }
44-
}
37+
): List<Blob> = vps.flatMap { it.getBlobsByCriteria(criteria, minValue, maxValue) }
4538

4639
/**
4740
* Get the largest blob across all colors.
4841
*/
49-
fun getLargestBlob(): Blob? {
50-
return getAllBlobs().maxByOrNull { it.contourArea }
51-
}
42+
fun getLargestBlob(): Blob? = getAllBlobs().maxByOrNull { it.contourArea }
5243

5344
/**
5445
* Get the most circular blob across all colors.
5546
*/
56-
fun getMostCircular(): Blob? {
57-
return getAllBlobs().maxByOrNull { it.circularity }
58-
}
47+
fun getMostCircular(): Blob? = getAllBlobs().maxByOrNull { it.circularity }
5948

6049
/**
6150
* Get the densest blob across all colors.
6251
*/
63-
fun getDensest(): Blob? {
64-
return getAllBlobs().maxByOrNull { it.density }
65-
}
52+
fun getDensest(): Blob? = getAllBlobs().maxByOrNull { it.density }
6653
}

0 commit comments

Comments
 (0)