Skip to content

Commit 2692f86

Browse files
Added photonvision example function.
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
1 parent d3fee13 commit 2692f86

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main/java/frc/robot/subsystems/swervedrive/SwerveSubsystem.java

+22
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import frc.robot.Constants.AutonConstants;
2525
import java.io.File;
2626
import java.util.function.DoubleSupplier;
27+
import org.photonvision.PhotonCamera;
28+
import org.photonvision.targeting.PhotonPipelineResult;
2729
import swervelib.SwerveController;
2830
import swervelib.SwerveDrive;
2931
import swervelib.SwerveDriveTest;
@@ -127,6 +129,26 @@ public void setupPathPlanner()
127129
);
128130
}
129131

132+
/**
133+
* Aim the robot at the target returned by PhotonVision.
134+
*
135+
* @param camera {@link PhotonCamera} to communicate with.
136+
* @return A {@link Command} which will run the alignment.
137+
*/
138+
public Command aimAtTarget(PhotonCamera camera)
139+
{
140+
return run(() -> {
141+
PhotonPipelineResult result = camera.getLatestResult();
142+
if (result.hasTargets())
143+
{
144+
drive(getTargetSpeeds(0,
145+
0,
146+
Rotation2d.fromDegrees(result.getBestTarget()
147+
.getYaw()))); // Not sure if this will work, more math may be required.
148+
}
149+
});
150+
}
151+
130152
/**
131153
* Get the path follower with events.
132154
*

0 commit comments

Comments
 (0)