This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
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.
- Loading branch information
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/main/java/com/team766/robot/reva/mechanisms/ArmCamera.java
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.team766.robot.reva.mechanisms; | ||
|
||
import org.photonvision.targeting.PhotonTrackedTarget; | ||
import com.team766.ViSIONbase.AprilTagGeneralCheckedException; | ||
import com.team766.ViSIONbase.GrayScaleCamera; | ||
import com.team766.controllers.PIDController; | ||
import com.team766.framework.Mechanism; | ||
import com.team766.robot.reva.Robot; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
|
||
|
||
public class ArmCamera extends Mechanism { | ||
private GrayScaleCamera camera; | ||
private int[] tagIds = {11,12,13,14,15,16}; | ||
private double targetX = 0; | ||
private double targetZ = 0; | ||
private PIDController xPID = new PIDController(0,0,0,0,0,0); | ||
private PIDController zPID = new PIDController(0,0,0,0,0,0); | ||
|
||
public ArmCamera() throws AprilTagGeneralCheckedException { | ||
try{ | ||
camera = new GrayScaleCamera("Arm_Camera_2024"); | ||
} catch (Exception e) { | ||
log("Unable to create GrayScaleCamera for Arm Camera"); | ||
} | ||
xPID.setSetpoint(targetX); | ||
zPID.setSetpoint(targetZ); | ||
} | ||
|
||
public GrayScaleCamera getCamera() { | ||
return camera; | ||
} | ||
|
||
public void shootTrap(){ | ||
PhotonTrackedTarget target = null; | ||
int tagIdUsing = 0; | ||
for (int tagId: tagIds){ | ||
try{ | ||
target = camera.getTrackedTargetWithID(tagId); | ||
tagIdUsing = tagId; | ||
break; | ||
} catch (Exception e){ | ||
log("Unable to get target with ID: " + tagId); | ||
if (tagId == tagIds[tagIds.length - 1]){ | ||
Robot.lights.signalTrapNotWorking(); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
Transform3d toUse = GrayScaleCamera.getBestTargetTransform3d(target); | ||
|
||
double currentX = toUse.getTranslation().getX(); | ||
double currentZ = toUse.getTranslation().getZ(); | ||
|
||
|
||
xPID.calculate(currentX); | ||
zPID.calculate(currentZ); | ||
|
||
while (Math.abs(xPID.getOutput()) + Math.abs(zPID.getOutput()) > 0){ | ||
try{ | ||
toUse = GrayScaleCamera.getBestTargetTransform3d(camera.getTrackedTargetWithID(tagIdUsing)); | ||
} catch (Exception e){ | ||
log("Lost tag!"); | ||
Robot.lights.signalTrapNotWorking(); | ||
return; | ||
} | ||
currentX = toUse.getTranslation().getX(); | ||
currentZ = toUse.getTranslation().getZ(); | ||
|
||
xPID.calculate(currentX); | ||
zPID.calculate(currentZ); | ||
|
||
Robot.drive.controlRobotOriented(currentX, currentZ, 0); | ||
Robot.lights.signalTrapRunning(); | ||
} | ||
Robot.lights.signalTrapFinished(); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
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