-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
268 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.rambots.commands | ||
|
||
import edu.wpi.first.wpilibj2.command.Command | ||
import org.rambots.config.ArmConstants.ARM_ACCEPTABLE_ERROR | ||
import org.rambots.subsystems.ArmSubsystem | ||
import org.rambots.util.CommandUtils.generateErrorRange | ||
|
||
class ArmPositionCommand(private val angle: () -> Double, private val finishState: () -> Double) : Command() { | ||
|
||
constructor(angle: () -> Double) : this(angle, angle) | ||
constructor(angle: Double) : this ({angle}) | ||
|
||
init { | ||
addRequirements(ArmSubsystem) | ||
} | ||
|
||
override fun initialize() { | ||
ArmSubsystem.desiredPosition = angle.invoke() | ||
} | ||
|
||
override fun execute() { | ||
ArmSubsystem.position = angle.invoke() | ||
} | ||
|
||
override fun isFinished(): Boolean { | ||
return generateErrorRange(ArmSubsystem.position, ARM_ACCEPTABLE_ERROR).contains(finishState.invoke()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/org/rambots/commands/ElevatorPositionCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.rambots.commands | ||
|
||
import edu.wpi.first.wpilibj2.command.Command | ||
import org.rambots.config.ArmConstants.ARM_ACCEPTABLE_ERROR | ||
import org.rambots.subsystems.ElevatorSubsystem | ||
import org.rambots.util.CommandUtils.generateErrorRange | ||
|
||
class ElevatorPositionCommand(private val position: () -> Double, private val finishState: () -> Double) : Command() { | ||
|
||
constructor(position: () -> Double) : this(position, position) | ||
constructor(position: Double) : this ({position}) | ||
|
||
init { | ||
addRequirements(ElevatorSubsystem) | ||
} | ||
|
||
override fun initialize() { | ||
ElevatorSubsystem.desiredPosition = position.invoke() | ||
} | ||
|
||
override fun execute() { | ||
ElevatorSubsystem.position = position.invoke() | ||
} | ||
|
||
override fun isFinished(): Boolean { | ||
return generateErrorRange(ElevatorSubsystem.position, ARM_ACCEPTABLE_ERROR).contains(finishState.invoke()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.rambots.config | ||
|
||
import com.pathplanner.lib.util.PIDConstants | ||
|
||
object ArmConstants { | ||
/** Arm Configuration */ | ||
const val ARM_NEO_LEADER_ID = 13 | ||
const val ARM_NEO_FOLLOWER_ID = 14 | ||
|
||
val ARM_PID = PIDConstants(0.02, 0.0, 0.0) | ||
|
||
val ARM_ACCEPTABLE_ERROR = 0.5 | ||
|
||
|
||
|
||
/** Elevator PID */ | ||
const val ElevatorKP = 0.2 | ||
const val ElevatorKI = 0.0 | ||
const val ElevatorKD = 0.0 | ||
|
||
/** Intake Configuration */ | ||
const val IntakeMotorOneCANID = 17 | ||
const val IntakeMotorTwoCANID = 18 | ||
const val IntakePower = -0.2 | ||
const val IntakeCurrent = 20 | ||
|
||
/** Shooter Configuration */ | ||
const val TopShooterCANID = 19 | ||
const val BottomShooterCANID = 20 | ||
|
||
/** Shooter PID */ | ||
const val ShooterKP = 0.00035 | ||
const val ShooterKD = 0.15 | ||
|
||
/** Wrist Configuration */ | ||
const val WristCANID = 21 | ||
|
||
/** Wrist PID */ | ||
const val WristKP = 0.2 | ||
const val WristKI = 0.0 | ||
const val WristKD = 0.0 | ||
|
||
/** Intake Positions */ | ||
const val ArmIntakePosition = 0.0 | ||
const val WristIntakePosition = -63.0 | ||
const val ElevatorIntakePosition = -50.0 | ||
|
||
/** Climb Positions */ | ||
const val ArmClimbPosition = -70.0 | ||
const val ElevatorClimbPosition = -70.0 | ||
const val ElevatorRetractPosition = 0.0 | ||
|
||
/** Manual Arm Controls */ | ||
// place holders | ||
const val MaximumAngle = 90 | ||
const val MinimumAngle = 30 | ||
const val ArmIdlePosition = -45.0 | ||
|
||
/** Limelight */ | ||
const val LimelightMountAngleDegrees = 25.0 | ||
const val LimelightLensHeightInches = 20.0 | ||
const val SpeakerGoalHeightInches = 50.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.rambots.config | ||
|
||
import com.pathplanner.lib.util.PIDConstants | ||
|
||
object ElevatorConstants { | ||
|
||
const val ELEVATOR_LEADER_ID = 15 | ||
const val ELEVATOR_FOLLOWER_ID = 16 | ||
|
||
val ELEVATOR_PID = PIDConstants(0.2, 0.0, 0.0) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.rambots.subsystems | ||
|
||
import com.revrobotics.CANSparkBase | ||
import com.revrobotics.CANSparkLowLevel | ||
import com.revrobotics.CANSparkMax | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger | ||
import org.rambots.config.ArmConstants.ARM_NEO_FOLLOWER_ID | ||
import org.rambots.config.ArmConstants.ARM_NEO_LEADER_ID | ||
import org.rambots.config.ArmConstants.ARM_PID | ||
|
||
object ArmSubsystem : SubsystemBase() { | ||
|
||
var offset = 0.0 | ||
var desiredPosition = 0.0 + offset | ||
var position | ||
get() = leader.encoder.position | ||
set(value) { | ||
leader.pidController.setReference(value, CANSparkBase.ControlType.kPosition) | ||
} | ||
|
||
private val leader = CANSparkMax(ARM_NEO_LEADER_ID, CANSparkLowLevel.MotorType.kBrushless).apply { | ||
restoreFactoryDefaults() | ||
|
||
idleMode = CANSparkBase.IdleMode.kBrake | ||
pidController.apply { | ||
p = ARM_PID.kP | ||
i = ARM_PID.kI | ||
d = ARM_PID.kD | ||
} | ||
|
||
setSmartCurrentLimit(40) | ||
} | ||
|
||
private val follower = CANSparkMax(ARM_NEO_FOLLOWER_ID, CANSparkLowLevel.MotorType.kBrushless) | ||
|
||
init { | ||
follower.restoreFactoryDefaults() | ||
follower.follow(leader, true) | ||
} | ||
|
||
override fun periodic() { | ||
Logger.recordOutput("Arm/DesiredPosition", desiredPosition) | ||
Logger.recordOutput("Arm/Offset", offset) | ||
Logger.recordOutput("Arm/Position", leader.encoder.position) | ||
Logger.recordOutput("Arm/Velocity", leader.encoder.velocity) | ||
Logger.recordOutput("Arm/Current", leader.outputCurrent) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.rambots.subsystems | ||
|
||
import com.revrobotics.CANSparkBase | ||
import com.revrobotics.CANSparkLowLevel | ||
import com.revrobotics.CANSparkMax | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger | ||
import org.rambots.config.ArmConstants.ARM_NEO_FOLLOWER_ID | ||
import org.rambots.config.ArmConstants.ARM_NEO_LEADER_ID | ||
import org.rambots.config.ArmConstants.ARM_PID | ||
import org.rambots.config.ElevatorConstants.ELEVATOR_FOLLOWER_ID | ||
import org.rambots.config.ElevatorConstants.ELEVATOR_LEADER_ID | ||
import org.rambots.config.ElevatorConstants.ELEVATOR_PID | ||
|
||
object ElevatorSubsystem : SubsystemBase() { | ||
|
||
var offset = 0.0 | ||
var desiredPosition = 0.0 + offset | ||
var position | ||
get() = leader.encoder.position | ||
set(value) { | ||
leader.pidController.setReference(value, CANSparkBase.ControlType.kPosition) | ||
} | ||
|
||
private val leader = CANSparkMax(ELEVATOR_LEADER_ID, CANSparkLowLevel.MotorType.kBrushless).apply { | ||
restoreFactoryDefaults() | ||
|
||
idleMode = CANSparkBase.IdleMode.kBrake | ||
pidController.apply { | ||
p = ELEVATOR_PID.kP | ||
i = ELEVATOR_PID.kI | ||
d = ELEVATOR_PID.kD | ||
} | ||
|
||
setSmartCurrentLimit(40) | ||
} | ||
|
||
private val follower = CANSparkMax(ELEVATOR_FOLLOWER_ID, CANSparkLowLevel.MotorType.kBrushless) | ||
|
||
init { | ||
follower.restoreFactoryDefaults() | ||
follower.follow(leader, true) | ||
} | ||
|
||
override fun periodic() { | ||
Logger.recordOutput("Elevator/DesiredPosition", desiredPosition) | ||
Logger.recordOutput("Elevator/Offset", offset) | ||
Logger.recordOutput("Elevator/Position", leader.encoder.position) | ||
Logger.recordOutput("Elevator/Velocity", leader.encoder.velocity) | ||
Logger.recordOutput("Elevator/Current", leader.outputCurrent) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.rambots.util | ||
|
||
object CommandUtils { | ||
|
||
fun generateErrorRange(value: Double, error: Double): ClosedRange<Double> = (value - error)..(value + error) | ||
|
||
} |