Skip to content

Commit 99b2b55

Browse files
kevinfreiKevin Frei
authored andcommitted
A few more updates, cleaned up getting the motor
1 parent d28c873 commit 99b2b55

5 files changed

Lines changed: 24 additions & 18 deletions

File tree

Path/src/main/java/com/technototes/path/subsystem/PathingMecanumDrivebaseSubsystem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public PathingMecanumDrivebaseSubsystem(
123123
c.getDouble(WheelBase.class),
124124
c.getDouble(LateralMult.class)
125125
);
126-
leftFront = fl.getDevice();
127-
leftRear = rl.getDevice();
128-
rightRear = rr.getDevice();
129-
rightFront = fr.getDevice();
126+
leftFront = fl.getRawMotor(DcMotorEx.class);
127+
leftRear = rl.getRawMotor(DcMotorEx.class);
128+
rightRear = rr.getRawMotor(DcMotorEx.class);
129+
rightFront = fr.getRawMotor(DcMotorEx.class);
130130

131131
motors = Arrays.asList(leftFront, leftRear, rightRear, rightFront);
132132

RobotLibrary/src/main/java/com/technototes/library/hardware/motor/EncodedMotor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,10 @@ public EncodedMotor<T> coast() {
291291
public EncodedMotor<T> setLimits(double mi, double ma) {
292292
return (EncodedMotor<T>) super.setLimits(mi, ma);
293293
}
294+
295+
// Ah, Java, you're such a hideous language...
296+
public <U extends DcMotorSimple> U getRawMotor(Class<U> type) {
297+
T device = getRawDevice();
298+
return (device != null && type.isInstance(device)) ? type.cast(device) : null;
299+
}
294300
}

RobotLibrary/src/main/java/com/technototes/library/hardware/sensor/encoder/ExternalEncoder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public void zeroEncoder() {
4343
*/
4444
@Override
4545
public double getSensorValue() {
46-
return getDevice().getVoltage() - zero;
46+
AnalogInput device = getRawDevice();
47+
if (device != null) {
48+
val = device.getVoltage();
49+
}
50+
return val - zero;
4751
}
4852
}

RobotLibrary/src/main/java/com/technototes/library/hardware/sensor/encoder/MotorEncoder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ public MotorEncoder(DcMotorEx motor) {
7575
this(motor, new ElapsedTime());
7676
}
7777

78-
public MotorEncoder(EncodedMotor<DcMotorEx> motor) {
79-
this(motor.getDevice());
80-
}
81-
8278
public MotorEncoder(String deviceName) {
8379
this(hardwareMap.get(DcMotorEx.class, deviceName));
8480
}

Vision/src/main/java/com/technototes/vision/subsystem/BasicVisionSubsystem.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public BasicVisionSubsystem(Camera c, int w, int h, OpenCvCameraRotation rot) {
6060
*
6161
* @return the Camera device in use
6262
*/
63-
public Camera getDevice() {
63+
protected Camera getRawDevice() {
6464
return camera;
6565
}
6666

@@ -211,15 +211,15 @@ protected int countPixelsOfColor(HSVRange range, Mat imgHSV, Mat telemetryRGB, i
211211
// Check to see which pixels are between low and high, output into a boolean matrix Cr
212212
Mat count = new Mat();
213213
Core.inRange(imgHSV, low, high, count);
214-
// TODO: It seems like there should be a more optimized way to do this.
215-
for (int i = 0; i < count.width(); i++) {
216-
for (int j = 0; j < count.height(); j++) {
217-
if (count.get(j, i)[0] > 0) {
218-
totalColorCount++;
219-
// Draw a dots on the image at this point - input was put into img
220-
if (telemetryRGB != null) {
214+
totalColorCount = Core.countNonZero(count);
215+
if (telemetryRGB != null) {
216+
// TODO: It seems like there should be a more optimized way to do this.
217+
for (int i = 0; i < count.width(); i++) {
218+
for (int j = 0; j < count.height(); j++) {
219+
if (count.get(j, i)[0] > 0) {
220+
// Draw a dots on the image at this point - input was put into img
221221
// The color choice makes things stripey, which makes it easier to identify
222-
double[] colorToDraw = ((j + i) & 3) != 0 ? low.val : high.val;
222+
double[] colorToDraw = ((j + i) & 2) != 0 ? low.val : high.val;
223223
telemetryRGB.put(j + yOffset, i + xOffset, colorToDraw);
224224
}
225225
}

0 commit comments

Comments
 (0)