-
Notifications
You must be signed in to change notification settings - Fork 2
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
Profiled PID for controlling the rotation of targeting commands #42
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -9,7 +9,8 @@ import com.team4099.robot2023.util.DebugLogger | |
import com.team4099.robot2023.util.driver.DriverProfile | ||
import edu.wpi.first.wpilibj.RobotBase | ||
import edu.wpi.first.wpilibj2.command.Command | ||
import org.team4099.lib.controller.PIDController | ||
import org.team4099.lib.controller.ProfiledPIDController | ||
import org.team4099.lib.controller.TrapezoidProfile | ||
import org.team4099.lib.units.Velocity | ||
import org.team4099.lib.units.derived.Radian | ||
import org.team4099.lib.units.derived.degrees | ||
|
@@ -35,7 +36,7 @@ class TargetNoteCommand( | |
val limelight: LimelightVision | ||
) : Command() { | ||
|
||
private var thetaPID: PIDController<Radian, Velocity<Radian>> | ||
private var thetaPID: ProfiledPIDController<Radian, Velocity<Radian>> | ||
val thetakP = | ||
LoggedTunableValue( | ||
"NoteAlignment/noteThetakP", | ||
|
@@ -61,10 +62,13 @@ class TargetNoteCommand( | |
addRequirements(drivetrain) | ||
|
||
thetaPID = | ||
PIDController( | ||
ProfiledPIDController( | ||
thetakP.get(), | ||
thetakI.get(), | ||
thetakD.get(), | ||
TrapezoidProfile.Constraints( | ||
DrivetrainConstants.STEERING_VEL_MAX, DrivetrainConstants.STEERING_ACCEL_MAX | ||
) | ||
) | ||
|
||
if (!(RobotBase.isSimulation())) { | ||
|
@@ -74,32 +78,46 @@ class TargetNoteCommand( | |
thetakD.initDefault(DrivetrainConstants.PID.LIMELIGHT_THETA_KD) | ||
|
||
thetaPID = | ||
PIDController( | ||
ProfiledPIDController( | ||
DrivetrainConstants.PID.LIMELIGHT_THETA_KP, | ||
DrivetrainConstants.PID.LIMELIGHT_THETA_KI, | ||
DrivetrainConstants.PID.LIMELIGHT_THETA_KD | ||
DrivetrainConstants.PID.LIMELIGHT_THETA_KD, | ||
TrapezoidProfile.Constraints( | ||
DrivetrainConstants.STEERING_VEL_MAX, DrivetrainConstants.STEERING_ACCEL_MAX | ||
) | ||
) | ||
} else { | ||
thetakP.initDefault(DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KP) | ||
thetakI.initDefault(DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KI) | ||
thetakD.initDefault(DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KD) | ||
|
||
thetaPID = | ||
PIDController( | ||
ProfiledPIDController( | ||
DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KP, | ||
DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KI, | ||
DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KD | ||
DrivetrainConstants.PID.SIM_AUTO_THETA_PID_KD, | ||
TrapezoidProfile.Constraints( | ||
DrivetrainConstants.STEERING_VEL_MAX, DrivetrainConstants.STEERING_ACCEL_MAX | ||
) | ||
) | ||
} | ||
|
||
thetaPID.enableContinuousInput(-PI.radians, PI.radians) | ||
} | ||
|
||
override fun initialize() { | ||
thetaPID.reset() | ||
thetaPID.reset(0.degrees) | ||
|
||
if (thetakP.hasChanged() || thetakI.hasChanged() || thetakD.hasChanged()) { | ||
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. please add tunable numbers for steering vel max and accel max as well 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. for the rest of the commands as well |
||
thetaPID = PIDController(thetakP.get(), thetakI.get(), thetakD.get()) | ||
thetaPID = | ||
ProfiledPIDController( | ||
thetakP.get(), | ||
thetakI.get(), | ||
thetakD.get(), | ||
TrapezoidProfile.Constraints( | ||
DrivetrainConstants.STEERING_VEL_MAX, DrivetrainConstants.STEERING_ACCEL_MAX | ||
) | ||
) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ object ControlBoard { | |
val climbAlignLeft = Trigger { driver.dPadLeft } | ||
val climbAlignRight = Trigger { driver.dPadRight } | ||
|
||
val targetSpeaker = Trigger { driver.xButton } // TODO: switch back to climbAlignLeft | ||
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. doesn't belong in this commit |
||
val targetSpeaker = Trigger { driver.xButton } | ||
val climbAutoAlign = Trigger { driver.bButton } | ||
|
||
// week0 controls | ||
|
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.
why 0 degrees?
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.
what would we reset it to then? the current gyro angle?
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.
you're not resetting the angle, you're resetting the error it sees. we don't want error from the previous path to carry on, but rather recalculate in our execute function