@@ -24,6 +24,7 @@ class TeleopDriver2(
2424 private val isEstimatingSpeed = Toggle (true )
2525 private val flywheelToggle = Toggle (false )
2626 private val launchToggle = Toggle (false )
27+ private val multiShotToggle = Toggle (false )
2728 private val launchPressedTimer = ElapsedTime ()
2829 private var tagShootingTarget = Pose () // Shooting target from goal tag class
2930 private var offsetShootingTarget = Pose () // Shooting target that has been rotated by manual adjustment
@@ -36,12 +37,24 @@ class TeleopDriver2(
3637 var manualFlywheelSpeed = 0.0
3738 var flywheelSpeedOffset = 0.0
3839 var turretTargetAngle = 0.0
40+ var errorDegrees = 0.0
41+ var shootCommanded = false
42+ var triggerMultishot = false
43+
44+ var multishotState = MultishotState .IDLE
45+
46+ enum class MultishotState {
47+ IDLE ,
48+ MOVING ,
49+ SHOOTING
50+ }
3951
4052 fun update () {
4153 updateFlywheelSpeed()
4254 handleFlywheel()
4355 handleTurret()
4456 handleShootInput()
57+ handleMultiShot()
4558 processShooting()
4659 updateIndicatorLED()
4760 }
@@ -96,8 +109,6 @@ class TeleopDriver2(
96109
97110 private fun handleFlywheel () {
98111 flywheelToggle.toggle(gamepad.dpad_right)
99- FileLogger .debug(" Teleop Driver 2" , flywheelToggle.state.toString())
100- FileLogger .debug(" Flywheel Speed" , flywheelSpeed.toString())
101112 if (flywheelToggle.state) {
102113 bot.flywheel?.velocity = flywheelSpeed
103114 } else {
@@ -119,24 +130,72 @@ class TeleopDriver2(
119130 }
120131 }
121132
133+ private fun handleMultiShot () {
134+ multiShotToggle.toggle(gamepad.touchpad)
135+
136+ when (multishotState) {
137+ MultishotState .IDLE -> {
138+ if (multiShotToggle.justChanged && multiShotToggle.state) {
139+ multishotState = MultishotState .MOVING
140+ FileLogger .debug(" Teleop Driver 2" , " Should have changed to MOVING" )
141+ }
142+ }
143+ MultishotState .MOVING -> {
144+ shootArtifact()
145+ if (multiShotToggle.justChanged && multiShotToggle.state) {
146+ FileLogger .debug(" Teleop Driver 2" , " Changed back to IDLE" )
147+ multishotState = MultishotState .IDLE
148+ }
149+
150+ val atSpeed = bot.flywheel?.velocity?.let {
151+ if (abs(flywheelSpeed - it) < 20.0 ) { true }
152+ else { false }
153+ }
154+
155+ if (bot.spindexer?.reachedTarget == true && atSpeed == true ) {
156+ multishotState = MultishotState .SHOOTING
157+ triggerMultishot = true
158+ }
159+ }
160+ MultishotState .SHOOTING -> {
161+ if (multiShotToggle.justChanged && multiShotToggle.state) {
162+ multishotState = MultishotState .IDLE
163+ }
164+ if (shootingArtifact) {
165+ triggerMultishot = false
166+ }
167+ if (! shootingArtifact && ! triggerMultishot) {
168+ multishotState = MultishotState .MOVING
169+ }
170+ }
171+ }
172+
173+ if (bot.spindexer?.isEmpty == true ) {
174+ multishotState = MultishotState .IDLE
175+ }
176+ }
177+
122178 private fun processShooting () {
123179 if (shootingArtifact && bot.launcher?.isReset == true ) {
124180 shootingArtifact = false
125181 bot.spindexer?.popCurrentArtifact()
126182 }
127183 if (! flywheelToggle.state) return
184+
128185 launchToggle.toggle(gamepad.square)
129- if (launchToggle.justChanged &&
186+ shootCommanded = launchToggle.justChanged || triggerMultishot
187+
188+ if (shootCommanded &&
130189 bot.spindexer?.withinDetectionTolerance == true &&
131190 bot.spindexer?.isOuttakePosition == true
132191 ) {
133192 bot.launcher?.triggerLaunch()
134193 shootingArtifact = true
135- } else if (launchToggle.justChanged && launchPressedTimer.seconds() < 0.5 ) {
194+ } else if (shootCommanded && launchPressedTimer.seconds() < 0.5 ) {
136195 bot.launcher?.triggerLaunch()
137196 shootingArtifact = true
138197 }
139- if (launchToggle.justChanged ) launchPressedTimer.reset()
198+ if (shootCommanded ) launchPressedTimer.reset()
140199 }
141200
142201 private fun shootArtifact (artifact : Artifact ? = null) {
0 commit comments