src/main/java/frc/robot/subsystems
創建 Limelight.java
(有使用IDashboard)NetworkTable
讀取LimelightNetworkTableEntry
讀取Limelight值(tx、ty為度數)
public class Limelight extends SubsystemBase implements IDashboardProvider {
private final NetworkTable table;
private final NetworkTableEntry tx;
private final NetworkTableEntry ty;
private final NetworkTableEntry tid;
private double distanceToGoalVerticalMeters;
private double distanceToGoalHorizontalMeters;
public Limelight() {
this.registerDashboard();
this.table = NetworkTableInstance.getDefault().getTable("limelight");
this.tx = this.table.getEntry("tx");
this.ty = this.table.getEntry("ty");
this.tid = this.table.getEntry("tid");
this.table.getEntry("ledMode").setNumber(LimelightCamera.ledMode);
this.table.getEntry("camMode").setNumber(LimelightCamera.camMode);
this.table.getEntry("crop").setDoubleArray(LimelightCamera.cameraPose);
}
}
a1
VerticalOffset
與AprilTag角度a2
MountAngleDeg
Limelight角度h1
LensHeightMeters
Limelight與地板高度h2
GoalHeightMeters
AprilTag與地板高度tan(a1+a2) = (h2-h1) / d
d = (h2-h1) / tan(a1+a2)
public double getDistanceToGoalVerticalMeters() {
double verticalOffset = this.ty.getDouble(0.0);
double mountAngleDeg = LimelightConstants.MOUNT_ANGLE_DEG;
double lensHeightMeters = LimelightConstants.LENS_HEIGHT_METERS;
double goalHeightMeters = LimelightConstants.GOAL_HEIGHT_METERS;
double angleToGoalDeg = mountAngleDeg + verticalOffset;
double angleToGoalRad = angleToGoalDeg * (Math.PI / 180.0);
this.distanceToGoalVerticalMeters = Math.abs((goalHeightMeters - lensHeightMeters) / Math.tan(angleToGoalRad));
return this.distanceToGoalVerticalMeters;
}
a1
HorizontalOffset
與AprilTag夾角d
distanceToGoalVerticalMeters
與AprilTag距離h
distanceToGoalHorizontalMeters
與Limelight水平距離
public double getDistanceToGoalHorizontalMeters(double distanceToGoalVerticalMeters) {
if (distanceToGoalVerticalMeters == -1) {
distanceToGoalVerticalMeters = this.getDistanceToGoalVerticalMeters();
}
double horizontalOffset = this.tx.getDouble(0.0);
double horizontalOffsetRad = horizontalOffset * (Math.PI / 180.0);
this.distanceToGoalHorizontalMeters = (Math.tan(horizontalOffsetRad) * distanceToGoalVerticalMeters) - LimelightConstants.HORIZONTAL_OFFSET_METERS;
return this.distanceToGoalHorizontalMeters;
}
public double getAprilTagId() {
return this.tid.getDouble(0.0);
}
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up