@@ -19,30 +19,33 @@ class TeleopDriver2(
1919 private val gamepad : Gamepad ,
2020 private val bot : Bot ,
2121) {
22- enum class FlywheelSpeed (
22+ enum class FlywheelSpeedRange (
2323 val velocity : Double ,
2424 ) {
2525 SHORT_RANGE (800.0 ),
2626 LONG_RANGE (1000.0 ),
2727 }
2828
29+ val isEstimateSpeed = Toggle (true )
2930 private val chrono = Chrono (autoUpdate = false )
3031 private val isAutoTracking = Toggle (false )
3132 private val flywheelToggle = Toggle (false )
32- private val changeFlywheelSpeedToggle = Toggle (false )
33+ private val changeFlywheelRangeToggle = Toggle (false )
3334
3435 var P = Points (bot.allianceColor)
3536
3637 enum class ShootState { READY , MOVING_TO_POSITION , LAUNCHING }
3738
38- var flywheelVelocityEnum = FlywheelSpeed .SHORT_RANGE
39+ var flywheelVelocityEnum = FlywheelSpeedRange .SHORT_RANGE
3940 var shootState = ShootState .READY
40- var targetGoal = Pose ()
41+ var targetGoal = GoalTag . RED
4142 private var shootingAll = false
4243 private var remainingShots = 0
4344 var turretAngle = 0.0
45+ var flywheelSpeed = 0.0
4446
4547 fun update () {
48+ checkTargetGoal()
4649 updateFlywheelSpeed()
4750 handleFlywheel()
4851 handleTurret()
@@ -52,24 +55,39 @@ class TeleopDriver2(
5255 chrono.update() // Manual update to allow dt to match across the loop.
5356 }
5457
58+ private fun checkTargetGoal () {
59+ if (bot.allianceColor == AllianceColor .BLUE ) {
60+ targetGoal = GoalTag .BLUE
61+ } else { return }
62+ }
63+
5564 private fun updateFlywheelSpeed () {
65+ isEstimateSpeed.toggle(gamepad.dpad_right)
5666// if (flywheelSpeed < 1.0 && gamepad.dpad_up) {
5767// flywheelSpeed += chrono.dt * 0.5
5868// }
5969// if (flywheelSpeed > 0.0 && gamepad.dpad_down) {
6070// flywheelSpeed -= chrono.dt * 0.5
6171// }
6272// flywheelSpeed = flywheelSpeed.coerceIn(0.0, 1.0)
63- changeFlywheelSpeedToggle.toggle(gamepad.dpad_up)
64- if (changeFlywheelSpeedToggle.justChanged) {
73+
74+ if (isEstimateSpeed.state) {
75+ flywheelSpeed = bot.flywheel!! .estimateVelocity(targetGoal.shootingPose, bot.pinpoint?.pose ? : Pose ())
76+ } else {
77+ flywheelSpeed = flywheelVelocityEnum.velocity
78+ }
79+
80+ changeFlywheelRangeToggle.toggle(gamepad.dpad_up)
81+
82+ if (changeFlywheelRangeToggle.justChanged) {
6583 flywheelVelocityEnum = flywheelVelocityEnum.next()
6684 }
6785 }
6886
6987 private fun handleFlywheel () {
7088 flywheelToggle.toggle(gamepad.dpad_left)
7189 if (flywheelToggle.state) {
72- bot.flywheel?.velocity = flywheelVelocityEnum.velocity
90+ bot.flywheel?.velocity = flywheelSpeed
7391 } else {
7492 bot.flywheel?.velocity = 0.0
7593 }
@@ -174,20 +192,9 @@ class TeleopDriver2(
174192
175193 private fun handleAutoTrack () {
176194 if (bot.turret?.mode == Turret .Mode .AUTO_TRACK ) {
177- if (bot.allianceColor == AllianceColor .RED ) {
178- targetGoal = GoalTag .RED .pose
179- } else {
180- targetGoal = GoalTag .BLUE .pose
181- }
182195 bot.turret?.autoTrack(
183196 bot.pinpoint?.pose ? : Pose (),
184- if (bot.allianceColor ==
185- AllianceColor .BLUE
186- ) {
187- GoalTag .BLUE .shootingPose
188- } else {
189- GoalTag .RED .shootingPose
190- },
197+ targetGoal.shootingPose,
191198 )
192199 }
193200 }
0 commit comments