Skip to content

Commit 5ae706b

Browse files
committed
Fixed NetworkTable data and area-based dist calculation
1 parent c014588 commit 5ae706b

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Robot2019/src/main/java/frc/robot/lib/Limelight.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public enum Mode {
1616
DIST, STEER, TARGET
1717
}
1818

19-
private NetworkTableInstance inst;
2019
private NetworkTable table;
2120
/* http://docs.limelightvision.io/en/latest/networktables_api.html
2221
tv = Whether the limelight has any valid targets (0 or 1)
@@ -27,33 +26,26 @@ public enum Mode {
2726
*/
2827
private double tv, tx, ty, ta;
2928

30-
public Limelight() {
31-
inst = NetworkTableInstance.getDefault();
32-
table = inst.getTable("limelight");
33-
}
34-
3529
// Adjusts the distance between a vision target and the robot. Uses basic PID with the ty value from the network table.
3630
public double distanceAssist() {
37-
tv = table.getEntry("tv").getDouble(0.0);
38-
ty = table.getEntry("ty").getDouble(0.0);
39-
SmartDashboard.putNumber("Crosshair Vertical Offset", ty);
31+
tv = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0.0);
4032
ta = table.getEntry("ta").getDouble(0.0);
33+
SmartDashboard.putNumber("Crosshair Vertical Offset", ty);
4134
double adjustment = 0.0;
42-
double area_threshold = 0.5; // TODO: Set the desired area.
35+
double area_threshold = 10; // TODO: Set the desired area ratio. 0 to 100.
4336
double Kp = 0.2; // TODO: Set PID K value.
4437

38+
// using area to calculate adjustment since camera does not have a fixed angle > 0.
4539
if (tv == 1.0) {
46-
if (ta < area_threshold) {
47-
adjustment += Kp * ty;
48-
}
40+
adjustment = (area_threshold-ta)*Kp;
4941
}
5042
return adjustment;
5143
}
5244

5345
// Adjusts the angle facing a vision target. Uses basic PID with the tx value from the network table.
5446
public double steeringAssist() {
55-
tv = table.getEntry("tv").getDouble(0.0);
56-
tx = -table.getEntry("tx").getDouble(0.0);
47+
tv = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0.0);
48+
tx = -NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0.0);
5749
SmartDashboard.putBoolean("Found Vision Target", tv == 1.0);
5850
SmartDashboard.putNumber("Crosshair Horizontal Offset", tx);
5951
double adjustment = 0.0;

0 commit comments

Comments
 (0)