Skip to content

Commit ccf5984

Browse files
committed
11/11/25
1 parent 7eb5f0d commit ccf5984

File tree

15 files changed

+191
-117
lines changed

15 files changed

+191
-117
lines changed

TeamCode/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ android {
2121
dependencies {
2222
implementation project(':FtcRobotController')
2323

24-
implementation 'com.github.AshOnDiscord.FTC-OffSeason:cmdx:01bc6d6334'
25-
implementation 'com.github.AshOnDiscord.FTC-OffSeason:cmdxpedro:01bc6d6334'
24+
implementation 'com.github.AshOnDiscord.FTC-OffSeason:cmdx:67adbc2b80'
25+
implementation 'com.github.AshOnDiscord.FTC-OffSeason:cmdxpedro:67adbc2b80'
2626

2727
// maven local
2828
// implementation('com.millburnx:cmdx:+')

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/common/hardware/GamepadManager.kt

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.firstinspires.ftc.teamcode.common.hardware.gamepad
2+
3+
import com.millburnx.cmdxpedro.util.geometry.vector.Vec2d
4+
5+
class DPad(var left: Boolean, var up: Boolean, var right: Boolean, var down: Boolean) {
6+
val vector: Vec2d
7+
get() {
8+
val x = (if (right) 1.0 else 0.0) - (if (left) 1.0 else 0.0)
9+
val y = (if (up) 1.0 else 0.0) - (if (down) 1.0 else 0.0)
10+
return Vec2d(x, y)
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.firstinspires.ftc.teamcode.common.hardware.gamepad
2+
3+
class Gamepad(private val gamepad: com.qualcomm.robotcore.hardware.Gamepad) {
4+
var current: GamepadState = GamepadState(gamepad)
5+
var prev: GamepadState = GamepadState(gamepad)
6+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.firstinspires.ftc.teamcode.common.hardware.gamepad
2+
3+
import com.bylazar.gamepad.GamepadManager
4+
import com.bylazar.gamepad.PanelsGamepad
5+
import org.firstinspires.ftc.teamcode.opmode.OpMode
6+
7+
class GamepadManager(private val opMode: OpMode) {
8+
private val _panelsGamepad1: GamepadManager = PanelsGamepad.firstManager
9+
private val _panelsGamepad2: GamepadManager = PanelsGamepad.secondManager
10+
11+
private val _gamepad1: com.qualcomm.robotcore.hardware.Gamepad
12+
get() = _panelsGamepad1.asCombinedFTCGamepad(opMode.gamepad1)
13+
private val _gamepad2: com.qualcomm.robotcore.hardware.Gamepad
14+
get() = _panelsGamepad2.asCombinedFTCGamepad(opMode.gamepad2)
15+
16+
val gamepad1: Gamepad = Gamepad(_gamepad1)
17+
val gamepad2: Gamepad = Gamepad(_gamepad2)
18+
19+
fun update() {
20+
val oldState1 = gamepad1.current
21+
val oldState2 = gamepad2.current
22+
23+
val newState1 = GamepadState(_gamepad1)
24+
val newState2 = GamepadState(_gamepad2)
25+
gamepad1.current = newState1
26+
gamepad2.current = newState2
27+
28+
gamepad1.prev = oldState1
29+
gamepad2.prev = oldState2
30+
}
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.firstinspires.ftc.teamcode.common.hardware.gamepad
2+
3+
class GamepadState(private val gamepad: com.qualcomm.robotcore.hardware.Gamepad) {
4+
val leftJoyStick = JoyStick(
5+
gamepad.left_stick_x.toDouble(),
6+
gamepad.left_stick_y.toDouble(),
7+
gamepad.left_stick_button
8+
)
9+
10+
val rightJoyStick = JoyStick(
11+
gamepad.right_stick_x.toDouble(),
12+
gamepad.right_stick_y.toDouble(),
13+
gamepad.right_stick_button
14+
)
15+
16+
val dPad = DPad(
17+
gamepad.dpad_left,
18+
gamepad.dpad_up,
19+
gamepad.dpad_right,
20+
gamepad.dpad_down
21+
)
22+
23+
val a: Boolean = gamepad.a
24+
val b: Boolean = gamepad.b
25+
val x: Boolean = gamepad.x
26+
val y: Boolean = gamepad.y
27+
28+
val guide: Boolean = gamepad.guide
29+
val start: Boolean = gamepad.start
30+
val back = gamepad.back
31+
32+
val leftBumper: Boolean = gamepad.left_bumper
33+
val rightBumper: Boolean = gamepad.right_bumper
34+
35+
val leftTrigger: Double = gamepad.left_trigger.toDouble()
36+
val rightTrigger: Double = gamepad.right_trigger.toDouble()
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.firstinspires.ftc.teamcode.common.hardware.gamepad
2+
3+
import com.millburnx.cmdxpedro.util.geometry.vector.Vec2d
4+
5+
class JoyStick(var x: Double, var y: Double, var down: Boolean) {
6+
val vector: Vec2d
7+
get() = Vec2d(x, y)
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.firstinspires.ftc.teamcode.common.hardware.gamepad
2+
3+
import com.millburnx.cmdxpedro.util.geometry.vector.Vec2d
4+
import com.millburnx.cmdxpedro.util.toDegrees
5+
import org.firstinspires.ftc.teamcode.common.normalizeDegrees
6+
import kotlin.math.abs
7+
8+
object SlewRateLimiter {
9+
fun limit(current: Double, target: Double, maxRate: Double): Double {
10+
val rate = target - current
11+
return current + rate.coerceIn(-maxRate, maxRate)
12+
}
13+
14+
fun limit(current: Vec2d, target: Vec2d, maxMagnitudeRate: Double, maxRotationRate: Double): Vec2d {
15+
// if angle diff < 90, slew angle and magnitude, if angle > thresh, focus on slewing magnitude (cross-over!)
16+
val targetAngle = Vec2d().angleTo(target).toDegrees()
17+
val currentAngle = Vec2d().angleTo(current).toDegrees()
18+
val angleDiff = normalizeDegrees(targetAngle - currentAngle)
19+
20+
if (abs(angleDiff) <= 135) {
21+
// TODO: Implement this stuff
22+
}
23+
24+
return Vec2d()
25+
}
26+
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/common/subsystem/Apriltags.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ class Apriltags : Subsystem("Apriltags") {
3434
}
3535

3636
fun AprilTagDetection.toPose(currentPose: Pose2d): Pose2d {
37-
val offset = Vec2d(ftcPose.range, 0).rotate(currentPose.radians + ftcPose.bearing.toRadians())
37+
val offset = Vec2d(ftcPose.range).rotate(currentPose.radians + ftcPose.bearing.toRadians())
3838
return Pose2d(currentPose.position + offset, currentPose.heading + ftcPose.yaw)
3939
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/common/subsystem/AutoTargetting.kt renamed to TeamCode/src/main/java/org/firstinspires/ftc/teamcode/common/subsystem/AutoTargeting.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.millburnx.cmdxpedro.util.WaitFor
66
import org.firstinspires.ftc.teamcode.common.roundTo
77
import org.firstinspires.ftc.teamcode.opmode.OpMode
88

9-
class AutoTargetting(opMode: OpMode, pedro: Pedro, apriltags: Apriltags) : Subsystem("Auto Targeting") {
9+
class AutoTargeting(opMode: OpMode, pedro: Pedro, apriltags: Apriltags) : Subsystem("Auto Targeting") {
1010

1111
var enabled = false
1212
var target: Pose2d? = null
@@ -32,7 +32,7 @@ class AutoTargetting(opMode: OpMode, pedro: Pedro, apriltags: Apriltags) : Subsy
3232
if (newLocked != pedro.isLocked) {
3333
pedro.isLocked = newLocked
3434
if (newLocked) {
35-
pedro.follower.turnTo(pedro.pose.position.angle(target!!.position))
35+
pedro.follower.turnTo(pedro.pose.angleTo(target!!))
3636
} else {
3737
pedro.follower.startTeleopDrive(true)
3838
}

0 commit comments

Comments
 (0)