Skip to content

Commit

Permalink
Elevator and Arm Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SachetK committed Dec 16, 2024
1 parent fc7777d commit 0b02047
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ class ArmCommand(
override fun initialize() {
subsystem.setpoint = setpoint
}

override fun execute() = subsystem.operateArm()

override fun isFinished(): Boolean = subsystem.isBusy

override fun end(interrupted: Boolean) = subsystem.stop()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.firstinspires.ftc.teamcode.commands.elevator

import com.arcrobotics.ftclib.command.CommandBase
import org.firstinspires.ftc.teamcode.subsystems.slides.ElevatorSubsystem

class ElevatorCommand(
private val subsystem: ElevatorSubsystem,
private val setpoint: Double
) : CommandBase() {
override fun initialize() {
subsystem.setpoint = setpoint
}

override fun execute() = subsystem.operateElevator()

override fun isFinished(): Boolean = subsystem.isBusy

override fun end(interrupted: Boolean) = subsystem.stop()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import org.firstinspires.ftc.teamcode.subsystems.slides.ElevatorSubsystem
class SpinDownCommand(
private val subsystem: ElevatorSubsystem
) : CommandBase() {


override fun execute() {
subsystem.spinDown()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.firstinspires.ftc.teamcode.subsystems.slides.ElevatorSubsystem
class SpinUpCommand(
private val subsystem: ElevatorSubsystem
) : CommandBase() {

override fun execute() {
subsystem.spinUp()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ArmPIDTuner : CommandOpMode() {

RunCommand({
ArmSubsystem.setpoint = Math.toRadians(target)
ArmSubsystem.operateArm()
}).perpetually().schedule()

RunCommand({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ class SlidesPIDTuner : CommandOpMode() {

RunCommand({
ElevatorSubsystem.setpoint = target
ElevatorSubsystem.operateElevator()
}).perpetually().schedule()

RunCommand({
telemetry.addData("Slides Position", ElevatorSubsystem.position)
telemetry.addData("Setpoint", target)

telemetry.addData("Arm Angle", ArmSubsystem.angle)
telemetry.addData("Slides Velocity", ElevatorSubsystem.velocity)

telemetry.update()
}).perpetually().schedule()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ object ArmSubsystem : SubsystemBase() {
ArmConstants.MAX_ACCELERATION.value
)
)
val isBusy
get() = controller.atGoal()

var setpoint = controller.goal.position
set(value) {
Expand All @@ -43,7 +45,7 @@ object ArmSubsystem : SubsystemBase() {

private var enabled = true

fun initialize(hardwareMap: HardwareMap) : ArmSubsystem {
fun initialize(hardwareMap: HardwareMap) {
val armLeft = Motor(hardwareMap, ControlBoard.ARM_LEFT.deviceName)
val armRight = Motor(hardwareMap, ControlBoard.ARM_RIGHT.deviceName)

Expand All @@ -53,8 +55,6 @@ object ArmSubsystem : SubsystemBase() {

turnMotors.resetEncoder()
turnMotors.setZeroPowerBehavior(Motor.ZeroPowerBehavior.BRAKE)

return this
}


Expand All @@ -70,7 +70,7 @@ object ArmSubsystem : SubsystemBase() {
turnMotors.set(0.0)
}

override fun periodic() {
fun operateArm() {
val output = controller.calculate(angle) + feedforward.calculate(angle, velocity)

if (enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ object ElevatorSubsystem: SubsystemBase() {
field = clamped
}

val isBusy
get() = controller.atGoal()

val position: Double
get() = elevatorMotors.positions[0] * SlidesConstants.MAX_HEIGHT_INCH.value / SlidesConstants.MAX_HEIGHT_TICKS.value

Expand Down Expand Up @@ -69,7 +72,7 @@ object ElevatorSubsystem: SubsystemBase() {
elevatorMotors.set(SlidesConstants.kG.value * sin(ArmSubsystem.angle))
}

override fun periodic() {
fun operateElevator() {
val output = controller.calculate(position) +
SlidesConstants.kG.value * sin(ArmSubsystem.angle)

Expand Down

0 comments on commit 0b02047

Please sign in to comment.