Skip to content

Commit e81a784

Browse files
More code cleanup - removed some warnings, removed some dead code, updated some code to use our coding conventions.
1 parent 1ce4114 commit e81a784

File tree

4 files changed

+32
-65
lines changed

4 files changed

+32
-65
lines changed

src/main/java/org/mayheminc/robot2020/RobotContainer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
import org.mayheminc.util.*;
1111

12-
import edu.wpi.first.wpilibj.Compressor;
12+
// import edu.wpi.first.wpilibj.Compressor;
1313
import edu.wpi.first.wpilibj.GenericHID;
1414
import edu.wpi.first.wpilibj.Solenoid;
1515
import edu.wpi.first.wpilibj2.command.Command;
16-
import edu.wpi.first.wpilibj2.command.button.Button;
16+
// import edu.wpi.first.wpilibj2.command.button.Button;
1717

1818
import java.util.LinkedList;
1919

@@ -48,7 +48,7 @@ public class RobotContainer {
4848
public static final MayhemDriverStick DRIVER_STICK = new MayhemDriverStick();
4949
public static final MayhemDriverPad DRIVER_PAD = new MayhemDriverPad();
5050
public static final MayhemOperatorPad OPERATOR_PAD = new MayhemOperatorPad();
51-
private final MayhemOperatorStick OPERATOR_STICK = new MayhemOperatorStick();
51+
// private final MayhemOperatorStick OPERATOR_STICK = new MayhemOperatorStick();
5252

5353
/**
5454
* The container for the robot. Contains subsystems, OI devices, and commands.

src/main/java/org/mayheminc/robot2020/commands/SystemZeroIncludingGyro.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public SystemZeroIncludingGyro() {
2424

2525
@Override
2626
public boolean runsWhenDisabled() {
27-
// TODO Auto-generated method stub
2827
return true;
2928
}
3029

src/main/java/org/mayheminc/robot2020/subsystems/Shooter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ public class Shooter extends SubsystemBase implements PidTunerObject {
2121
private final MayhemTalonSRX hoodTalon = new MayhemTalonSRX(Constants.Talon.SHOOTER_HOOD);
2222
private final MayhemTalonSRX feederTalon = new MayhemTalonSRX(Constants.Talon.SHOOTER_FEEDER);
2323

24-
private final double MAX_SPEED_RPM = 5760.0;
24+
// private final double MAX_SPEED_RPM = 5760.0;
2525
private final double TALON_TICKS_PER_REV = 2048.0;
2626
private final double TURRET_MIN_POS = -5500.0;
2727
private final double TURRET_MAX_POS = +5500.0;
28+
private final double SECONDS_PER_MINUTE = 60.0;
29+
private final double HUNDRED_MS_PER_SECOND = 10.0;
2830

2931
double m_targetSpeedRPM;
3032
History headingHistory = new History();
3133

3234
double convertRpmToTicksPer100ms(double rpm) {
33-
return rpm / 60 * 2048 / 10;
35+
return rpm / SECONDS_PER_MINUTE * TALON_TICKS_PER_REV / HUNDRED_MS_PER_SECOND;
3436
}
3537

3638
double convertTicksPer100msToRPM(double ticks) {
37-
return ticks * 10 / 2048 * 60;
39+
return ticks * HUNDRED_MS_PER_SECOND / TALON_TICKS_PER_REV * SECONDS_PER_MINUTE;
3840
}
3941

4042
/**
@@ -49,7 +51,7 @@ public Shooter() {
4951
shooterWheelTalon.config_kP(0, 3.0, 0);
5052
shooterWheelTalon.config_kI(0, 0.0, 0);
5153
shooterWheelTalon.config_kD(0, 0.0, 0);
52-
shooterWheelTalon.config_kF(0, 0.048);// 1023.0 / convertRpmToTicksPer100ms(5760), 0);
54+
shooterWheelTalon.config_kF(0, 0.048); // 1023.0 / convertRpmToTicksPer100ms(5760), 0);
5355
}
5456

5557
public void init() {

src/main/java/org/mayheminc/robot2020/subsystems/Targeting.java

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class Targeting extends SubsystemBase {
4040
private final static double FOV_CAMERA_IN_DEGREES = 78.0;
4141
private double m_bestY = 0.0;
4242
private double m_bestX = 0.0;
43-
private double tilt = 0.0;
44-
private double area = 0.0;
43+
private double m_tilt = 0.0;
44+
private double m_area = 0.0;
4545

4646
public enum TargetPosition {
4747
LEFT_MOST, CENTER_MOST, RIGHT_MOST, CENTER_OF_RIGHT_CARGO_SHIP, CENTER_OF_LEFT_CARGO_SHIP
@@ -51,17 +51,12 @@ public enum TargetHeight {
5151
CARGO, HATCH
5252
};
5353

54-
private TargetPosition m_mode = TargetPosition.CENTER_MOST;
55-
// Mode for target height
56-
private TargetHeight m_TargetHeightMode = TargetHeight.HATCH;
57-
5854
@Override
5955
public void periodic() {
6056
update();
6157
}
6258

6359
// TODO: make an updateSmartDashboard() method in Targeting for optimization
64-
// TODO: clean up the content in Targeting.update() -- just too long!
6560
public void update() {
6661
// perform periodic update functions for the targeting capability
6762
int latestFrameCount = (int) SmartDashboard.getNumber("frameCount", -1.0 /* default to -1 */);
@@ -86,14 +81,11 @@ public void update() {
8681
SmartDashboard.putString("visionOkDebug", "Good Data");
8782
}
8883

