-
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
base: master
Are you sure you want to change the base?
Changes from all commits
2a1d177
f96dfa3
e902e05
be90c1e
3d123c8
c1097bc
c4c56f4
de917a8
4d0c1fe
1522e4f
977ce21
1bae2ee
4f4b737
c48b5cf
7434d82
c02f9f7
8d03161
bae7cc9
b11f46f
8818756
3b43e75
1720d0e
fee353f
f633447
8f7b992
1176e7f
c653fd2
55f49d8
5c2deb2
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
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 | ||
|
||
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 val mAnglePID: PIDF | ||
private val 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.reset() | ||
mDistancePID.reset() | ||
|
||
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 | ||
|
||
mAnglePID.setpoint = -Constants.Vision.CAMERA_HORIZONTAL_ANGLE | ||
mDistancePID.setpoint = Constants.Vision.TARGET_DISTANCE | ||
|
||
// turn on leds | ||
// vision.ledState = Vision.LEDState.ON | ||
} | ||
|
||
public override fun update() { | ||
|
||
if (!vision.hasValidTarget) { | ||
drivetrain.setVelocity(0.0, 0.0) | ||
} else { | ||
mAnglePID.processVariable = -vision.targetXOffset | ||
var steer = mAnglePID.calculate() | ||
|
||
// mDistancePID.processVariable = when (goal) { | ||
// VisionGoal.BALL_TARGET -> vision.distanceToBallTarget | ||
// VisionGoal.HATCH_TARGET -> vision.distanceToHatchTarget | ||
// } | ||
mDistancePID.processVariable = -vision.distanceToTarget | ||
val drive = mDistancePID.calculate() | ||
|
||
val left = drive + steer | ||
val right = drive - steer | ||
|
||
drivetrain.setVelocity(left, right) | ||
} | ||
} | ||
|
||
public override fun next(): Boolean { | ||
return super.timedOut() || ( | ||
vision.distanceToTarget < Constants.Vision.TARGET_DISTANCE // && | ||
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. Does this work? I'm concerned that this condition wont ever be satisfied |
||
// abs(mAnglePID.error) < Constants.Vision.ACCEPTABLE_ANGLE_ERROR && | ||
// abs(mDistancePID.error) < Constants.Vision.ACCEPTABLE_DISTANCE_ERROR | ||
) | ||
} | ||
|
||
public override fun finish() { | ||
drivetrain.setVelocity(0.0, 0.0) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,10 @@ public interface IDriverControls { | |
|
||
public fun getStow(): Boolean | ||
|
||
public fun getAutoAlign(): Boolean | ||
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. Add this function to the 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. Ok. |
||
|
||
public fun getState(): String { | ||
@Suppress("MaxLineLength") | ||
return "${getThrottle()} : ${getTurn()} : ${getLeft()} : ${getRight()} : ${getQuickTurn()} : ${getCreep()} : ${getExitAuto()} : ${getStow()}" | ||
return "${getThrottle()} : ${getTurn()} : ${getLeft()} : ${getRight()} : ${getQuickTurn()} : ${getCreep()} : ${getExitAuto()} : ${getStow()} : ${getAutoAlign()}" | ||
} | ||
} |
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.