-
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.
This commit fixes the style issues introduced in 6c4c746 according to the output from Ktlint. Details: #2
- Loading branch information
1 parent
5c966c7
commit 296279b
Showing
3 changed files
with
41 additions
and
35 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
27 changes: 12 additions & 15 deletions
27
src/main/java/frc/robot/subsystems/vision/VisionSubsystem.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,37 +1,34 @@ | ||
package frc.robot.subsystems.vision | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase | ||
import edu.wpi.first.math.geometry.Rotation2d | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase | ||
import org.photonvision.PhotonCamera | ||
import org.photonvision.PhotonUtils | ||
import org.photonvision.targeting.PhotonTrackedTarget | ||
|
||
class VisionSubsystem : SubsystemBase(){ | ||
private var camera : PhotonCamera = PhotonCamera("ShitCam") | ||
class VisionSubsystem : SubsystemBase() { | ||
private var camera: PhotonCamera = PhotonCamera("ShitCam") | ||
private lateinit var rot: Rotation2d | ||
private var countWithoutMeasurement: Int = 0 | ||
|
||
|
||
override fun periodic(){ | ||
override fun periodic() { | ||
// This method will be called once per scheduler run | ||
var result = camera.getLatestResult() | ||
if(result.hasTargets()){ | ||
var target : PhotonTrackedTarget = result.getBestTarget() | ||
if (result.hasTargets()) { | ||
var target: PhotonTrackedTarget = result.getBestTarget() | ||
rot = Rotation2d.fromDegrees(target.yaw) | ||
countWithoutMeasurement = 0 | ||
} else countWithoutMeasurement++ | ||
} else { | ||
countWithoutMeasurement++ | ||
} | ||
|
||
if (countWithoutMeasurement > 25) { // method called every 20 ms, | ||
// so 25 * 20 = 500 ms without a target before setting rotation to 0 | ||
rot = Rotation2d.fromDegrees(0.0) | ||
} | ||
} | ||
|
||
//returns angle to nearest note relative to the front of the robot | ||
fun getNearestRotation() : Rotation2d { | ||
|
||
// returns angle to nearest note relative to the front of the robot | ||
fun getNearestRotation(): Rotation2d { | ||
return rot | ||
} | ||
|
||
|
||
} | ||
} |