Skip to content

Commit

Permalink
Added photonvision example function.
Browse files Browse the repository at this point in the history
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Feb 6, 2024
1 parent d3fee13 commit 2692f86
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import frc.robot.Constants.AutonConstants;
import java.io.File;
import java.util.function.DoubleSupplier;
import org.photonvision.PhotonCamera;
import org.photonvision.targeting.PhotonPipelineResult;
import swervelib.SwerveController;
import swervelib.SwerveDrive;
import swervelib.SwerveDriveTest;
Expand Down Expand Up @@ -127,6 +129,26 @@ public void setupPathPlanner()
);
}

/**
* Aim the robot at the target returned by PhotonVision.
*
* @param camera {@link PhotonCamera} to communicate with.
* @return A {@link Command} which will run the alignment.
*/
public Command aimAtTarget(PhotonCamera camera)
{
return run(() -> {
PhotonPipelineResult result = camera.getLatestResult();
if (result.hasTargets())
{
drive(getTargetSpeeds(0,
0,
Rotation2d.fromDegrees(result.getBestTarget()
.getYaw()))); // Not sure if this will work, more math may be required.
}
});
}

/**
* Get the path follower with events.
*
Expand Down

0 comments on commit 2692f86

Please sign in to comment.