Skip to content

Commit 91decb5

Browse files
committed
Add graphable swerve drive
1 parent 35d5eba commit 91decb5

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.strykeforce.thirdcoast.swerve;
2+
3+
import static org.strykeforce.thirdcoast.telemetry.grapher.Measure.ANGLE;
4+
import static org.strykeforce.thirdcoast.telemetry.grapher.Measure.GYRO_YAW;
5+
6+
import com.kauailabs.navx.frc.AHRS;
7+
import com.squareup.moshi.JsonWriter;
8+
import java.io.IOException;
9+
import java.util.Collections;
10+
import java.util.EnumSet;
11+
import java.util.Set;
12+
import java.util.function.DoubleSupplier;
13+
import javax.inject.Inject;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.strykeforce.thirdcoast.telemetry.TelemetryService;
16+
import org.strykeforce.thirdcoast.telemetry.grapher.Measure;
17+
import org.strykeforce.thirdcoast.telemetry.item.Item;
18+
19+
public class GraphableSwerveDrive extends SwerveDrive implements Item {
20+
21+
private static final String TYPE = "swerve";
22+
private static final String DESCRIPTION = "Swerve Drive";
23+
24+
private static final Set<Measure> MEASURES =
25+
Collections.unmodifiableSet(EnumSet.of(ANGLE, GYRO_YAW));
26+
27+
@Inject
28+
public GraphableSwerveDrive(AHRS gyro, Wheel[] wheels) {
29+
super(gyro, wheels);
30+
}
31+
32+
@Override
33+
public void registerWith(TelemetryService telemetryService) {
34+
super.registerWith(telemetryService);
35+
telemetryService.register(this);
36+
}
37+
38+
@Override
39+
public int deviceId() {
40+
return 0;
41+
}
42+
43+
@Override
44+
public String type() {
45+
return TYPE;
46+
}
47+
48+
@Override
49+
public String description() {
50+
return DESCRIPTION;
51+
}
52+
53+
@Override
54+
public Set<Measure> measures() {
55+
return MEASURES;
56+
}
57+
58+
@Override
59+
public DoubleSupplier measurementFor(Measure measure) {
60+
if (!MEASURES.contains(measure)) {
61+
throw new IllegalArgumentException("invalid measure: " + measure.name());
62+
}
63+
switch (measure) {
64+
case ANGLE:
65+
return gyro::getAngle;
66+
case GYRO_YAW:
67+
return gyro::getYaw;
68+
default:
69+
throw new AssertionError(measure);
70+
}
71+
}
72+
73+
@Override
74+
public void toJson(JsonWriter writer) throws IOException {
75+
writer.beginObject();
76+
writer.name("not").value("implemented");
77+
writer.endObject();
78+
}
79+
80+
@Override
81+
public int compareTo(@NotNull Item o) {
82+
return 0;
83+
}
84+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.strykeforce.thirdcoast.swerve;
2+
3+
import dagger.Module;
4+
import dagger.Provides;
5+
import javax.inject.Singleton;
6+
7+
@Module
8+
public class GraphableSwerveDriveModule {
9+
10+
@Provides
11+
@Singleton
12+
public static SwerveDrive swerveDrive(GraphableSwerveDrive swerveDrive) {
13+
return swerveDrive;
14+
}
15+
}

core/src/main/java/org/strykeforce/thirdcoast/swerve/SwerveDrive.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class SwerveDrive {
3131
static final Logger logger = LoggerFactory.getLogger(SwerveDrive.class);
3232
private static final int WHEEL_COUNT = 4;
3333
private final Wheel[] wheels;
34-
private final AHRS gyro;
34+
final AHRS gyro;
3535

3636
@Inject
3737
SwerveDrive(AHRS gyro, Wheel[] wheels) {

core/src/main/java/org/strykeforce/thirdcoast/telemetry/grapher/Measure.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public enum Measure {
2424
MOMAGIC_ACCL("Motion Magic Acceleration"),
2525
MOMAGIC_A_TRAJ_POS("Motion Magic Trajectory Point Target Position"),
2626
MOMAGIC_A_TRAJ_VEL("Motion Magic Trajectory Point Target Velocity"),
27-
MOMAGIC_CRUISE_VEL("Motion Magic Cruise Velocity");
27+
MOMAGIC_CRUISE_VEL("Motion Magic Cruise Velocity"),
28+
GYRO_YAW("Gyro Yaw");
2829

2930
// private final static Map<Item.Type, Set<Measure>> byType = new HashMap<>();
3031
//

robot/src/main/java/org/team2767/thirdcoast/RobotComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import dagger.Component;
55
import java.io.File;
66
import javax.inject.Singleton;
7+
import org.strykeforce.thirdcoast.swerve.GraphableSwerveDriveModule;
78
import org.strykeforce.thirdcoast.swerve.GyroModule;
89
import org.strykeforce.thirdcoast.swerve.SwerveDrive;
910
import org.strykeforce.thirdcoast.swerve.WheelModule;
@@ -17,6 +18,7 @@
1718
modules = {
1819
GyroModule.class,
1920
WheelModule.class,
21+
GraphableSwerveDriveModule.class,
2022
}
2123
)
2224
interface RobotComponent {

0 commit comments

Comments
 (0)