Skip to content
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

Turret fop #154

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Turret fop #154

wants to merge 19 commits into from

Conversation

KaustubhKhulbe
Copy link
Member

Code works now.
Button press --> tracks until any other turret routine is called.
when button pressed, looks for new target and tracks that.

Copy link
Member

@aykhm aykhm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also run formatting before you commit!

@@ -43,6 +43,8 @@ suspend fun Subsystems.digestionTeleop() = startChoreo("Digestion Teleop") {

val rezeroTurret by operator.rezeroTurret.readEagerly().withoutStamps
val reindexCarousel by operator.reindexCarousel.readEagerly().withoutStamps
val track by operator.trackTarget.readEagerly().withoutStamps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to smth slightly more descriptive

@@ -79,6 +80,39 @@ suspend fun TurretComponent.trackTarget(limelight: LimelightComponent) = startRo
}
}

suspend fun TurretComponent.fieldOriented(drivetrain: DrivetrainComponent, limelight: LimelightComponent, turret: TurretComponent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turret doesn't need to be a paremeter, the function is an extension function of TurretComponent


controller {
if (lastLimelightPos != null) {
val pitch by drivetrain.hardware.pitch.readEagerly().withoutStamps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move sensor stuff to before the controller block

@@ -84,6 +86,10 @@ suspend fun Subsystems.digestionTeleop() = startChoreo("Digestion Teleop") {

{ rezeroTurret } to { turret?.rezero(electrical) ?: freeze() },
{ reindexCarousel } to { whereAreMyBalls() },
{track} to {
trackTargetTurret()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just do turret?.fieldOriented(drivetrain, limelight) ?: freeze() and get rid of the trackTargetTurret function

if(reading != null) lastLimelightPos = reading

controller {
if (lastLimelightPos != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a copy of lastLimelightPos so you don't have to use !! later in line 95 (what if lastLimlightPos changes to null while this routine is running?)

val position = limelight.hardware.conversions.outerGoalPosition(lastLimelightPos!!, bearing, pitch)
val angle = atan2(position.x - drivetrainPosition.x, position.y - drivetrainPosition.y)
val target = (angle `coterminal +` drivetrainPosition.bearing)
if (abs(target) > 2.Degree) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we stop driving and aim to fire then we'll have up to 2 degrees of error D:

import info.kunalsheth.units.generated.*

class TurretComponent(hardware: TurretHardware) :
Component<TurretComponent, TurretHardware, OffloadedOutput>(hardware, Subsystems.shooterTicker) {

val safeSpeed by pref(1, Volt)
val windupPosition by pref(-90, Degree)
var lastLimelightPos: LimelightReading? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to lastGoalPos

Base automatically changed from 2021-offseason to master October 11, 2021 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants