Skip to content

Commit 8ddb656

Browse files
committed
Finished cleaning up the *Group types
1 parent 476ba4f commit 8ddb656

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

RobotLibrary/src/main/java/com/technototes/library/hardware/HardwareDeviceGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface HardwareDeviceGroup<T extends HardwareDevice> {
2020
*/
2121
T[] getFollowers();
2222

23-
default List<T> getFollowerist() {
23+
default List<T> getFollowerList() {
2424
return Arrays.asList(getFollowers());
2525
}
2626

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import com.qualcomm.robotcore.hardware.DcMotorSimple;
44
import com.technototes.library.hardware.HardwareDeviceGroup;
55

6-
/** Class for encoded motor groups
6+
/**
7+
* Class for encoded motor groups
8+
*
79
* @author Alex Stedman
810
*/
911
@SuppressWarnings("unused")
@@ -13,9 +15,10 @@ public class EncodedMotorGroup<T extends DcMotorSimple>
1315

1416
private final EncodedMotor<T>[] followers;
1517

16-
/** Create an encoded motor groupM
18+
/**
19+
* Create an encoded motor groupM
1720
*
18-
* @param leader The Lead motor
21+
* @param leader The Lead motor
1922
* @param followers The following motors
2023
*/
2124
public EncodedMotorGroup(EncodedMotor<T> leader, EncodedMotor<T>... followers) {
@@ -49,10 +52,26 @@ public void setVelocity(double tps) {
4952
propagate(super.getSpeed());
5053
}
5154

55+
public void setVelocities(double... tps) {
56+
for (int i = 0; i < tps.length && i < getDeviceCount(); i++) {
57+
getDeviceNum(i).setVelocity(tps[i]);
58+
}
59+
}
60+
5261
@Override
5362
public boolean setPosition(double ticks, double speed) {
54-
boolean b = super.setPosition(ticks, speed);
55-
propagate(super.getSpeed());
63+
boolean b = true;
64+
for (int i = 0; i < getDeviceCount(); i++) {
65+
b = getDeviceNum(i).setPosition(ticks, speed) && b;
66+
}
67+
return b;
68+
}
69+
70+
public boolean setPositions(double... ticks_then_speeds) {
71+
boolean b = true;
72+
for (int i = 0; i < ticks_then_speeds.length / 2 && i < getDeviceCount(); i++) {
73+
b = getDeviceNum(i).setPosition(ticks_then_speeds[i * 2], ticks_then_speeds[i * 2 + 1]) && b;
74+
}
5675
return b;
5776
}
5877

RobotLibrary/src/main/java/com/technototes/library/hardware/servo/ServoGroup.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,23 @@ public void propagate(double value) {
4545
}
4646
}
4747

48+
@Override
49+
public Servo getDeviceNum(int i) {
50+
return (i == 0) ? this : followers[i - 1];
51+
}
52+
4853
@Override
4954
public void setPosition(double position) {
5055
super.setPosition(position);
5156
propagate(position);
5257
}
5358

59+
public void setPositions(double... positions) {
60+
for (int i = 0; i < positions.length && i < getDeviceCount(); i++) {
61+
getDeviceNum(i).setPosition(positions[i]);
62+
}
63+
}
64+
5465
@Override
5566
public ServoGroup startAt(double position) {
5667
return (ServoGroup) super.startAt(position);

RobotLibrary/src/main/java/com/technototes/library/subsystem/drivebase/DrivebaseSubsystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.qualcomm.robotcore.hardware.DcMotorSimple;
44
import com.technototes.library.hardware.motor.Motor;
55
import com.technototes.library.hardware.motor.MotorGroup;
6+
import com.technototes.library.subsystem.Subsystem;
67
import java.util.function.DoubleSupplier;
78

89
/**
@@ -11,7 +12,7 @@
1112
* @param <T> The type of motors for the drivebase
1213
* @author Alex Stedman The motors for the drivebase
1314
*/
14-
public abstract class DrivebaseSubsystem<T extends DcMotorSimple> {
15+
public abstract class DrivebaseSubsystem<T extends DcMotorSimple> implements Subsystem {
1516

1617
protected MotorGroup<T> motors;
1718

0 commit comments

Comments
 (0)