Skip to content

Commit 35f7043

Browse files
committed
fixed distance functions
1 parent 17abb8b commit 35f7043

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

src/main/java/frc/robot/commands/shooter/pivot/ShooterPivotAimCommand.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ public void end(){
2121
}
2222

2323
public boolean isFinished(){
24-
if(Math.abs(shooterPivotSubsystem.getPosition()) - shooterPivotSubsystem.getCurrentAngle() < shooterPivotSubsystem.ERRORTOLERANCE){
25-
return true;
26-
}
24+
return(Math.abs(shooterPivotSubsystem.getPosition() - shooterPivotSubsystem.getAutoAimAngle()) < shooterPivotSubsystem.ERRORTOLERANCE);
2725

28-
return false;
2926
}
3027
}

src/main/java/frc/robot/commands/shooter/pivot/ShooterPivotSetAngle.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ public void initialize() {
2020

2121
@Override
2222
public boolean isFinished() {
23-
if(Math.abs(pivotSubsystem.getPosition()) - angle < pivotSubsystem.ERRORTOLERANCE){
24-
return true;
25-
}
26-
27-
return false;
23+
return (Math.abs(pivotSubsystem.getPosition() - angle) < pivotSubsystem.ERRORTOLERANCE);
2824
}
2925
}

src/main/java/frc/robot/commands/shooter/pivot/ShooterPivotVerticalCommand.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public void initialize() {
1818

1919
@Override
2020
public boolean isFinished() {
21-
if(Math.abs(pivotSubsystem.getPosition()) - 90 < pivotSubsystem.ERRORTOLERANCE){
22-
return true;
23-
}
24-
25-
return false;
21+
return (Math.abs(pivotSubsystem.getPosition() - 90) < pivotSubsystem.ERRORTOLERANCE);
2622
}
2723
}

src/main/java/frc/robot/subsystems/shooter/ShooterPivotSubsystem.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ShooterPivotSubsystem extends SubsystemBase {
3838
private boolean alliance; //true equals red alliance
3939
private boolean autoAim;
4040
private double currentEncoderAngle;
41+
private double currentDistance;
4142
private Pose2d currentField = new Pose2d();
4243

4344
//center of red speaker: (652.73 218.42)
@@ -92,34 +93,31 @@ public void setAngle(double angle){ //check if it works
9293
public void setFieldPosition(Pose2d field){
9394
//System.out.println("setting field position");
9495
currentField = field;
95-
}
96-
97-
public double getAutoAimAngle(double distance){
98-
double speakerHeight = Units.inchesToMeters(80.51);
99-
//System.out.println("Angle of shooter" + Math.atan(speakerHeight/distance));
100-
return Math.atan(speakerHeight/distance);
101-
}
102-
103-
public void printCurrentAngle(){
104-
System.out.println("radians: " + rotationEncoder.getPosition() + "degrees: " + rotationEncoder.getPosition() * 57.29);
105-
}
106-
107-
public double getDistance(){
10896

10997
if(alliance){ //true = red
11098
double xLength = Math.pow(currentField.getX()-RED_X, 2);
11199
double yLength = Math.pow(currentField.getY()-RED_Y, 2);
112100
//System.out.println("alliance red:" + alliance);
113-
return Math.sqrt(xLength + yLength);
101+
currentDistance = Math.sqrt(xLength + yLength);
114102

115103
} else {
116104
double xLength = Math.pow(currentField.getX()-BLUE_X, 2);
117105
double yLength = Math.pow(currentField.getY()-BLUE_Y, 2);
118106

119-
return Math.sqrt(xLength + yLength);
107+
currentDistance = Math.sqrt(xLength + yLength);
120108
}
121109
}
122110

111+
public double getAutoAimAngle(){
112+
double speakerHeight = Units.inchesToMeters(80.51);
113+
//System.out.println("Angle of shooter" + Math.atan(speakerHeight/distance));
114+
return Math.atan(speakerHeight/currentDistance);
115+
}
116+
117+
public void printCurrentAngle(){
118+
System.out.println("radians: " + rotationEncoder.getPosition() + "degrees: " + rotationEncoder.getPosition() * 57.29);
119+
}
120+
123121
public double getPosition(){
124122
//System.out.println("rotation encoder position: " + rotationEncoder.getPosition());
125123
return rotationEncoder.getPosition();
@@ -142,7 +140,7 @@ public void periodic(){
142140
// }
143141

144142
if(autoAim){
145-
setAngle(getAutoAimAngle(getDistance()));
143+
setAngle(getAutoAimAngle());
146144
}
147145

148146
// printCurrentAngle();

0 commit comments

Comments
 (0)