-
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
Adding Vision to robot #53
Open
BBScholar
wants to merge
29
commits into
master
Choose a base branch
from
dev/vision
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 6 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2a1d177
vision initial
BBScholar f96dfa3
auto
BBScholar e902e05
it works
BBScholar be90c1e
stuff, need to merge
BBScholar 3d123c8
merge with master
BBScholar c1097bc
refactored vision subsystem, added constants, refactored vision action
BBScholar c4c56f4
added link for reference:
BBScholar de917a8
reset functions
BBScholar 4d0c1fe
its working better
BBScholar 1522e4f
Merge branch 'master' into dev/vision
andycate 977ce21
yeet
BBScholar 1bae2ee
commit
BBScholar 4f4b737
need to merge
BBScholar c48b5cf
merge with master
BBScholar 7434d82
one instance
BBScholar c02f9f7
yeet
BBScholar 8d03161
added blink shit
BBScholar bae7cc9
add thing to robot class
BBScholar b11f46f
added test methods
BBScholar 8818756
chagned pids to val
BBScholar 3b43e75
yeet
BBScholar 1720d0e
it mildy works
BBScholar fee353f
works kinda, needs skew
BBScholar f633447
added auto align button to driver controls
BBScholar 8f7b992
added vision lineup to teleop
BBScholar 1176e7f
added autoAlign to state
BBScholar c653fd2
Merge branch 'master' into dev/vision
BBScholar 55f49d8
fixes
BBScholar 5c2deb2
changed led modes
BBScholar 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 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 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 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
90 changes: 90 additions & 0 deletions
90
src/main/kotlin/org/team5499/frc2019/auto/actions/VisionGoalAction.kt
This file contains 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,90 @@ | ||
package org.team5499.frc2019.auto.actions | ||
|
||
import org.team5499.monkeyLib.auto.Action | ||
import org.team5499.monkeyLib.math.pid.PIDF | ||
|
||
import org.team5499.frc2019.subsystems.Vision | ||
import org.team5499.frc2019.subsystems.Drivetrain | ||
import org.team5499.frc2019.Constants | ||
|
||
import kotlin.math.abs | ||
|
||
public class VisionGoalAction( | ||
timeout: Double, | ||
val goal: VisionGoal, | ||
val vision: Vision, | ||
val drivetrain: Drivetrain | ||
) : Action(timeout) { | ||
|
||
public enum class VisionGoal { HATCH_TARGET, BALL_TARGET } | ||
|
||
private var mAnglePID: PIDF | ||
private var mDistancePID: PIDF | ||
|
||
init { | ||
mAnglePID = PIDF( | ||
Constants.Vision.ANGLE_KP, | ||
Constants.Vision.ANGLE_KI, | ||
Constants.Vision.ANGLE_KI, | ||
Constants.Vision.ANGLE_KD, | ||
false | ||
) | ||
mDistancePID = PIDF( | ||
Constants.Vision.DISTANCE_KP, | ||
Constants.Vision.DISTANCE_KI, | ||
Constants.Vision.DISTANCE_KD, | ||
Constants.Vision.DISTANCE_KF, | ||
false | ||
) | ||
} | ||
|
||
public override fun start() { | ||
// reset pid for dashboard | ||
mAnglePID.kP = Constants.Vision.ANGLE_KP | ||
mAnglePID.kI = Constants.Vision.ANGLE_KI | ||
mAnglePID.kD = Constants.Vision.ANGLE_KD | ||
mAnglePID.kF = Constants.Vision.ANGLE_KF | ||
|
||
mDistancePID.kP = Constants.Vision.DISTANCE_KP | ||
mDistancePID.kI = Constants.Vision.DISTANCE_KI | ||
mDistancePID.kD = Constants.Vision.DISTANCE_KD | ||
mDistancePID.kF = Constants.Vision.DISTANCE_KF | ||
|
||
// turn on leds | ||
vision.ledState = Vision.LEDState.ON | ||
} | ||
|
||
public override fun update() { | ||
|
||
if (!vision.hasValidTarget) { | ||
drivetrain.setVelocity(0.0, 0.0) | ||
} else { | ||
mAnglePID.setpoint = 0.0 | ||
mAnglePID.processVariable = vision.targetXOffset | ||
var steer = mAnglePID.calculate() | ||
|
||
mDistancePID.setpoint = Constants.Vision.TARGET_DISTANCE | ||
mDistancePID.processVariable = when (goal) { | ||
VisionGoal.BALL_TARGET -> vision.distanceToBallTarget | ||
VisionGoal.HATCH_TARGET -> vision.distanceToHatchTarget | ||
} | ||
val drive = mDistancePID.calculate() | ||
|
||
val left = drive + steer | ||
val right = drive - steer | ||
|
||
drivetrain.setVelocity(left, right) | ||
} | ||
} | ||
|
||
public override fun next(): Boolean { | ||
return super.timedOut() || ( | ||
abs(mAnglePID.error) < Constants.Vision.ACCEPTABLE_ANGLE_ERROR && | ||
abs(mDistancePID.error) < Constants.Vision.ACCEPTABLE_DISTANCE_ERROR | ||
) | ||
} | ||
|
||
public override fun finish() { | ||
vision.ledState = Vision.LEDState.OFF | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,15 +1,74 @@ | ||
package org.team5499.frc2019.subsystems | ||
|
||
import org.team5499.frc2019.Constants | ||
|
||
import org.team5499.monkeyLib.Subsystem | ||
|
||
import edu.wpi.first.networktables.NetworkTableInstance | ||
|
||
import kotlin.math.tan | ||
|
||
public class Vision : Subsystem() { | ||
|
||
public override fun update() { | ||
} | ||
@Suppress("MagicNumber") | ||
public enum class LEDState(val value: Int) { PIPELINE(0), OFF(1), BLINK(2), ON(3) } | ||
|
||
public override fun stop() { | ||
} | ||
@Suppress("MagicNumber") | ||
public enum class VisionMode(val value: Int) { DRIVER(9), VISION(0) } // pipeline | ||
|
||
public override fun reset() { | ||
public var ledState: LEDState = LEDState.OFF | ||
set(value) { | ||
NetworkTableInstance.getDefault().getTable("limelight") .getEntry("ledMode").setNumber(value.value) | ||
field = value | ||
} | ||
public var visionMode: VisionMode = VisionMode.VISION | ||
set(value) { | ||
NetworkTableInstance.getDefault().getTable("limelight") .getEntry("pipeline").setNumber(value.value) | ||
field = value | ||
} | ||
public val hasValidTarget: Boolean | ||
get() { | ||
return if ( | ||
NetworkTableInstance.getDefault().getTable("limelight") .getEntry("tv").getDouble(0.0) == 1.0 | ||
) true | ||
else false | ||
} | ||
public val targetXOffset: Double | ||
get() { | ||
return NetworkTableInstance.getDefault().getTable("limelight") .getEntry("tx").getDouble(0.0) | ||
} | ||
public val targetYOffset: Double | ||
get() { | ||
return NetworkTableInstance.getDefault().getTable("limelight") .getEntry("ty").getDouble(0.0) | ||
} | ||
public val targetSkew: Double | ||
get() { | ||
return NetworkTableInstance.getDefault().getTable("limelight") .getEntry("ts").getDouble(0.0) | ||
} | ||
public val targetArea: Double | ||
get() { | ||
return NetworkTableInstance.getDefault().getTable("limelight") .getEntry("ta").getDouble(0.0) | ||
} | ||
public val distanceToHatchTarget: Double | ||
get() { | ||
return (Constants.Vision.HATCH_TARGET_HEIGHT - Constants.Vision.CAMERA_HEIGHT) / | ||
tan(Constants.Vision.CAMERA_VERTICAL_ANGLE + targetYOffset) | ||
} | ||
public val distanceToBallTarget: Double | ||
get() { | ||
return (Constants.Vision.BALL_TARGET_HEIGHT - Constants.Vision.CAMERA_HEIGHT) / | ||
tan(Constants.Vision.CAMERA_VERTICAL_ANGLE + targetYOffset) | ||
} | ||
|
||
init { | ||
NetworkTableInstance.getDefault().getTable("limelight") .getEntry("camMode").setNumber(0) | ||
NetworkTableInstance.getDefault().getTable("limelight") .getEntry("stream").setNumber(0) | ||
NetworkTableInstance.getDefault().getTable("limelight") .getEntry("ledMode").setNumber(0) | ||
} | ||
|
||
public override fun update() {} | ||
|
||
public override fun stop() {} | ||
|
||
public override fun reset() {} | ||
} |
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.
Maybe coast here?
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.
Will check this.