Commit 2692f86 1 parent d3fee13 commit 2692f86 Copy full SHA for 2692f86
File tree 1 file changed +22
-0
lines changed
src/main/java/frc/robot/subsystems/swervedrive
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 24
24
import frc .robot .Constants .AutonConstants ;
25
25
import java .io .File ;
26
26
import java .util .function .DoubleSupplier ;
27
+ import org .photonvision .PhotonCamera ;
28
+ import org .photonvision .targeting .PhotonPipelineResult ;
27
29
import swervelib .SwerveController ;
28
30
import swervelib .SwerveDrive ;
29
31
import swervelib .SwerveDriveTest ;
@@ -127,6 +129,26 @@ public void setupPathPlanner()
127
129
);
128
130
}
129
131
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
+
130
152
/**
131
153
* Get the path follower with events.
132
154
*
You can’t perform that action at this time.
0 commit comments