@@ -3,6 +3,7 @@ package pioneer.opmodes.teleop.drivers
33import com.qualcomm.robotcore.hardware.Gamepad
44import com.qualcomm.robotcore.util.ElapsedTime
55import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor
6+ import org.openftc.apriltag.AprilTagDetection
67import pioneer.Bot
78import pioneer.decode.Artifact
89import pioneer.decode.GoalTag
@@ -15,6 +16,7 @@ import pioneer.helpers.Pose
1516import pioneer.helpers.Toggle
1617import pioneer.vision.AprilTag
1718import kotlin.math.*
19+ import kotlin.run
1820
1921class TeleopDriver2 (
2022 private val gamepad : Gamepad ,
@@ -36,8 +38,7 @@ class TeleopDriver2(
3638 var flywheelSpeed = 0.0
3739 var manualFlywheelSpeed = 0.0
3840 var flywheelSpeedOffset = 0.0
39- var turretTargetAngle = 0.0
40- var errorDegrees = 0.0
41+ var errorDegrees: Double? = 0.0
4142 var shootCommanded = false
4243 var triggerMultishot = false
4344
@@ -226,26 +227,31 @@ class TeleopDriver2(
226227 if (bot.turret?.mode == Turret .Mode .AUTO_TRACK ) {
227228 val tagDetections = bot.camera?.getProcessor<AprilTagProcessor >()?.detections
228229
230+ FileLogger .debug(" TeleopDriver2" , " Tag Detections: ${tagDetections?.map { it.id }?.joinToString { " , " }} " )
231+
229232 // Only look at goal tag for the current alliance
230- tagDetections?.filter{
233+ val filteredDetections = tagDetections?.filter{
231234 it.id == when (bot.allianceColor) {
232235 AllianceColor .RED -> GoalTag .RED .id
233236 AllianceColor .BLUE -> GoalTag .BLUE .id
234237 AllianceColor .NEUTRAL -> GoalTag .RED .id
235238 }
236239 }
237240
238- val errorDegrees = tagDetections?.firstOrNull()?.ftcPose?.bearing?.times(- 1.0 )
239- val currentRobotAngle = bot.pinpoint?.pose?.theta ? : 0.0
241+ FileLogger .debug(" TeleopDriver2" , " Tag Detections: ${filteredDetections?.map { it.id }?.joinToString { " , " }} " )
242+
243+ errorDegrees = filteredDetections?.firstOrNull()?.ftcPose?.bearing
240244 if (errorDegrees != null ) {
241- turretTargetAngle = currentRobotAngle + errorDegrees
242245 bot.turret?.tagTrack(
243- errorDegrees,
246+ errorDegrees!! .times( - 1.0 ) ,
244247 )
245248 } else {
246249 // No tag detected, use last known target
247- // TODO: Test tag loss logic
248- bot.turret?.gotoAngle(turretTargetAngle- currentRobotAngle)
250+ // TODO: fix tag loss logic
251+ bot.turret?.autoTrack(
252+ bot.pinpoint?.pose ? : Pose (),
253+ targetGoal.shootingPose
254+ )
249255 }
250256 }
251257// if (abs(gamepad.right_stick_x) > 0.02) {
0 commit comments