89-
double[] centerMostTargetArray;
9084
// Update all of the targeting information, as follows:
9185
// 1 - Determine if we have any valid data in the array.
9286
// If not, set the "error" to zero, so that the robot thinks
9387
// it is on target.
94-
// 2 - Look through the valid data in the array to find the
95-
// target closest to the "trueCenter"
96-
// 3 - Use the selected target to compute the needed information
88+
// 2 - Use the target to compute the needed information
9789

9890
// get the latest output from the targeting camera
9991
m_target_array = SmartDashboard.getNumberArray("target", ARRAY_OF_NEG_ONE);
@@ -102,15 +94,15 @@ public void update() {
10294
// this means the key is found, but is empty
10395
m_bestX = 0.0;
10496
m_bestY = 0.0;
105-
tilt = 0.0;
106-
area = 0.0;
97+
m_tilt = 0.0;
98+
m_area = 0.0;
10799
m_desiredAzimuth = RobotContainer.shooter.getAzimuthForCapturedImage();
108100
} else if (m_target_array[0] < 0.0) {
109101
// this means the array has no valid data. Set m_xError = 0.0
110102
m_bestX = 0.0;
111103
m_bestY = 0.0;
112-
tilt = 0.0;
113-
area = 0.0;
104+
m_tilt = 0.0;
105+
m_area = 0.0;
114106
m_desiredAzimuth = RobotContainer.shooter.getAzimuthForCapturedImage();
115107
} else {
116108
// We have a valid data array.
@@ -123,17 +115,17 @@ public void update() {
123115
// we need the results in "bestXError" and "bestY"
124116
m_bestX = m_target_array[0]; // get the x-value
125117
m_bestY = m_target_array[1]; // get the y-value
126-
tilt = m_target_array[2];
127-
area = m_target_array[3];
118+
m_tilt = m_target_array[2];
119+
m_area = m_target_array[3];
128120

129-
m_desiredAzimuth = findDesiredAzimuth(m_bestX, m_bestY, tilt, area);
121+
m_desiredAzimuth = findDesiredAzimuth(m_bestX, m_bestY, m_tilt, m_area);
130122
}
131123

132124
// at this point in the code, the "selected" target should be in the "best"
133125
SmartDashboard.putNumber("m_bestX", m_bestX);
134126
SmartDashboard.putNumber("m_bestY", m_bestY);
135-
SmartDashboard.putNumber("tilt", tilt);
136-
SmartDashboard.putNumber("area", area);
127+
SmartDashboard.putNumber("m_tilt", m_tilt);
128+
SmartDashboard.putNumber("m_area", m_area);
137129
}
138130

