Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
MustacheNinja23 committed Oct 21, 2024
1 parent b78b9bf commit 78645cd
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/RobotContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import edu.wpi.first.wpilibj2.command.Commands
import edu.wpi.first.wpilibj2.command.button.CommandXboxController
import frc.robot.generated.TunerConstants
import frc.robot.subsystems.CommandSwerveDrivetrain
import frc.robot.subsystems.VisionSubsystem
import java.util.function.Supplier

class RobotContainer {
Expand All @@ -35,6 +36,7 @@ class RobotContainer {
/* Setting up bindings for necessary control of the swerve drive platform */
private val joystick = CommandXboxController(0)
var drivetrain: CommandSwerveDrivetrain = TunerConstants.DriveTrain // drivetrain
val camera : VisionSubsystem = VisionSubsystem()

// Slew Rate Limiters to limit acceleration of joystick inputs
private val xLimiter = SlewRateLimiter(2.0)
Expand Down Expand Up @@ -77,6 +79,9 @@ class RobotContainer {
// reset the field-centric heading on left bumper press
joystick.leftBumper().onTrue(drivetrain.runOnce { drivetrain.seedFieldRelative() })

//face robot toward closest note
joystick.rightBumper().onTrue(drivetrain.applyRequest { point.withModuleDirection(camera.getNearestRotation())})

if (Utils.isSimulation()) {
drivetrain.seedFieldRelative(Pose2d(Translation2d(), Rotation2d.fromDegrees(90.0)))
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/frc/robot/subsystems/vision/VisionSubsystem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package frc.robot.subsystems

import edu.wpi.first.wpilibj2.command.SubsystemBase
import edu.wpi.first.math.geometry.Rotation2d
import org.photonvision.PhotonCamera
import org.photonvision.PhotonUtils
import org.photonvision.targeting.PhotonTrackedTarget

public class VisionSubsystem : SubsystemBase(){
private var camera : PhotonCamera = PhotonCamera("camera1")

public VisionSubsystem()

//returns angle to nearest note relative to the front of the robot
public fun getNearestRotation() : Rotation2d{
var result = camera.getLatestResult()
if(result.hasTargets()){
var target : PhotonTrackedTarget = result.getBestTarget()
return Rotation2d.fromDegrees(target.getYaw())
}
return Rotation2d.fromDegrees(0.0)
}


}
57 changes: 57 additions & 0 deletions vendordeps/photonlib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"fileName": "photonlib.json",
"name": "photonlib",
"version": "v2024.3.1",
"uuid": "515fe07e-bfc6-11fa-b3de-0242ac130004",
"frcYear": "2024",
"mavenUrls": [
"https://maven.photonvision.org/repository/internal",
"https://maven.photonvision.org/repository/snapshots"
],
"jsonUrl": "https://maven.photonvision.org/repository/internal/org/photonvision/photonlib-json/1.0/photonlib-json-1.0.json",
"jniDependencies": [],
"cppDependencies": [
{
"groupId": "org.photonvision",
"artifactId": "photonlib-cpp",
"version": "v2024.3.1",
"libName": "photonlib",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxathena",
"linuxx86-64",
"osxuniversal"
]
},
{
"groupId": "org.photonvision",
"artifactId": "photontargeting-cpp",
"version": "v2024.3.1",
"libName": "photontargeting",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxathena",
"linuxx86-64",
"osxuniversal"
]
}
],
"javaDependencies": [
{
"groupId": "org.photonvision",
"artifactId": "photonlib-java",
"version": "v2024.3.1"
},
{
"groupId": "org.photonvision",
"artifactId": "photontargeting-java",
"version": "v2024.3.1"
}
]
}

0 comments on commit 78645cd

Please sign in to comment.