-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limelight #110
base: dev
Are you sure you want to change the base?
Limelight #110
Changes from 7 commits
b4b4578
ba673dd
37e3dbf
98c1bba
479eaf7
8dc4594
c014588
5ae706b
a308866
821e31a
6a240e8
e92ddd8
da45242
29782d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,4 @@ protected void initialize() { | |
lights.setLights(state); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*----------------------------------------------------------------------------*/ | ||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */ | ||
/* Open Source Software - may be modified and shared by FRC teams. The code */ | ||
/* must be accompanied by the FIRST BSD license file in the root directory of */ | ||
/* the project. */ | ||
/*----------------------------------------------------------------------------*/ | ||
|
||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.wpilibj.command.InstantCommand; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
public class ToggleLimelight extends InstantCommand { | ||
public ToggleLimelight() { | ||
} | ||
|
||
@Override | ||
protected void initialize() { | ||
if (SmartDashboard.getBoolean("Using Limelight", false)) { | ||
SmartDashboard.putBoolean("Using Limelight", false); | ||
} else { | ||
SmartDashboard.putBoolean("Using Limelight", true); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*----------------------------------------------------------------------------*/ | ||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ | ||
/* Open Source Software - may be modified and shared by FRC teams. The code */ | ||
/* must be accompanied by the FIRST BSD license file in the root directory of */ | ||
/* the project. */ | ||
/*----------------------------------------------------------------------------*/ | ||
|
||
package frc.robot.lib; | ||
|
||
import edu.wpi.first.networktables.NetworkTable; | ||
import edu.wpi.first.networktables.NetworkTableInstance; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
public class Limelight { | ||
public enum Mode { | ||
DIST, STEER, TARGET | ||
} | ||
|
||
private NetworkTableInstance inst; | ||
private NetworkTable table; | ||
/* http://docs.limelightvision.io/en/latest/networktables_api.html | ||
tv = Whether the limelight has any valid targets (0 or 1) | ||
tx = Horizontal Offset From Crosshair To Target (-27 degrees to 27 degrees) | ||
ty = Vertical Offset From Crosshair To Target (-20.5 degrees to 20.5 degrees) | ||
ta = Target Area (0% of image to 100% of image) | ||
There are more values we could be using. Check the documentation. | ||
*/ | ||
private double tv, tx, ty, ta; | ||
|
||
public Limelight() { | ||
inst = NetworkTableInstance.getDefault(); | ||
table = inst.getTable("limelight"); | ||
} | ||
|
||
// Adjusts the distance between a vision target and the robot. Uses basic PID with the ty value from the network table. | ||
public double distanceAssist() { | ||
tv = table.getEntry("tv").getDouble(0.0); | ||
ty = table.getEntry("ty").getDouble(0.0); | ||
SmartDashboard.putNumber("Crosshair Vertical Offset", ty); | ||
ta = table.getEntry("ta").getDouble(0.0); | ||
double adjustment = 0.0; | ||
double area_threshold = 0.5; // TODO: Set the desired area. | ||
double Kp = 0.2; // TODO: Set PID K value. | ||
|
||
if (tv == 1.0) { | ||
if (ta < area_threshold) { | ||
adjustment += Kp * ty; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems odd. It will move further faster if ty is larger, but ty will generally be larger if you are closer to the target. I also don't understand the point of area_threshold. As it stands, it will prevent moving backward if you are too close to the target. I recommend reviewing: |
||
} | ||
return adjustment; | ||
} | ||
|
||
// Adjusts the angle facing a vision target. Uses basic PID with the tx value from the network table. | ||
public double steeringAssist() { | ||
tv = table.getEntry("tv").getDouble(0.0); | ||
tx = -table.getEntry("tx").getDouble(0.0); | ||
SmartDashboard.putBoolean("Found Vision Target", tv == 1.0); | ||
SmartDashboard.putNumber("Crosshair Horizontal Offset", tx); | ||
double adjustment = 0.0; | ||
double steering_factor = 0.25; | ||
double Kp = 0.2; // TODO: Set PID K value. | ||
|
||
if (tv == 1.0) { | ||
adjustment += Kp * tx; | ||
} else { | ||
adjustment += steering_factor; | ||
} | ||
return adjustment; | ||
} | ||
|
||
// Combination of distance assist and steering assist | ||
public double[] autoTarget() { | ||
double dist_assist = distanceAssist(); | ||
double steer_assist = steeringAssist(); | ||
double[] params = {dist_assist + steer_assist, dist_assist - steer_assist}; | ||
return params; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document what tv, ty, and ta are and, if appropriate, include a link to relevant limelight doc.