139131
public double getDesiredAzimuth() {
@@ -163,30 +155,8 @@ public double getRecommendedSpeed() {
163155
return speed;
164156
}
165157

166-
// public boolean atWall(Autonomous.RocketHeight desiredHeight) {
167-
// // we are at the wall when the target is lower in the field of view (bigger
168-
// Y)
169-
// // than the "at the wall" threshold
170-
// switch (desiredHeight) {
171-
// case HIGH:
172-
// return (m_bestY >= Y_WHEN_HATCH_HIGH_AT_WALL);
173-
// case MID:
174-
// return (m_bestY >= Y_WHEN_HATCH_MID_AT_WALL);
175-
// case LOW:
176-
// return (m_bestY >= Y_WHEN_HATCH_LOW_AT_WALL);
177-
// default:
178-
// return (m_bestY >= Y_WHEN_HATCH_LOW_AT_WALL);
179-
// }
180-
// }
181-
182-
public void setMode(TargetPosition modeToSet) {
183-
// Set the mode e.g. LEFT_MOST, CENTER_MOST, RIGHT_MOST,
184-
// CENTER_OF_RIGHT_CARGO_SHIP, CENTER_OF_LEFT_CARGO_SHIP
185-
m_mode = modeToSet;
186-
}
187-
188-
private final double CenterOfTarget_X = 0.5;
189-
private final double TICK_PER_DEGREE = (6300.0 / 45.0);
158+
private final double CENTER_OF_TARGET_X = 0.5;
159+
private final double TICKS_PER_DEGREE = (6300.0 / 45.0);
190160

191161
/**
192162
* Return the desired turrent encoder ticks in the turret for the center of the
@@ -200,28 +170,24 @@ public void setMode(TargetPosition modeToSet) {
200170
*/
201171
public double findDesiredAzimuth(double X, double Y, double tilt, double area) {
202172
// Calulate angle error based on an X,Y
203-
double AngleError;
173+
double angleError;
204174
double ticksError;
205-
// double TrueCenter;
206-
double XError;
175+
double xError;
207176
double desiredAzimuth;
208177

209-
// compute the "x error" based upon the trueCenter
210-
XError = X - CenterOfTarget_X;
178+
// compute the "x error" based upon the center for shooting
179+
xError = X - CENTER_OF_TARGET_X;
211180
// Find the angle error
212-
AngleError = FOV_CAMERA_IN_DEGREES * XError;
213-
ticksError = AngleError * TICK_PER_DEGREE;
181+
angleError = FOV_CAMERA_IN_DEGREES * xError;
182+
// convert the angle error into ticks
183+
ticksError = angleError * TICKS_PER_DEGREE;
214184

215-
// Convert angleError into a desired heading, using the heading history
185+
// Convert angleError into a desired azimuth, using the azimuth history
216186
desiredAzimuth = ticksError + RobotContainer.shooter.getAzimuthForCapturedImage();
217187
// Update SmartDashboard
218-
SmartDashboard.putNumber("True Angle Error", AngleError);
188+
SmartDashboard.putNumber("Vision Angle Error", angleError);
219189
SmartDashboard.putNumber("Vision Desired Azimuth", desiredAzimuth);
220190
return desiredAzimuth;
221191
}
222192

223-
public void setTargetHeight(TargetHeight target) {
224-
m_TargetHeightMode = target;
225-
}
226-
227193
}

0 commit comments

Comments
 (0)