11package org .strykeforce .thirdcoast .telemetry .tct .talon ;
22
3- import static org .strykeforce .thirdcoast .telemetry .tct .talon .config .AbstractTalonConfigCommand .VERIFY ;
4-
53import com .ctre .phoenix .ParamEnum ;
4+ import com .ctre .phoenix .motorcontrol .NeutralMode ;
65import com .ctre .phoenix .motorcontrol .VelocityMeasPeriod ;
6+ import java .io .PrintWriter ;
77import java .util .Formatter ;
88import java .util .List ;
99import java .util .Set ;
1212import javax .annotation .ParametersAreNonnullByDefault ;
1313import javax .inject .Inject ;
1414import org .jline .reader .LineReader ;
15+ import org .strykeforce .thirdcoast .talon .Encoder ;
16+ import org .strykeforce .thirdcoast .talon .LimitSwitch ;
17+ import org .strykeforce .thirdcoast .talon .MotionMagicTalonConfiguration ;
18+ import org .strykeforce .thirdcoast .talon .PIDTalonConfiguration ;
19+ import org .strykeforce .thirdcoast .talon .SoftLimit ;
20+ import org .strykeforce .thirdcoast .talon .TalonConfiguration ;
1521import org .strykeforce .thirdcoast .talon .ThirdCoastTalon ;
1622import org .strykeforce .thirdcoast .telemetry .tct .AbstractCommand ;
1723import org .strykeforce .thirdcoast .telemetry .tct .Messages ;
2026@ ParametersAreNonnullByDefault
2127public class ListCommand extends AbstractCommand {
2228
23- public static final String NAME = VERIFY + "List Selected Talons with Current Register Values" ;
24- private static final String FORMAT_DESCRIPTION = "%12s" ;
25- private static final String FORMAT_DOUBLE = "%12.3f" ;
26- private static final String FORMAT_INTEGER = "%12d" ;
27- private static final String FORMAT_STRING = "%12s" ;
29+ public static final String NAME = "List Selected Talons with Configuration" ;
30+ private static final String FORMAT_DESCRIPTION = "%14s" ;
31+ private static final String FORMAT_CONFIG_DESCRIPTION = "%-24s" ;
32+ private static final String FORMAT_DOUBLE = "%14.3f" ;
33+ private static final String FORMAT_INTEGER = "%14d" ;
34+ private static final String FORMAT_STRING = "%14s" ;
2835
2936 private final TalonSet talonSet ;
3037
@@ -62,13 +69,18 @@ private static int intValue(@Nullable VelocityMeasPeriod period) {
6269
6370 @ Override
6471 public void perform () {
72+ PrintWriter writer = terminal .writer ();
73+
74+ //
75+ // read talons directly
76+ //
6577 Set <ThirdCoastTalon > talons = talonSet .selected ();
66- terminal . writer () .println ();
78+ writer .println ();
6779 if (talons .size () == 0 ) {
68- terminal . writer () .println (Messages .NO_TALONS );
80+ writer .println (Messages .NO_TALONS );
6981 return ;
7082 }
71- terminal . writer () .print (header ());
83+ writer .print (header ());
7284 outputString (
7385 "Mode:" ,
7486 talons
@@ -81,7 +93,6 @@ public void perform() {
8193 outputParameter ("D:" , ParamEnum .eProfileParamSlot_D );
8294 outputParameter ("F:" , ParamEnum .eProfileParamSlot_F );
8395 outputParameter ("IZone:" , ParamEnum .eProfileParamSlot_IZone );
84- outputParameter ("Max I Accum:" , ParamEnum .eProfileParamSlot_MaxIAccum );
8596 outputParameter ("Allowed Err:" , ParamEnum .eProfileParamSlot_AllowableErr );
8697
8798 outputInteger (
@@ -120,7 +131,101 @@ public void perform() {
120131
121132 outputParameter ("VM Period:" , ParamEnum .eSampleVelocityPeriod );
122133 outputParameter ("VM Window:" , ParamEnum .eSampleVelocityWindow );
123- terminal .writer ().println ();
134+ writer .println ();
135+
136+ //
137+ // read talon configuration
138+ //
139+ writer .println (Messages .bold ("Current session configuration:" ));
140+ TalonConfiguration config = talonSet .talonConfigurationBuilder ().build ();
141+ writer .println ();
142+
143+ stringLine ("Mode:" , config .getMode ().name ());
144+ doubleLine ("Max Setpoint:" , config .getSetpointMax ());
145+ Encoder encoder = config .getEncoder ();
146+ if (encoder != null ) {
147+ writer .println ();
148+ stringLine ("Encoder:" , encoder .getDevice ().name ());
149+ booleanLine (" Reversed:" , encoder .isReversed ());
150+ writer .println ();
151+ } else {
152+ stringLine ("Encoder:" , "DEFAULT" );
153+ }
154+
155+ NeutralMode neutralMode = config .getBrakeInNeutral ();
156+ stringLine ("Neutral Mode:" , neutralMode != null ? neutralMode .name () : "DEFAULT" );
157+ booleanLine ("Output Reversed:" , config .getOutputReversed ());
158+ VelocityMeasPeriod period = config .getVelocityMeasurementPeriod ();
159+ stringLine ("Vel. Meas. Period:" , period != null ? period .name () : "DEFAULT" );
160+ intLine ("Vel. Meas. Window:" , config .getVelocityMeasurementWindow ());
161+
162+ LimitSwitch limit = config .getForwardLimitSwitch ();
163+ if (limit != null ) {
164+ writer .println ();
165+ booleanLine ("Fwd Limit Switch:" , limit .isEnabled ());
166+ booleanLine (" Normally Open :" , limit .isNormallyOpen ());
167+ } else {
168+ stringLine ("Fwd Limit Switch:" , "DEFAULT" );
169+ }
170+
171+ limit = config .getReverseLimitSwitch ();
172+ if (limit != null ) {
173+ writer .println ();
174+ booleanLine ("Rev Limit Switch:" , limit .isEnabled ());
175+ booleanLine (" Normally Open :" , limit .isNormallyOpen ());
176+ writer .println ();
177+ } else {
178+ stringLine ("Rev Limit Switch:" , "DEFAULT" );
179+ }
180+
181+ SoftLimit soft = config .getForwardSoftLimit ();
182+ if (soft != null ) {
183+ writer .println ();
184+ booleanLine ("Fwd Soft Limit:" , soft .isEnabled ());
185+ intLine (" Position:" , soft .getPosition ());
186+ writer .println ();
187+ } else {
188+ stringLine ("Fwd Soft Limit:" , "DEFAULT" );
189+ }
190+
191+ soft = config .getReverseSoftLimit ();
192+ if (soft != null ) {
193+ writer .println ();
194+ booleanLine ("Rev Soft Limit:" , soft .isEnabled ());
195+ intLine (" Position:" , soft .getPosition ());
196+ writer .println ();
197+ } else {
198+ stringLine ("Rev Soft Limit:" , "DEFAULT" );
199+ }
200+
201+ intLine ("Current Limit:" , config .getContinuousCurrentLimit ());
202+ doubleLine ("Voltage Ramp Rate:" , config .getOpenLoopRampTime ());
203+
204+ if (config instanceof PIDTalonConfiguration ) {
205+ PIDTalonConfiguration pid = (PIDTalonConfiguration ) config ;
206+ writer .println ();
207+ doubleLine ("P:" , pid .getPGain ());
208+ doubleLine ("I:" , pid .getIGain ());
209+ doubleLine ("D:" , pid .getDGain ());
210+ doubleLine ("F:" , pid .getFGain ());
211+ intLine ("I-zone:" , pid .getIZone ());
212+ writer .println ();
213+ if (pid instanceof MotionMagicTalonConfiguration ) {
214+ MotionMagicTalonConfiguration mmtc = (MotionMagicTalonConfiguration ) pid ;
215+ intLine ("MM Cruise Velocity:" , mmtc .getMotionMagicCruiseVelocity ());
216+ intLine ("MM Acceleration:" , mmtc .getMotionMagicAcceleration ());
217+ writer .println ();
218+ }
219+ intLine ("Allowable CL Error:" , pid .getAllowableClosedLoopError ());
220+ doubleLine ("Nominal CL Voltage:" , pid .getNominalClosedLoopVoltage ());
221+ doubleLine ("Output Voltage Max:" , pid .getVoltageCompSaturation ());
222+ doubleLine ("Fwd Peak Output Voltage:" , pid .getForwardOutputVoltagePeak ());
223+ doubleLine ("Rev Peak Output Voltage:" , pid .getReverseOutputVoltagePeak ());
224+ doubleLine ("Fwd Nom. Output Voltage:" , pid .getForwardOutputVoltageNominal ());
225+ doubleLine ("Rev Nom. Output Voltage:" , pid .getReverseOutputVoltageNominal ());
226+ }
227+
228+ writer .println ();
124229 }
125230
126231 private void outputParameter (String description , ParamEnum param ) {
@@ -189,4 +294,44 @@ private String header() {
189294 sb .append ("\n " );
190295 return Messages .bold (sb .toString ());
191296 }
297+
298+ private void stringLine (String description , String value ) {
299+ StringBuilder sb = new StringBuilder ();
300+ Formatter formatter = new Formatter (sb );
301+ sb .append (Messages .bold (String .format (FORMAT_CONFIG_DESCRIPTION , description )));
302+ formatter .format (FORMAT_STRING , value );
303+ terminal .writer ().println (sb .toString ());
304+ }
305+
306+ private void booleanLine (String description , @ Nullable Boolean value ) {
307+ StringBuilder sb = new StringBuilder ();
308+ Formatter formatter = new Formatter (sb );
309+ sb .append (Messages .bold (String .format (FORMAT_CONFIG_DESCRIPTION , description )));
310+ formatter .format (FORMAT_STRING , value == null ? "DEFAULT" : (value ? "YES" : "NO" ));
311+ terminal .writer ().println (sb .toString ());
312+ }
313+
314+ private void intLine (String description , @ Nullable Integer value ) {
315+ StringBuilder sb = new StringBuilder ();
316+ Formatter formatter = new Formatter (sb );
317+ sb .append (Messages .bold (String .format (FORMAT_CONFIG_DESCRIPTION , description )));
318+ if (value != null ) {
319+ formatter .format (FORMAT_INTEGER , value );
320+ } else {
321+ formatter .format (FORMAT_STRING , "DEFAULT" );
322+ }
323+ terminal .writer ().println (sb .toString ());
324+ }
325+
326+ private void doubleLine (String description , @ Nullable Double value ) {
327+ StringBuilder sb = new StringBuilder ();
328+ Formatter formatter = new Formatter (sb );
329+ sb .append (Messages .bold (String .format (FORMAT_CONFIG_DESCRIPTION , description )));
330+ if (value != null ) {
331+ formatter .format (FORMAT_DOUBLE , value );
332+ } else {
333+ formatter .format (FORMAT_STRING , "DEFAULT" );
334+ }
335+ terminal .writer ().println (sb .toString ());
336+ }
192337}
0 commit comments