-
Notifications
You must be signed in to change notification settings - Fork 2
David vision integration #135
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
davidliu-2706
wants to merge
10
commits into
master
Choose a base branch
from
David_VisionIntegration
base: master
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
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d4ee5e
Vision integration, a new run command to just report calculated RPM
2ce4af1
resolution for merging from master
e3e1dfa
commands/VisionAssistedTargetRPM.java
3c8c4f0
merge with master
1c0c91a
adjusted vision distance
d9b8598
Cleaned up
14ff77e
Adressed the review comments
9e83a8e
Merge branch 'master' into David_VisionIntegration
davidliu-2706 139caaa
clean up
b3e4c4c
Addressed comments
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
100 changes: 100 additions & 0 deletions
100
src/main/java/frc/robot/commands/VisionAssistedTargetRPM.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,100 @@ | ||
| package frc.robot.commands; | ||
|
|
||
| import frc.robot.config.Config; | ||
| import edu.wpi.first.wpilibj2.command.RunCommand; | ||
| import frc.robot.nettables.VisionCtrlNetTable; | ||
| import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
|
||
| /** | ||
| * VisionAssistedTargetRPM command. | ||
| * NOTE: this command should be run after command TurnToOuterPortCommand | ||
| */ | ||
| public class VisionAssistedTargetRPM implements Runnable { | ||
|
|
||
|
|
||
| // values from Vision Network Table | ||
| private double distanceToOuterPortInMeters; | ||
|
|
||
| //adjusted value | ||
| private double adjustedDistanceToOutPortInMeters; | ||
|
|
||
| //network table for vision control | ||
| private VisionCtrlNetTable visionControlNetTable = new VisionCtrlNetTable (); | ||
|
|
||
| //calculated RPM | ||
| double targetDistance = 0; | ||
| double targetRPM = 0; | ||
|
|
||
| /** | ||
| * Creates a new VisionAssistedTargetRPM Command. | ||
| * | ||
| * @param subsystem The subsystem used by this command. | ||
| */ | ||
| public VisionAssistedTargetRPM() { | ||
|
|
||
| // Ensure the vision is running in tape mode | ||
| //don't need this any more | ||
| //VisionCtrlNetTable.setTapeMode(); | ||
| } | ||
|
|
||
| public void run() { | ||
|
|
||
| //Read the network table from vision | ||
| distanceToOuterPortInMeters = visionControlNetTable.distanceToOuterPort.get(); | ||
davidliu-2706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ( distanceToOuterPortInMeters < 0.0 ) | ||
| { | ||
| // Vision can not provide valid detection | ||
| targetRPM = 0; | ||
| } | ||
| else | ||
| { | ||
| // NOTE: unit in the vision network table is feet. Convert it to meters. | ||
| distanceToOuterPortInMeters = distanceToOuterPortInMeters * Config.METER_PER_FOOT ; | ||
|
|
||
| // adjuste the distance for the shooter | ||
| adjustedDistanceToOutPortInMeters = distanceToOuterPortInMeters + Config.D_CAMERA_SHOOTER_IN_METERS; | ||
|
|
||
| //Calculate the RPM of the shooter wheel. | ||
| double targetV = initVelocity( adjustedDistanceToOutPortInMeters); | ||
| targetRPM = velocityToRPM (targetV); | ||
| } | ||
|
|
||
| System.out.println("Vision RPM"); | ||
| System.out.println( targetRPM); | ||
| // provide feedback to the shuffleboard for Driver Team | ||
| // vision assisted calculated RPM | ||
| SmartDashboard.putNumber("Vision RPM", targetRPM); | ||
| } | ||
|
|
||
| private double initVelocity(double distanceToTargetInMeters) { | ||
| double dTemp; | ||
| //unit: m/s | ||
| double dInitVelocity; | ||
|
|
||
| double dCheck = Math.tan(Config.SHOOTER_ANGLE_IN_DEGREES)*distanceToTargetInMeters - Config.TARGET_HEIGHT_IN_METERS; | ||
| if (dCheck > 0) | ||
| { | ||
| dTemp = Math.sqrt(Config.HALF_OF_GRAVITY/dCheck); | ||
| dInitVelocity = distanceToTargetInMeters/Math.cos(Config.SHOOTER_ANGLE_IN_DEGREES) * dTemp; | ||
| } | ||
| else | ||
| { | ||
| dInitVelocity = 0.0; | ||
| System.out.println("WARNING! Not suitable for shooting!"); | ||
| } | ||
|
|
||
| return dInitVelocity; | ||
|
|
||
| } | ||
|
|
||
| // convert velocity to RPM | ||
| // velocity: unit m/s | ||
| // return: unit revolutions per minute | ||
| private double velocityToRPM( double velocity) | ||
| { | ||
| double rpm = velocity*Config.CONVERSION_NUMBER/(Math.PI*Config.SHOOTER_WHEEL_RADIUS_IN_CM); | ||
| return rpm; | ||
| } | ||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.