-
Notifications
You must be signed in to change notification settings - Fork 0
Limelight #110
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
Open
alexander-mcdowell
wants to merge
14
commits into
dev
Choose a base branch
from
limelight
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Limelight #110
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b4b4578
Robot code that we know works (#104)
kevinzwang ba673dd
Create branch and add basic limelight functionality
alexander-mcdowell 37e3dbf
Make it so that drive assist occurs only when bounding box is seen
alexander-mcdowell 98c1bba
Create AllignAssist Command (INCOMPLETE)
DriverStationComputer 479eaf7
Create Drive command (combines limelight drive and teleop drive)
8dc4594
Correct typo "Allign" to "Align"
c014588
Fix dean's comments and fix toggle limelight btn
alexander-mcdowell 5ae706b
Fixed NetworkTable data and area-based dist calculation
Akalay27 a308866
fixed ta
Akalay27 821e31a
calibrated steeringAssist and autoTarget works
DriverStationComputer 6a240e8
Lex's distance algorithm using linear algebra
alexander-mcdowell e92ddd8
2020 Build Season Autonomous Prototyping
alexander-mcdowell da45242
Auto align testing changes
DeepBlueRobots 29782d4
removed debug print
CoolSpy3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -28,4 +28,4 @@ protected void initialize() { | |
lights.setLights(state); | ||
} | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Robot2019/src/main/java/frc/robot/commands/ToggleLimelight.java
This file contains hidden or 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,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); | ||
} | ||
} | ||
} |
This file contains hidden or 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,77 @@ | ||
/*----------------------------------------------------------------------------*/ | ||
/* 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 | ||
} | ||
|
||
/* 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; | ||
private double prev_tx = 1.0; | ||
|
||
// 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 = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0.0); | ||
ta = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ta").getDouble(0.0); | ||
SmartDashboard.putNumber("Crosshair Vertical Offset", ty); | ||
double adjustment = 0.0; | ||
double area_threshold = 1.75; // TODO: Set the desired area ratio. 0 to 100. | ||
double Kp = 0.225; // TODO: Set PID K value. | ||
|
||
if (tv == 1.0) { | ||
adjustment = (area_threshold - ta) * Kp; | ||
} | ||
adjustment = Math.signum(adjustment) * Math.min(Math.abs(adjustment), 0.5); | ||
return adjustment; | ||
} | ||
|
||
// Adjusts the angle facing a vision target. Uses basic PID with the tx value from the network table. | ||
public double steeringAssist() { | ||
tv = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0.0); | ||
tx = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0.0); | ||
ta = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ta").getDouble(0.0); | ||
SmartDashboard.putNumber("Crosshair Horizontal Offset", tx); | ||
SmartDashboard.putNumber("Found Vision Target", tv); | ||
SmartDashboard.putNumber("Prev_tx", prev_tx); | ||
double adjustment = 0.0; | ||
double steering_factor = 0.25; | ||
double Kp = 0.025; // TODO: Set PID K value. | ||
|
||
if (tv == 1.0) { | ||
if (ta > 0.02) { | ||
adjustment += Kp * tx; | ||
prev_tx = tx; | ||
} | ||
} else { | ||
adjustment += Math.signum(prev_tx) * steering_factor; | ||
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. Same comment regarding += vs =. |
||
} | ||
adjustment = Math.signum(adjustment) * Math.min(Math.abs(adjustment), 0.5); | ||
SmartDashboard.putNumber("Adjustment", adjustment); | ||
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; | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using += instead of = here seems unnecessarily confusing. Am I missing something?