Skip to content

Commit

Permalink
tune and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Cancelable committed May 20, 2024
1 parent c175318 commit ca161e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/stuypulse/robot/constants/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public interface Settings {
double DT = 0.02;

public interface Turret {
int MIN_ANGLE = -180;
int MAX_ANGLE = +180;
int MIN_ANGLE = -135;
int MAX_ANGLE = +135;

public interface Feedback {
SmartNumber kP = new SmartNumber("Turret/kP", 3.0);
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/com/stuypulse/robot/subsystems/turret/Turret.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.stuypulse.robot.constants.Ports;
import com.stuypulse.robot.constants.Settings;
import com.stuypulse.robot.constants.Settings.Turret.Feedback;
import com.stuypulse.robot.subsystems.swerve.SwerveDrive;
import com.stuypulse.stuylib.control.Controller;
import com.stuypulse.stuylib.control.feedback.PIDController;
import com.stuypulse.stuylib.network.SmartNumber;
Expand Down Expand Up @@ -45,19 +46,22 @@ public void stop() {
}

public void setTargetAngle(double angle, double minTarget, double maxTarget) {
// number of rotations needed to bring angle back in (min, max) range
// keep in mind that this assumes that the minimum angle is 360, when it very
// much could be less, in which case I'll change it in like 5 minutes lol

// // number of rotations needed to bring angle back in (min, max) range
double deltaRotations = 0;

if (angle > maxTarget) {
deltaRotations = -Math.ceil((angle - maxTarget) / 360.0);
deltaRotations = -Math.ceil((angle - maxTarget) / 180.0); // minimum number of turns possible to reach it
}
else if (angle < minTarget) {
deltaRotations = +Math.ceil(-(angle - minTarget) / 360.0);
deltaRotations = +Math.ceil(-(angle - minTarget) / 180.0);
}

targetAngle.set(angle + deltaRotations * 36);
targetAngle.set(angle + deltaRotations * 360); // 360 makes sure that right side of robot is tracking
}

@Override
public final void periodic() {
controller.update(
Expand Down

0 comments on commit ca161e7

Please sign in to comment.