5
5
import edu .wpi .first .apriltag .AprilTagFields ;
6
6
import edu .wpi .first .math .geometry .*;
7
7
import edu .wpi .first .math .util .Units ;
8
- import edu .wpi .first .wpilibj .smartdashboard .SendableChooser ;
9
8
import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
10
9
import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
10
+ import frc .robot .StateControllerSub ;
11
11
import org .photonvision .EstimatedRobotPose ;
12
12
import org .photonvision .PhotonCamera ;
13
13
import org .photonvision .PhotonPoseEstimator ;
14
+ import org .photonvision .targeting .PhotonTrackedTarget ;
14
15
16
+ import java .util .List ;
15
17
import java .util .Optional ;
16
18
17
19
public class VisionSubsystem extends SubsystemBase {
@@ -20,28 +22,32 @@ public class VisionSubsystem extends SubsystemBase {
20
22
21
23
22
24
AprilTagFieldLayout aprilTagFieldLayout ;
23
- PhotonCamera cam ;
25
+ PhotonCamera shooterSideArducam ;
26
+
27
+ PhotonCamera intakeAssistCamera = new PhotonCamera ("intake_assist_scary" );
24
28
PhotonPoseEstimator photonPoseEstimator ;
25
- public VisionSubsystem () {
26
29
27
- // SmartDashboard.putData("poseStrategy",selectedPoseStrategy);
30
+ StateControllerSub stateControllerSub ;
31
+ public VisionSubsystem (StateControllerSub stateControllerSub ) {
28
32
33
+ // SmartDashboard.putData("poseStrategy",selectedPoseStrategy);
29
34
try {
30
35
aprilTagFieldLayout = AprilTagFieldLayout .loadFromResource (AprilTagFields .k2024Crescendo .m_resourceFile );
31
36
}catch (Exception e ){
32
37
e .printStackTrace ();
33
38
}
34
39
35
- cam = new PhotonCamera ("Arducam_OV2311_USB_Camera " );
40
+ shooterSideArducam = new PhotonCamera ("Arducam_OV2311_shooter " );
36
41
Transform3d robotToCam = new Transform3d (new Translation3d (0.357 ,0.076 ,0.224 ), new Rotation3d (0 ,Units .degreesToRadians (-30 ),0 ));
37
- photonPoseEstimator = new PhotonPoseEstimator (aprilTagFieldLayout , PhotonPoseEstimator .PoseStrategy .MULTI_TAG_PNP_ON_COPROCESSOR , cam , robotToCam );
42
+ photonPoseEstimator = new PhotonPoseEstimator (aprilTagFieldLayout , PhotonPoseEstimator .PoseStrategy .MULTI_TAG_PNP_ON_COPROCESSOR , shooterSideArducam , robotToCam );
38
43
// photonPoseEstimator.setPrimaryStrategy();
39
44
photonPoseEstimator .setMultiTagFallbackStrategy (PhotonPoseEstimator .PoseStrategy .LOWEST_AMBIGUITY );
40
45
41
46
//1st + is cam forward
42
47
//2nd + is cam to left
43
48
//3rd + is cam up
44
49
50
+ this .stateControllerSub = stateControllerSub ;
45
51
46
52
}
47
53
@@ -54,8 +60,20 @@ public Optional<EstimatedRobotPose> getEstimatedGlobalPose(Pose2d prevEstimatedR
54
60
55
61
}
56
62
63
+
64
+
65
+
57
66
public void periodic (){
58
67
68
+ List <PhotonTrackedTarget > targets = intakeAssistCamera .getLatestResult ().getTargets ();
69
+ double assistAngle = 0 ;
70
+ if (!targets .isEmpty ())
71
+ assistAngle = Units .degreesToRadians (targets .get (0 ).getYaw ());
72
+ stateControllerSub .feedNoteAlignAngleDiff (assistAngle );
73
+
74
+ SmartDashboard .putNumber ("noteAssistAngle" ,assistAngle );
75
+
76
+
59
77
}
60
78
61
79
0 commit comments