Skip to content

Commit ad87443

Browse files
committed
Merge branch 'feature/talon-dump'
2 parents 45de424 + 71043ab commit ad87443

File tree

5 files changed

+53
-127
lines changed

5 files changed

+53
-127
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
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;
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810
import org.strykeforce.thirdcoast.talon.Errors;
911
import org.strykeforce.thirdcoast.talon.TalonConfiguration;
1012
import org.strykeforce.thirdcoast.util.Settings;
1113

12-
import javax.inject.Inject;
13-
import javax.inject.Singleton;
14-
1514
/**
1615
* Control a Third Coast swerve drive.
1716
*

core/src/main/java/org/strykeforce/thirdcoast/talon/TalonConfiguration.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@
44
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
55
import com.moandjiezana.toml.Toml;
66
import com.moandjiezana.toml.TomlWriter;
7-
import java.util.ArrayList;
8-
import java.util.Arrays;
9-
import java.util.Collections;
10-
import java.util.List;
11-
import java.util.Objects;
7+
import java.util.*;
128
import javax.annotation.Nullable;
139
import javax.annotation.ParametersAreNonnullByDefault;
1410
import org.jetbrains.annotations.NotNull;
1511
import org.slf4j.Logger;
1612
import org.slf4j.LoggerFactory;
17-
import org.strykeforce.thirdcoast.talon.config.Configurable;
18-
import org.strykeforce.thirdcoast.talon.config.CurrentLimits;
19-
import org.strykeforce.thirdcoast.talon.config.FeedbackSensor;
20-
import org.strykeforce.thirdcoast.talon.config.LimitSwitches;
21-
import org.strykeforce.thirdcoast.talon.config.MotionMagic;
22-
import org.strykeforce.thirdcoast.talon.config.Output;
23-
import org.strykeforce.thirdcoast.talon.config.SoftLimits;
24-
import org.strykeforce.thirdcoast.talon.config.VelocityMeasurement;
13+
import org.strykeforce.thirdcoast.talon.config.*;
2514

2615
/**
2716
* Represents a Talon configuration.
@@ -70,9 +59,8 @@ public TalonConfiguration(
7059
}
7160

7261
public static TalonConfiguration create(@Nullable Toml toml) {
73-
if (toml == null) {
74-
return DEFAULT;
75-
}
62+
if (toml == null) return DEFAULT;
63+
7664
String name = toml.getString("name", DEFAULT.name);
7765
List<Integer> talonIds = new ArrayList<>();
7866
for (Long l : toml.getList("talonIds", Collections.<Long>emptyList())) {
@@ -98,6 +86,33 @@ public static TalonConfiguration create(@Nullable Toml toml) {
9886
return configuration;
9987
}
10088

89+
@NotNull
90+
public static Map<String, Object> dump(@Nullable Toml toml) {
91+
// if (toml == null) return DEFAULT;
92+
93+
Map<String, Object> dump = new LinkedHashMap<>();
94+
String name = toml.getString("name", DEFAULT.name);
95+
dump.put("name", name);
96+
List<Integer> talonIds = new ArrayList<>();
97+
for (Long l : toml.getList("talonIds", Collections.<Long>emptyList())) {
98+
talonIds.add(l.intValue());
99+
}
100+
dump.put("talonIds", talonIds);
101+
List<ClosedLoopProfile> closedLoopProfiles = getClosedLoopProfiles(toml, name);
102+
dump.put("closedLoopProfile", closedLoopProfiles);
103+
dump.put("motionMagic", MotionMagic.create(toml.getTable("motionMagic")));
104+
dump.put(
105+
"selectedFeedbackSensor", FeedbackSensor.create(toml.getTable("selectedFeedbackSensor")));
106+
dump.put("limitSwitch", LimitSwitches.create(toml.getTable("limitSwitch")));
107+
dump.put("softLimit", SoftLimits.create(toml.getTable("softLimit")));
108+
dump.put("currentLimit", CurrentLimits.create(toml.getTable("currentLimit")));
109+
dump.put(
110+
"velocityMeasurement", VelocityMeasurement.create(toml.getTable("velocityMeasurement")));
111+
dump.put("output", Output.create(toml.getTable("output")));
112+
113+
return dump;
114+
}
115+
101116
@NotNull
102117
private static List<ClosedLoopProfile> getClosedLoopProfiles(@NotNull Toml toml, String name) {
103118
List<ClosedLoopProfile> closedLoopProfiles = new ArrayList<>(PROFILE_COUNT);

core/src/main/java/org/strykeforce/thirdcoast/talon/Talons.java

Lines changed: 16 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package org.strykeforce.thirdcoast.talon;
22

3-
import com.ctre.phoenix.ParamEnum;
4-
import com.ctre.phoenix.motorcontrol.Faults;
5-
import com.ctre.phoenix.motorcontrol.SensorCollection;
6-
import com.ctre.phoenix.motorcontrol.StatusFrameEnhanced;
73
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
84
import com.moandjiezana.toml.Toml;
9-
import org.slf4j.Logger;
10-
import org.slf4j.LoggerFactory;
11-
import org.strykeforce.thirdcoast.util.Settings;
12-
13-
import javax.annotation.ParametersAreNonnullByDefault;
14-
import javax.inject.Inject;
15-
import javax.inject.Singleton;
5+
import com.moandjiezana.toml.TomlWriter;
166
import java.util.ArrayList;
177
import java.util.HashMap;
188
import java.util.List;
199
import java.util.Map;
2010
import java.util.stream.Collectors;
11+
import javax.annotation.ParametersAreNonnullByDefault;
12+
import javax.inject.Inject;
13+
import javax.inject.Singleton;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
import org.strykeforce.thirdcoast.util.Settings;
2117

2218
/** Instantiate {@link TalonSRX} instances with defaults. */
2319
@Singleton
@@ -37,10 +33,13 @@ public Talons(Settings settings, Factory factory) {
3733
final int timeout = settingsTable.getLong("timeout").intValue();
3834
logger.debug("TalonSRX configuration timeout = {}", timeout);
3935

40-
final boolean summarizeErrors = settingsTable.getBoolean("summarizeErrors", false);
36+
boolean summarizeErrors = settingsTable.getBoolean("summarizeErrors", false);
4137
Errors.setSummarized(summarizeErrors);
4238
logger.debug("TalonSRX configuration errors summarized = {}", summarizeErrors);
4339

40+
boolean logConfig = settingsTable.getBoolean("logConfig", false);
41+
TomlWriter writer = logConfig ? new TomlWriter() : null;
42+
4443
List<TalonConfiguration> talonConfigurations = new ArrayList<>();
4544
List<Toml> talonConfigTables = settings.getTables(TALONS);
4645
if (talonConfigTables.size() == 0) logger.warn("no TalonSRX configurations available");
@@ -52,6 +51,11 @@ public Talons(Settings settings, Factory factory) {
5251

5352
for (Toml toml : talonConfigTables) {
5453
TalonConfiguration config = TalonConfiguration.create(toml);
54+
if (logConfig) {
55+
Map<String, Object> dump = new HashMap<>(1);
56+
dump.put("TALON", TalonConfiguration.dump(toml));
57+
logger.info("\n" + writer.write(dump));
58+
}
5559
talonConfigurations.add(config);
5660
logger.debug("added '{}' for TalonSRX ids: {}", config.getName(), config.getTalonIds());
5761
}
@@ -72,98 +76,6 @@ public Talons(Settings settings, Factory factory) {
7276
if (errorCount > 0) logger.error("TalonSRX configuration error count = {}", errorCount);
7377
}
7478

75-
@SuppressWarnings("unused")
76-
public static void dump(TalonSRX talon) {
77-
logger.debug("Talon ID = {}", talon.getDeviceID());
78-
int timeout = 10;
79-
for (int i = 0; i < 4; i++) {
80-
logger.debug(
81-
"Slot {} P = {}", i, talon.configGetParameter(ParamEnum.eProfileParamSlot_P, i, timeout));
82-
logger.debug(
83-
"Slot {} I = {}", i, talon.configGetParameter(ParamEnum.eProfileParamSlot_I, i, timeout));
84-
logger.debug(
85-
"Slot {} D = {}", i, talon.configGetParameter(ParamEnum.eProfileParamSlot_D, i, timeout));
86-
logger.debug(
87-
"Slot {} F = {}", i, talon.configGetParameter(ParamEnum.eProfileParamSlot_F, i, timeout));
88-
logger.debug(
89-
"Slot {} Izone = {}",
90-
i,
91-
talon.configGetParameter(ParamEnum.eProfileParamSlot_IZone, i, timeout));
92-
logger.debug(
93-
"Slot {} Max I Accum = {}",
94-
i,
95-
talon.configGetParameter(ParamEnum.eProfileParamSlot_MaxIAccum, i, timeout));
96-
logger.debug(
97-
"Slot {} Allowable Error = {}",
98-
i,
99-
talon.configGetParameter(ParamEnum.eProfileParamSlot_AllowableErr, i, timeout));
100-
}
101-
logger.debug(
102-
"Motion Magic Acceleration = {}",
103-
talon.configGetParameter(ParamEnum.eMotMag_Accel, 0, timeout));
104-
logger.debug(
105-
"Motion Magic Cruise Velocity = {}",
106-
talon.configGetParameter(ParamEnum.eMotMag_VelCruise, 0, timeout));
107-
logger.debug(
108-
"Feedback Sensor Type = {}",
109-
talon.configGetParameter(ParamEnum.eFeedbackSensorType, 0, timeout));
110-
111-
logger.debug("Closed Loop Error 0 = {}", talon.getClosedLoopError(0));
112-
logger.debug("Closed Loop Error 1 = {}", talon.getClosedLoopError(1));
113-
logger.debug("Closed Loop Target 0 = {}", talon.getClosedLoopTarget(0));
114-
logger.debug("Closed Loop Target 1 = {}", talon.getClosedLoopTarget(1));
115-
logger.debug("Control Mode = {}", talon.getControlMode());
116-
117-
// logger.debug("Error Derivative 0 = {}", talon.getErrorDerivative(0));
118-
// logger.debug("Error Derivative 1 = {}", talon.getErrorDerivative(1));
119-
// logger.debug("Active Trajectory Heading = {}", talon.getActiveTrajectoryHeading());
120-
// logger.debug("Active Trajectory Position = {}", talon.getActiveTrajectoryPosition());
121-
// logger.debug("Active Trajectory Velocity = {}", talon.getActiveTrajectoryVelocity());
122-
// logger.debug("Base ID = {}", talon.getBaseID());
123-
// logger.debug("Bus Voltage = {}", talon.getBusVoltage());
124-
125-
Faults faults = new Faults();
126-
talon.getFaults(faults);
127-
logger.debug("Faults = {}", faults);
128-
129-
logger.debug("Firmware Version = {}", talon.getFirmwareVersion());
130-
logger.debug("Integral Accumulator 0 = {}", talon.getIntegralAccumulator(0));
131-
logger.debug("Integral Accumulator 1 = {}", talon.getIntegralAccumulator(1));
132-
logger.debug("Inverted = {}", talon.getInverted());
133-
logger.debug("Last Error = {}", talon.getLastError());
134-
// TODO: MotionProfileStatus
135-
logger.debug("Motor Output Percent = {}", talon.getMotorOutputPercent());
136-
logger.debug("Motor Output Voltage = {}", talon.getMotorOutputVoltage());
137-
logger.debug("Output Current = {}", talon.getOutputCurrent());
138-
logger.debug("Selected Sensor Position 0 = {}", talon.getSelectedSensorPosition(0));
139-
logger.debug("Selected Sensor Position 1 = {}", talon.getSelectedSensorPosition(1));
140-
logger.debug("Selected Sensor Velocity 0 = {}", talon.getSelectedSensorVelocity(0));
141-
logger.debug("Selected Sensor Velocity 1 = {}", talon.getSelectedSensorVelocity(1));
142-
143-
SensorCollection sensors = talon.getSensorCollection();
144-
logger.debug("Analog In = {}", sensors.getAnalogIn());
145-
logger.debug("Analog In Raw = {}", sensors.getAnalogInRaw());
146-
logger.debug("Analog In Velocity = {}", sensors.getAnalogInVel());
147-
logger.debug("Pin State Quad A = {}", sensors.getPinStateQuadA());
148-
logger.debug("Pin State Quad B = {}", sensors.getPinStateQuadB());
149-
logger.debug("Pin State Quad Index = {}", sensors.getPinStateQuadIdx());
150-
logger.debug("Pulse Width Position = {}", sensors.getPulseWidthPosition());
151-
logger.debug("Pulse Width Rise to Fall usec = {}", sensors.getPulseWidthRiseToFallUs());
152-
logger.debug("Pulse Width Rise to Rise usec = {}", sensors.getPulseWidthRiseToRiseUs());
153-
logger.debug("Pulse Width Position = {}", sensors.getPulseWidthPosition());
154-
logger.debug("Pulse Width Velocity = {}", sensors.getPulseWidthVelocity());
155-
logger.debug("Quadrature Position = {}", sensors.getQuadraturePosition());
156-
logger.debug("Quadrature Velocity = {}", sensors.getQuadratureVelocity());
157-
logger.debug("Forward Limit Switch Closed = {}", sensors.isFwdLimitSwitchClosed());
158-
logger.debug("Reverse Limit Switch Closed = {}", sensors.isRevLimitSwitchClosed());
159-
logger.debug("Temperature = {}", talon.getTemperature());
160-
logger.debug("Reset Has Occurred = {}", talon.hasResetOccurred());
161-
162-
for (StatusFrameEnhanced sfe : StatusFrameEnhanced.values()) {
163-
logger.debug("Status Frame Period {} = {}", sfe, talon.getStatusFramePeriod(sfe, timeout));
164-
}
165-
}
166-
16779
/**
16880
* Gets a {@link TalonSRX} with appropriate default values.
16981
*

core/src/main/resources/META-INF/thirdcoast/defaults.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
[THIRDCOAST.TALONS]
2020
timeout = 10
2121
summarizeErrors = false
22+
logConfig = false

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.strykeforce.thirdcoast.telemetry;
22

33
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
4+
import java.util.*;
5+
import javax.inject.Inject;
6+
import javax.inject.Singleton;
47
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
69
import org.strykeforce.thirdcoast.swerve.SwerveDrive;
@@ -9,10 +12,6 @@
912
import org.strykeforce.thirdcoast.telemetry.item.Item;
1013
import org.strykeforce.thirdcoast.telemetry.item.TalonItem;
1114

12-
import javax.inject.Inject;
13-
import javax.inject.Singleton;
14-
import java.util.*;
15-
1615
/**
1716
* The Telemetry service registers {@link Item} instances for data collection and controls the
1817
* starting and stopping of the service. When active, the services listens for incoming config

0 commit comments

Comments
 (0)