Skip to content

Commit 54aafec

Browse files
committed
Move swerve telemetry registration to telemetry pkg
1 parent b3d7d3b commit 54aafec

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import com.kauailabs.navx.frc.AHRS;
44
import com.moandjiezana.toml.Toml;
55
import edu.wpi.first.wpilibj.Preferences;
6-
import javax.inject.Inject;
7-
import javax.inject.Singleton;
86
import org.slf4j.Logger;
97
import org.slf4j.LoggerFactory;
108
import org.strykeforce.thirdcoast.talon.Errors;
119
import org.strykeforce.thirdcoast.talon.TalonConfiguration;
1210
import org.strykeforce.thirdcoast.util.Settings;
1311

12+
import javax.inject.Inject;
13+
import javax.inject.Singleton;
14+
1415
/**
1516
* Control a Third Coast swerve drive.
1617
*
@@ -220,26 +221,6 @@ public void zeroAzimuthEncoders() {
220221
if (errorCount > 0) logger.error("TalonSRX set azimuth zero error count = {}", errorCount);
221222
}
222223

223-
/**
224-
* Register the swerve wheel azimuth and drive {@link com.ctre.phoenix.motorcontrol.can.TalonSRX}
225-
* with the Telemetry service for data collection. The Telemetry service will set the Talon status
226-
* frame update rates to default values during registration.
227-
*
228-
* @param telemetryService the active Telemetry service instance created by the robot
229-
*/
230-
// public void registerWith(TelemetryService telemetryService) {
231-
// for (int i = 0; i < WHEEL_COUNT; i++) {
232-
// TalonSRX t = wheels[i].getAzimuthTalon();
233-
// if (t != null)
234-
// telemetryService.register(
235-
// new TalonItem(t, "Azimuth Talon " + i + " (" + t.getDeviceID() + ")"));
236-
// t = wheels[i].getDriveTalon();
237-
// if (t != null)
238-
// telemetryService.register(
239-
// new TalonItem(t, "Drive Talon " + i + " (" + t.getDeviceID() + ")"));
240-
// }
241-
// }
242-
243224
/**
244225
* Returns the four wheels of the swerve drive.
245226
*

telemetry/src/main/java/org/strykeforce/thirdcoast/telemetry/TelemetryService.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package org.strykeforce.thirdcoast.telemetry;
22

33
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
4-
import java.util.Collection;
5-
import java.util.Collections;
6-
import java.util.LinkedHashSet;
7-
import java.util.Optional;
8-
import java.util.Set;
9-
import javax.inject.Inject;
10-
import javax.inject.Singleton;
114
import org.slf4j.Logger;
125
import org.slf4j.LoggerFactory;
6+
import org.strykeforce.thirdcoast.swerve.SwerveDrive;
7+
import org.strykeforce.thirdcoast.swerve.Wheel;
138
import org.strykeforce.thirdcoast.talon.config.StatusFrameRate;
149
import org.strykeforce.thirdcoast.telemetry.item.Item;
1510
import org.strykeforce.thirdcoast.telemetry.item.TalonItem;
1611

12+
import javax.inject.Inject;
13+
import javax.inject.Singleton;
14+
import java.util.*;
15+
1716
/**
1817
* The Telemetry service registers {@link Item} instances for data collection and controls the
1918
* starting and stopping of the service. When active, the services listens for incoming config
@@ -79,17 +78,6 @@ public void clear() {
7978
logger.info("item set was cleared");
8079
}
8180

82-
/**
83-
* Convenience method to register a TalonSRX for telemetry sending.
84-
*
85-
* @param talon the TalonSRX to register for data collection
86-
* @throws IllegalStateException if TelemetryService is running.
87-
* @see StatusFrameRate
88-
*/
89-
public void register(TalonSRX talon) {
90-
register(new TalonItem(talon));
91-
}
92-
9381
/**
9482
* Registers an Item for telemetry sending.
9583
*
@@ -117,6 +105,31 @@ public void registerAll(Collection<Item> collection) {
117105
logger.info("registered all: {}", collection);
118106
}
119107

108+
/**
109+
* Convenience method to register a {@code TalonSRX} for telemetry sending.
110+
*
111+
* @param talon the TalonSRX to register for data collection
112+
* @throws IllegalStateException if TelemetryService is running.
113+
* @see StatusFrameRate
114+
*/
115+
public void register(TalonSRX talon) {
116+
register(new TalonItem(talon));
117+
}
118+
119+
/**
120+
* Convenience method to register a {@code SwerveDrive} for telemetry sending.
121+
*
122+
* @param swerveDrive the SwerveDrive to register for data collection
123+
* @throws IllegalStateException if TelemetryService is running.
124+
* @see StatusFrameRate
125+
*/
126+
public void register(SwerveDrive swerveDrive) {
127+
for (Wheel wheel : swerveDrive.getWheels()) {
128+
register(new TalonItem(wheel.getAzimuthTalon()));
129+
register(new TalonItem(wheel.getDriveTalon()));
130+
}
131+
}
132+
120133
/**
121134
* Configure the Talon with the given ID with the given status frame rates.
122135
*

0 commit comments

Comments
 (0)