Skip to content

Commit 9588bc4

Browse files
committed
Add camera aim adjustment (doesn't wrap)
1 parent 250d7fa commit 9588bc4

4 files changed

Lines changed: 23 additions & 19 deletions

File tree

‎TeamCode/src/main/kotlin/pioneer/hardware/Turret.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.qualcomm.robotcore.hardware.DcMotor
55
import com.qualcomm.robotcore.hardware.DcMotorEx
66
import com.qualcomm.robotcore.hardware.DcMotorSimple
77
import com.qualcomm.robotcore.hardware.HardwareMap
8+
import com.qualcomm.robotcore.hardware.PIDFCoefficients
89
import pioneer.Constants
910
import pioneer.helpers.Chrono
1011
import pioneer.helpers.MathUtils
@@ -62,6 +63,7 @@ class Turret(
6263
require(motorRange.first < motorRange.second) {
6364
"Motor range must be valid: ${motorRange.first} to ${motorRange.second}"
6465
}
66+
tagTrackPID.integralClamp = 1.0
6567
}
6668

6769
override fun init() {
@@ -71,6 +73,10 @@ class Turret(
7173
mode = DcMotor.RunMode.RUN_USING_ENCODER
7274
zeroPowerBehavior = DcMotor.ZeroPowerBehavior.FLOAT
7375
direction = DcMotorSimple.Direction.FORWARD
76+
// setPIDFCoefficients(
77+
// DcMotor.RunMode.RUN_USING_ENCODER,
78+
// PIDFCoefficients(1.0, 0.0, 0.0, 0.0)
79+
// )
7480
}
7581
}
7682

‎TeamCode/src/main/kotlin/pioneer/opmodes/calibration/ManualSpindexerControl.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ManualSpindexerControl : OpMode() {
1313
var power = 0.0
1414

1515
override fun init() {
16-
motor = hardwareMap.get(DcMotorEx::class.java, Constants.HardwareNames.SPINDEXER_MOTOR)
16+
motor = hardwareMap.get(DcMotorEx::class.java, Constants.HardwareNames.TURRET_MOTOR)
1717
}
1818

1919
override fun loop() {

‎TeamCode/src/main/kotlin/pioneer/opmodes/teleop/Teleop.kt‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ class Teleop : BaseOpMode() {
6262
}
6363

6464
private fun addTelemetryData() {
65-
val detection = bot.camera?.getProcessor<AprilTagProcessor>()?.detections?.firstOrNull()?.ftcPose
66-
addTelemetryData("Multishot state", driver2.multishotState, Verbose.DEBUG)
67-
addTelemetryData("April Tag Relative Position", "x: ${detection?.x} y: ${detection?.y} bearing: ${detection?.bearing}", Verbose.FATAL)
68-
addTelemetryData("Shooting Distance", hypot(detection?.x ?: 0.0, detection?.y ?: 0.0), Verbose.FATAL)
69-
// telemetry.addData("Transfer Data", Constants.TransferData.turretPositionTicks)
70-
// telemetry.addData("Turret Offset Ticks", bot.turret?.offsetTicks)
71-
// telemetry.addData("Turret Angle", bot.turret?.currentAngle)
7265
addTelemetryData("Alliance Color", bot.allianceColor, Verbose.INFO)
7366
addTelemetryData("Drive Power", driver1.drivePower, Verbose.INFO)
7467
addTelemetryData("Pose", bot.pinpoint!!.pose, Verbose.DEBUG)
@@ -86,8 +79,7 @@ class Teleop : BaseOpMode() {
8679
addTelemetryData("Drive Power", driver1.drivePower, Verbose.DEBUG)
8780
addTelemetryData("Spindexer State", bot.spindexer?.motorState, Verbose.INFO)
8881

89-
addTelemetryData("Relative Tag Pose", Pose(driver1.detection?.ftcPose?.x ?: 0.0, driver1.detection?.ftcPose?.y ?: 0.0), Verbose.FATAL)
90-
addTelemetryData("Robot Pose Tag", driver1.robotPoseTag, Verbose.FATAL)
82+
addTelemetryData("April Tag Relative Error", driver2.errorDegrees, Verbose.INFO)
9183

9284
addTelemetryData("Spindexer Target Ticks", bot.spindexer?.targetMotorTicks, Verbose.DEBUG)
9385
addTelemetryData("Spindexer Ticks", bot.spindexer?.currentMotorTicks, Verbose.DEBUG)

‎TeamCode/src/main/kotlin/pioneer/opmodes/teleop/drivers/TeleopDriver2.kt‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pioneer.opmodes.teleop.drivers
33
import com.qualcomm.robotcore.hardware.Gamepad
44
import com.qualcomm.robotcore.util.ElapsedTime
55
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor
6+
import org.openftc.apriltag.AprilTagDetection
67
import pioneer.Bot
78
import pioneer.decode.Artifact
89
import pioneer.decode.GoalTag
@@ -15,6 +16,7 @@ import pioneer.helpers.Pose
1516
import pioneer.helpers.Toggle
1617
import pioneer.vision.AprilTag
1718
import kotlin.math.*
19+
import kotlin.run
1820

1921
class 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

Comments
 (0)