-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from blair-robot-project/autoAim
- Loading branch information
Showing
12 changed files
with
132 additions
and
72 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
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 frc.team449.robot2024.commands | ||
|
||
import edu.wpi.first.wpilibj2.command.Command | ||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup | ||
import edu.wpi.first.wpilibj2.command.WaitUntilCommand | ||
import frc.team449.robot2024.Robot | ||
import frc.team449.robot2024.commands.driveAlign.OrbitAlign | ||
import frc.team449.robot2024.constants.field.FieldConstants | ||
import frc.team449.robot2024.constants.subsystem.SpinShooterConstants | ||
import kotlin.math.abs | ||
|
||
class AutoAim( | ||
private val robot: Robot | ||
) : Command() { | ||
|
||
private val shootingMap = SpinShooterConstants.SHOOTING_MAP | ||
|
||
override fun initialize() { | ||
if (getDistanceToSpeaker() > SpinShooterConstants.MAX_RANGE) { | ||
this.cancel() | ||
} | ||
|
||
addRequirements(robot.shooter, robot.pivot) | ||
} | ||
|
||
override fun execute() { | ||
robot.shooter.shootSubwoofer() | ||
robot.pivot.moveToAngle(shootingMap.get(getDistanceToSpeaker())) | ||
|
||
|
||
|
||
val fieldToRobot = robot.drive.pose.translation | ||
val robotToPoint = FieldConstants.SPEAKER_POSE - fieldToRobot | ||
robot.driveCommand.snapToAngle(robotToPoint.angle.radians) | ||
|
||
if (robot.mechController.().asBoolean && | ||
abs(robot.drive.currentSpeeds.vxMetersPerSecond) <= 0.1 && abs(robot.drive.currentSpeeds.vyMetersPerSecond) <= 0.1 && abs(robot.drive.currentSpeeds.omegaRadiansPerSecond) <= 0.1 | ||
) { | ||
SequentialCommandGroup( | ||
WaitUntilCommand { robot.shooter.atSetpoint() }, | ||
robot.feeder.intake(), | ||
robot.undertaker.intake() | ||
).alongWith( | ||
robot.shooter.shootSubwoofer() | ||
).schedule() | ||
} | ||
} | ||
|
||
override fun isFinished(): Boolean { | ||
return getDistanceToSpeaker() > SpinShooterConstants.MAX_RANGE | ||
} | ||
|
||
override fun end(interrupted: Boolean) { | ||
robot.undertaker.stop() | ||
robot.shooter.rampStop() | ||
robot.feeder.stop() | ||
robot.pivot.moveStow() | ||
} | ||
|
||
private fun getDistanceToSpeaker(): Double { | ||
return abs(FieldConstants.SPEAKER_POSE.getDistance(robot.drive.pose.translation)) | ||
} | ||
} |
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
6 changes: 5 additions & 1 deletion
6
src/main/kotlin/frc/team449/robot2024/constants/field/FieldConstants.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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package frc.team449.robot2024.constants.field | ||
|
||
import edu.wpi.first.math.geometry.Translation2d | ||
import edu.wpi.first.math.util.Units | ||
|
||
object FieldConstants { | ||
const val fieldLength = 16.54175 | ||
const val fieldWidth = 8.21055 | ||
|
||
/** Find these constants in meters for the blue alliance */ | ||
val SUBWOOFER_POSE = Translation2d(1.0, 4.0) | ||
val BLUE_SPEAKER_POSE = Translation2d(Units.inchesToMeters(-1.5), Units.inchesToMeters(218.42)) | ||
val RED_SPEAKER_POSE = Translation2d(Units.inchesToMeters(652.73), Units.inchesToMeters(218.42)) | ||
|
||
var SPEAKER_POSE = BLUE_SPEAKER_POSE | ||
} |
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
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