-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.team4099.apriltag | ||
|
||
import edu.wpi.first.apriltag.AprilTag | ||
import org.team4099.lib.geometry.Pose3d | ||
|
||
class AprilTag(val id: Int, val pose: Pose3d) { | ||
constructor(apriltagWpilib: AprilTag) : this(apriltagWpilib.ID, Pose3d(apriltagWpilib.pose)) {} | ||
|
||
val apriltagWpilib = AprilTag(id, pose.pose3d) | ||
|
||
override fun equals(obj: Any?): Boolean { | ||
if (obj is com.team4099.apriltag.AprilTag) { | ||
val other = obj | ||
return id == other.id && pose == other.pose | ||
} | ||
return false | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/org/team4099/lib/apriltag/AprilTagFieldLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.team4099.apriltag | ||
|
||
import edu.wpi.first.apriltag.AprilTagFieldLayout | ||
import org.team4099.lib.geometry.Pose3d | ||
import org.team4099.lib.geometry.Rotation3d | ||
import org.team4099.lib.geometry.Translation3d | ||
import org.team4099.lib.units.base.Length | ||
import org.team4099.lib.units.base.inMeters | ||
import org.team4099.lib.units.base.meters | ||
import org.team4099.lib.units.derived.radians | ||
|
||
class AprilTagFieldLayout( | ||
val aprilTags: List<AprilTag>, | ||
val fieldLength: Length, | ||
val fieldWidth: Length | ||
) { | ||
|
||
init { | ||
setOrigin(OriginPosition.kBlueAllianceWallRightSide) | ||
} | ||
|
||
val apriltagFieldLayoutWPILIB = | ||
AprilTagFieldLayout( | ||
aprilTags.map { it.apriltagWpilib }, fieldLength.inMeters, fieldWidth.inMeters | ||
) | ||
|
||
var origin = Pose3d() | ||
|
||
fun getTagPose(id: Int): Pose3d { | ||
if (id < aprilTags.size) { | ||
return Pose3d((-1337).meters, (-1337).meters, (-1337).meters, Rotation3d()) | ||
} | ||
return aprilTags[id].pose | ||
} | ||
|
||
fun setOrigin(newOrigin: OriginPosition) { | ||
origin = | ||
when (newOrigin) { | ||
OriginPosition.kBlueAllianceWallRightSide -> Pose3d() | ||
OriginPosition.kRedAllianceWallRightSide -> | ||
Pose3d( | ||
Translation3d(fieldLength, fieldWidth, 0.meters), | ||
Rotation3d(0.radians, 0.radians, Math.PI.radians) | ||
) | ||
} | ||
} | ||
|
||
data class FieldDimensions(val fieldWidth: Length, val fieldLength: Length) | ||
|
||
enum class OriginPosition { | ||
kBlueAllianceWallRightSide, | ||
kRedAllianceWallRightSide | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters