001/* Copyright (C) Cross The Road Electronics 2024 */
002package com.ctre.phoenix.motorcontrol.can;
003
004import com.ctre.phoenix.ErrorCode;
005import com.ctre.phoenix.ErrorCollection;
006import com.ctre.phoenix.ParamEnum;
007import com.ctre.phoenix.motorcontrol.ControlMode;
008import com.ctre.phoenix.motorcontrol.DemandType;
009import com.ctre.phoenix.motorcontrol.FeedbackDevice;
010import com.ctre.phoenix.motorcontrol.InvertType;
011import com.ctre.phoenix.motorcontrol.MotorCommutation;
012import com.ctre.phoenix.motorcontrol.StatorCurrentLimitConfiguration;
013import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration;
014import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
015import com.ctre.phoenix.motorcontrol.TalonFXFeedbackDevice;
016import com.ctre.phoenix.motorcontrol.TalonFXInvertType;
017import com.ctre.phoenix.motorcontrol.TalonFXSensorCollection;
018import com.ctre.phoenix.motorcontrol.TalonFXSimCollection;
019import com.ctre.phoenix.sensors.AbsoluteSensorRange;
020import com.ctre.phoenix.sensors.SensorInitializationStrategy;
021
022/**
023 * CTRE Talon FX Motor Controller when used on CAN Bus.
024 *
025 * <pre>
026 * {@code
027 * // Example usage of a TalonFX motor controller
028 * TalonFX motor = new TalonFX(0); // creates a new TalonFX with ID 0
029 *
030 * TalonFXConfiguration config = new TalonFXConfiguration();
031 * config.supplyCurrLimit.enable = true;
032 * config.supplyCurrLimit.triggerThresholdCurrent = 40; // the peak supply current, in amps
033 * config.supplyCurrLimit.triggerThresholdTime = 1.5; // the time at the peak supply current before the limit triggers, in sec
034 * config.supplyCurrLimit.currentLimit = 30; // the current to maintain if the peak supply limit is triggered
035 * motor.configAllSettings(config); // apply the config settings; this selects the quadrature encoder
036 *
037 * motor.set(TalonFXControlMode.PercentOutput, 0.5); // runs the motor at 50% power
038 *
039 * System.out.println(motor.getSelectedSensorPosition()); // prints the position of the selected sensor
040 * System.out.println(motor.getSelectedSensorVelocity()); // prints the velocity recorded by the selected sensor
041 * System.out.println(motor.getMotorOutputPercent()); // prints the percent output of the motor (0.5)
042 * System.out.println(motor.getStatorCurrent()); // prints the output current of the motor
043 *
044 * ErrorCode error = motor.getLastError(); // gets the last error generated by the motor controller
045 * Faults faults = new Faults();
046 * ErrorCode faultsError = motor.getFaults(faults); // fills faults with the current motor controller faults; returns the last error generated
047 *
048 * motor.setStatusFramePeriod(StatusFrame.Status_2_Feedback0, 10); // changes the period of the Status 2 frame (getSelectedSensor*()) to 10ms
049 * }
050 * </pre>
051 *
052 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
053 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
054 * Phoenix 6 API. A migration guide is available at
055 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
056 * <p>
057 * If the Phoenix 5 API must be used for this device, the device must have 22.X
058 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
059 * the firmware year dropdown.
060 */
061@Deprecated(since = "2024", forRemoval = true)
062public class TalonFX extends BaseTalon {
063
064    /**
065     * Constructor
066     * @param deviceNumber [0,62]
067         * @param canbus Name of the CANbus; can be a SocketCAN interface (on Linux),
068         *               or a CANivore device name or serial number
069     */
070    public TalonFX(int deviceNumber, String canbus) {
071        super(deviceNumber, "Talon FX", canbus);
072    }
073
074    /**
075     * Constructor
076     * @param deviceNumber [0,62]
077     */
078    public TalonFX(int deviceNumber) {
079        this(deviceNumber, "");
080    }
081
082    // ------ Set output routines. ----------//
083    /**
084     * Sets the appropriate output on the talon, depending on the mode.
085     * @param mode The output mode to apply.
086     * In PercentOutput, the output is between -1.0 and 1.0, with 0.0 as stopped.
087     * In Current mode, output value is in amperes.
088     * In Velocity mode, output value is in position change / 100ms.
089     * In Position mode, output value is in encoder ticks or an analog value,
090     *   depending on the sensor.
091     * In Follower mode, the output value is the integer device ID of the talon to
092     * duplicate.
093     *
094     * @param value The setpoint value, as described above.
095     *
096     *
097     *  Standard Driving Example:
098    *   _talonLeft.set(ControlMode.PercentOutput, leftJoy);
099    *   _talonRght.set(ControlMode.PercentOutput, rghtJoy);
100    */
101    public void set(TalonFXControlMode mode, double value) {
102        super.set(mode.toControlMode(), value);
103    }
104    /**
105     * @param mode Sets the appropriate output on the talon, depending on the mode.
106     * @param demand0 The output value to apply.
107     *  such as advanced feed forward and/or auxiliary close-looping in firmware.
108     * In PercentOutput, the output is between -1.0 and 1.0, with 0.0 as stopped.
109     * In Current mode, output value is in amperes.
110     * In Velocity mode, output value is in position change / 100ms.
111     * In Position mode, output value is in encoder ticks or an analog value,
112     *   depending on the sensor. See
113     * In Follower mode, the output value is the integer device ID of the talon to
114     * duplicate.
115     *
116     * @param demand1Type The demand type for demand1.
117     * Neutral: Ignore demand1 and apply no change to the demand0 output.
118     * AuxPID: Use demand1 to set the target for the auxiliary PID 1.  Auxiliary
119     *   PID is always executed as standard Position PID control.
120     * ArbitraryFeedForward: Use demand1 as an arbitrary additive value to the
121     *   demand0 output.  In PercentOutput the demand0 output is the motor output,
122    *   and in closed-loop modes the demand0 output is the output of PID0.
123    * @param demand1 Supplmental output value.
124    * AuxPID: Target position in Sensor Units
125    * ArbitraryFeedForward: Percent Output between -1.0 and 1.0
126    *
127    *
128    *  Arcade Drive Example:
129    *           _talonLeft.set(ControlMode.PercentOutput, joyForward, DemandType.ArbitraryFeedForward, +joyTurn);
130    *           _talonRght.set(ControlMode.PercentOutput, joyForward, DemandType.ArbitraryFeedForward, -joyTurn);
131    *
132    *   Drive Straight Example:
133    *   Note: Selected Sensor Configuration is necessary for both PID0 and PID1.
134    *           _talonLeft.follow(_talonRght, FollwerType.AuxOutput1);
135    *           _talonRght.set(ControlMode.PercentOutput, joyForward, DemandType.AuxPID, desiredRobotHeading);
136    *
137    *   Drive Straight to a Distance Example:
138    *   Note: Other configurations (sensor selection, PID gains, etc.) need to be set.
139    *           _talonLeft.follow(_talonRght, FollwerType.AuxOutput1);
140    *           _talonRght.set(ControlMode.MotionMagic, targetDistance, DemandType.AuxPID, desiredRobotHeading);
141    */
142    public void set(TalonFXControlMode mode, double demand0, DemandType demand1Type, double demand1) {
143        super.set(mode.toControlMode(), demand0, demand1Type, demand1);
144    }
145    //------ Invert behavior ----------//
146    /**
147     * Inverts the hbridge output of the motor controller in relation to the master if present
148     *
149     * This does not impact sensor phase and should not be used to correct sensor polarity.
150     *
151     * This will allow you to either:
152     *  - Spin counterclockwise (default)
153     *  - Spin Clockwise (invert direction)
154     *  - Always follow the master regardless of master's inversion
155     *  - Always oppose the master regardless of master's inversion
156     *
157     * @param invertType
158     *            Invert state to set.
159     */
160    public void setInverted(TalonFXInvertType invertType)
161    {
162        super.setInverted(invertType.toInvertType());
163    }
164
165    //------ sensor selection ----------//
166    /**
167     * Select the feedback device for the motor controller.
168     *
169     * @param feedbackDevice
170     *            Talon FX feedback Device to select.
171     * @param pidIdx
172     *            0 for Primary closed-loop. 1 for auxiliary closed-loop.
173     * @param timeoutMs
174     *            Timeout value in ms. If nonzero, function will wait for
175     *            config success and report an error if it times out.
176     *            If zero, no blocking or checking is performed.
177     * @return Error Code generated by function. 0 indicates no error.
178     */
179    public ErrorCode configSelectedFeedbackSensor(TalonFXFeedbackDevice feedbackDevice, int pidIdx, int timeoutMs) {
180        return super.configSelectedFeedbackSensor(feedbackDevice.toFeedbackDevice(), pidIdx, timeoutMs);
181    }
182    //------ Current Lim ----------//
183
184    /**
185     * Configures the supply (input) current limit.
186     * @param currLimitCfg  Current limit configuration
187     * @param timeoutMs
188     *            Timeout value in ms. If nonzero, function will wait for
189     *            config success and report an error if it times out.
190     *            If zero, no blocking or checking is performed.
191     * @return Error Code generated by function. 0 indicates no error.
192     */
193    public ErrorCode configSupplyCurrentLimit(SupplyCurrentLimitConfiguration currLimitCfg, int timeoutMs) {
194        double[] doubles = currLimitCfg.toArray();
195        return ErrorCode.valueOf(MotControllerJNI.ConfigSupplyCurrentLimit(getHandle(), doubles, timeoutMs));
196    }
197    /**
198     * Configures the supply (input) current limit.
199     * @param currLimitCfg  Current limit configuration
200     * @return Error Code generated by function. 0 indicates no error.
201     */
202    public ErrorCode configSupplyCurrentLimit(SupplyCurrentLimitConfiguration currLimitCfg) {
203        int timeoutMs = 50;
204        return configSupplyCurrentLimit(currLimitCfg, timeoutMs);
205    }
206    /**
207     * Configures the stator (output) current limit.
208     * @param currLimitCfg  Current limit configuration
209     * @param timeoutMs
210     *            Timeout value in ms. If nonzero, function will wait for
211     *            config success and report an error if it times out.
212     *            If zero, no blocking or checking is performed.
213     * @return Error Code generated by function. 0 indicates no error.
214     */
215    public ErrorCode configStatorCurrentLimit(StatorCurrentLimitConfiguration currLimitCfg, int timeoutMs)
216    {
217        double[] doubles = currLimitCfg.toArray();
218        return ErrorCode.valueOf(MotControllerJNI.ConfigStatorCurrentLimit(getHandle(), doubles, timeoutMs));
219    }
220    /**
221     * Configures the stator (output) current limit.
222     * @param currLimitCfg  Current limit configuration
223     * @return Error Code generated by function. 0 indicates no error.
224     */
225    public ErrorCode configStatorCurrentLimit(StatorCurrentLimitConfiguration currLimitCfg)
226    {
227        int timeoutMs = 50;
228        return configStatorCurrentLimit(currLimitCfg, timeoutMs);
229    }
230    /**
231     * Gets the supply (input) current limit configuration.
232     * @param currLimitConfigsToFill  Configuration object to fill with read values.
233     * @param timeoutMs
234     *            Timeout value in ms. If nonzero, function will wait for
235     *            config success and report an error if it times out.
236     * @return Error Code generated by function. 0 indicates no error.
237     */
238    public ErrorCode configGetSupplyCurrentLimit(SupplyCurrentLimitConfiguration currLimitConfigsToFill, int timeoutMs)
239    {
240        double toFill[] = new double[10];
241        int fillCnt = MotControllerJNI.ConfigGetSupplyCurrentLimit(getHandle(), toFill, timeoutMs);
242        currLimitConfigsToFill.deserialize(toFill);
243        return getLastError();
244    }
245    /**
246     * Gets the supply (input) current limit configuration.
247     * @param currLimitConfigsToFill  Configuration object to fill with read values..
248     * @return Error Code generated by function. 0 indicates no error.
249     */
250    public ErrorCode configGetSupplyCurrentLimit(SupplyCurrentLimitConfiguration currLimitConfigsToFill)
251    {
252        int timeoutMs = 50;
253        return configGetSupplyCurrentLimit(currLimitConfigsToFill, timeoutMs);
254    }
255    /**
256     * Gets the stator (output) current limit configuration.
257     * @param currLimitConfigsToFill  Configuration object to fill with read values.
258     * @param timeoutMs
259     *            Timeout value in ms. If nonzero, function will wait for
260     *            config success and report an error if it times out.
261     * @return Error Code generated by function. 0 indicates no error.
262     */
263    public ErrorCode configGetStatorCurrentLimit(StatorCurrentLimitConfiguration currLimitConfigsToFill, int timeoutMs)
264    {
265        double toFill[] = new double[10];
266        int fillCnt = MotControllerJNI.ConfigGetStatorCurrentLimit(getHandle(), toFill, timeoutMs);
267        currLimitConfigsToFill.deserialize(toFill);
268        return getLastError();
269    }
270    /**
271     * Gets the stator (output) current limit configuration.
272     * @param currLimitConfigsToFill  Configuration object to fill with read values.
273     * @return Error Code generated by function. 0 indicates no error.
274     */
275    public ErrorCode configGetStatorCurrentLimit(StatorCurrentLimitConfiguration currLimitConfigsToFill)
276    {
277        int timeoutMs = 50;
278        return configGetStatorCurrentLimit(currLimitConfigsToFill, timeoutMs);
279    }
280
281    /**
282     * Configure the motor commutation type.
283     *
284     * @param motorCommutation  Motor Commutation Type.
285     *
286     * @param timeoutMs
287     *            Timeout value in ms. If nonzero, function will wait for config
288     *            success and report an error if it times out. If zero, no
289     *            blocking or checking is performed.
290     */
291    public ErrorCode configMotorCommutation(MotorCommutation motorCommutation, int timeoutMs)
292    {
293        return ErrorCode.valueOf(MotControllerJNI.ConfigMotorCommutation(getHandle(), motorCommutation.value, timeoutMs));
294    }
295    /**
296     * Configure the motor commutation type.
297     *
298     * @param motorCommutation  Motor Commutation Type.
299     */
300    public ErrorCode configMotorCommutation(MotorCommutation motorCommutation)
301    {
302        int timeoutMs = 50;
303        return configMotorCommutation(motorCommutation, timeoutMs);
304    }
305
306    /**
307     * @param timeoutMs
308     *            Timeout value in ms. If nonzero, function will wait for config
309     *            success and report an error if it times out.
310     * @return  The motor commutation type.
311     */
312    public MotorCommutation configGetMotorCommutation(int timeoutMs)
313    {
314        return MotorCommutation.values()[MotControllerJNI.ConfigGetMotorCommutation(getHandle(), timeoutMs)];
315    }
316    /**
317     * @return  The motor commutation type.
318     */
319    public MotorCommutation configGetMotorCommutation()
320    {
321        int timeoutMs = 0;
322        return configGetMotorCommutation(timeoutMs);
323    }
324
325    /**
326     * Sets the signage and range of the "Absolute Position" signal.
327     * Choose unsigned for an absolute range of [0,+1) rotations, [0,360) deg, etc...
328     * Choose signed for an absolute range of [-0.5,+0.5) rotations, [-180,+180) deg, etc...
329     * @param absoluteSensorRange
330     *            Desired Sign/Range for the absolute position register.
331     * @param timeoutMs
332     *            Timeout value in ms. If nonzero, function will wait for
333     *            config success and report an error if it times out.
334     *            If zero, no blocking or checking is performed.
335     * @return Error Code generated by function. 0 indicates no error.
336     */
337    public ErrorCode configIntegratedSensorAbsoluteRange(AbsoluteSensorRange absoluteSensorRange, int timeoutMs)
338    {
339        return ErrorCode.valueOf(MotControllerJNI.ConfigIntegratedSensorAbsoluteRange(getHandle(), absoluteSensorRange.value, timeoutMs));
340    }
341
342    /**
343     * Sets the signage and range of the "Absolute Position" signal.
344     * Choose unsigned for an absolute range of [0,+1) rotations, [0,360) deg, etc...
345     * Choose signed for an absolute range of [-0.5,+0.5) rotations, [-180,+180) deg, etc...
346     * @param absoluteSensorRange
347     *            Desired Sign/Range for the absolute position register.
348     * @return Error Code generated by function. 0 indicates no error.
349     */
350    public ErrorCode configIntegratedSensorAbsoluteRange(AbsoluteSensorRange absoluteSensorRange)
351    {
352        int timeoutMs = 0;
353        return configIntegratedSensorAbsoluteRange(absoluteSensorRange, timeoutMs);
354    }
355    /**
356     * Adjusts the zero point for the integrated sensor absolute position register.
357     * The absolute position of the sensor will always have a discontinuity (360 -> 0 deg) or (+180 -> -180)
358     * and a hard-limited mechanism may have such a discontinuity in its functional range.
359     * In which case use this config to move the discontinuity outside of the function range.
360     * @param offsetDegrees
361     *            Offset in degrees
362     * @param timeoutMs
363     *            Timeout value in ms. If nonzero, function will wait for
364     *            config success and report an error if it times out.
365     *            If zero, no blocking or checking is performed.
366     * @return Error Code generated by function. 0 indicates no error.
367     */
368    public ErrorCode configIntegratedSensorOffset(double offsetDegrees, int timeoutMs)
369    {
370        return ErrorCode.valueOf(MotControllerJNI.ConfigIntegratedSensorOffset(getHandle(), offsetDegrees, timeoutMs));
371    }
372    /**
373     * Adjusts the zero point for the integrated sensor absolute position register.
374     * The absolute position of the sensor will always have a discontinuity (360 -> 0 deg) or (+180 -> -180)
375     * and a hard-limited mechanism may have such a discontinuity in its functional range.
376     * In which case use this config to move the discontinuity outside of the function range.
377     * @param offsetDegrees
378     *            Offset in degrees
379     * @return Error Code generated by function. 0 indicates no error.
380     */
381    public ErrorCode configIntegratedSensorOffset(double offsetDegrees)
382    {
383        int timeoutMs = 0;
384        return configIntegratedSensorOffset(offsetDegrees, timeoutMs);
385    }
386    /**
387     * Pick the strategy on how to initialize the integrated sensor register.  Depending on the mechanism,
388     * it may be desirable to auto set the Position register to match the Absolute Position (swerve for example).
389     * Or it may be desired to zero the sensor on boot (drivetrain translation sensor or a relative servo).
390     *
391     * TIP: Tuner's self-test feature will report what the boot sensor value will be in the event the product is reset.
392     *
393     * @param initializationStrategy
394     *            The sensor initialization strategy to use.  This will impact the behavior the next time product boots up.
395     * @param timeoutMs
396     *            Timeout value in ms. If nonzero, function will wait for
397     *            config success and report an error if it times out.
398     *            If zero, no blocking or checking is performed.
399     * @return Error Code generated by function. 0 indicates no error.
400     */
401    public ErrorCode configIntegratedSensorInitializationStrategy(SensorInitializationStrategy initializationStrategy, int timeoutMs)
402    {
403        return ErrorCode.valueOf(MotControllerJNI.ConfigIntegratedSensorInitializationStrategy(getHandle(), initializationStrategy.value, timeoutMs));
404    }
405    /**
406     * Pick the strategy on how to initialize the integrated sensor register.  Depending on the mechanism,
407     * it may be desirable to auto set the Position register to match the Absolute Position (swerve for example).
408     * Or it may be desired to zero the sensor on boot (drivetrain translation sensor or a relative servo).
409     *
410     * TIP: Tuner's self-test feature will report what the boot sensor value will be in the event the product is reset.
411     *
412     * @param initializationStrategy
413     *            The sensor initialization strategy to use.  This will impact the behavior the next time product boots up.
414     * @return Error Code generated by function. 0 indicates no error.
415     */
416    public ErrorCode configIntegratedSensorInitializationStrategy(SensorInitializationStrategy initializationStrategy)
417    {
418        int timeoutMs = 0;
419        return configIntegratedSensorInitializationStrategy(initializationStrategy, timeoutMs);
420    }
421
422    /**
423     * @return object that can get/set individual raw sensor values.
424     */
425    public TalonFXSensorCollection getSensorCollection() {
426        return super.getTalonFXSensorCollection();
427    }
428
429        /**
430         * @return object that can get/set simulation inputs.
431         */
432        public TalonFXSimCollection getSimCollection() {
433                return super.getTalonFXSimCollection();
434        }
435
436   /**
437     * Configures all PID set persistent settings (overloaded so timeoutMs is 50 ms
438     * and pidIdx is 0).
439     *
440         * @param pid               Object with all of the PID set persistant settings
441         * @param pidIdx            0 for Primary closed-loop. 1 for auxiliary closed-loop.
442     * @param timeoutMs
443     *              Timeout value in ms. If nonzero, function will wait for
444     *              config success and report an error if it times out.
445     *              If zero, no blocking or checking is performed.
446     *
447     * @return Error Code generated by function. 0 indicates no error.
448     */
449        protected ErrorCode configurePID(TalonFXPIDSetConfiguration pid, int pidIdx, int timeoutMs) {
450        return super.configurePID(pid, pidIdx, timeoutMs, false);
451        }
452    /**
453     * Configures all PID set persistent settings (overloaded so timeoutMs is 50 ms
454     * and pidIdx is 0).
455     *
456         * @param pid               Object with all of the PID set persistant settings
457     *
458     * @return Error Code generated by function. 0 indicates no error.
459     */
460        protected ErrorCode configurePID(TalonFXPIDSetConfiguration pid) {
461        return super.configurePID(pid);
462    }
463
464    /**
465     * Gets all PID set persistant settings.
466     *
467         * @param pid               Object with all of the PID set persistant settings
468         * @param pidIdx            0 for Primary closed-loop. 1 for auxiliary closed-loop.
469     * @param timeoutMs
470     *              Timeout value in ms. If nonzero, function will wait for
471     *              config success and report an error if it times out.
472     *              If zero, no blocking or checking is performed.
473     */
474    public void getPIDConfigs(TalonFXPIDSetConfiguration pid, int pidIdx, int timeoutMs){
475        super.getPIDConfigs(pid, pidIdx, timeoutMs);
476    }
477    /**
478     * Gets all PID set persistant settings (overloaded so timeoutMs is 50 ms
479     * and pidIdx is 0).
480     *
481         * @param pid               Object with all of the PID set persistant settings
482     */
483        public void getPIDConfigs(TalonFXPIDSetConfiguration pid) {
484        int pidIdx = 0;
485        int timeoutMs = 50;
486        getPIDConfigs(pid, pidIdx, timeoutMs);
487    }
488
489    /**
490     * Configures all persistent settings.
491     *
492     * @param allConfigs        Object with all of the persistant settings
493     * @param timeoutMs
494     *              Timeout value in ms. If nonzero, function will wait for
495     *              config success and report an error if it times out.
496     *              If zero, no blocking or checking is performed.
497     *
498     * @return Error Code generated by function. 0 indicates no error.
499     */
500    public ErrorCode configAllSettings(TalonFXConfiguration allConfigs, int timeoutMs)
501    {
502        ErrorCollection ec = new ErrorCollection();
503
504        ec.NewError(super.configAllSettings(allConfigs, timeoutMs));
505
506        if (TalonFXConfigUtil.SupplyCurrentLimitDifferent(allConfigs))
507        {
508            double[] doubles = allConfigs.supplyCurrLimit.toArray();
509            ec.NewError(MotControllerJNI.ConfigSupplyCurrentLimit(getHandle(), doubles, timeoutMs));
510        }
511        if (TalonFXConfigUtil.StatorCurrentDurationDifferent(allConfigs))
512        {
513            double[] doubles = allConfigs.statorCurrLimit.toArray();
514            ec.NewError(MotControllerJNI.ConfigStatorCurrentLimit(getHandle(), doubles, timeoutMs));
515        }
516        if (TalonFXConfigUtil.MotorCommutationDifferent(allConfigs))
517        {
518            ec.NewError(configMotorCommutation(allConfigs.motorCommutation, timeoutMs));
519        }
520        if (TalonFXConfigUtil.AbsoluteSensorRangeDifferent(allConfigs))
521        {
522            ec.NewError(configIntegratedSensorAbsoluteRange(allConfigs.absoluteSensorRange, timeoutMs));
523        }
524        if (TalonFXConfigUtil.IntegratedSensorOffsetDegreesDifferent(allConfigs))
525        {
526            ec.NewError(configIntegratedSensorOffset(allConfigs.integratedSensorOffsetDegrees, timeoutMs));
527        }
528        if (TalonFXConfigUtil.InitializationStrategyDifferent(allConfigs))
529        {
530            ec.NewError(configIntegratedSensorInitializationStrategy(allConfigs.initializationStrategy, timeoutMs));
531        }
532
533        return ec._worstError;
534    }
535    /**
536     * Configures all persistent settings.
537     *
538     * @param allConfigs        Object with all of the persistant settings
539     *
540     * @return Error Code generated by function. 0 indicates no error.
541     */
542    public ErrorCode configAllSettings(TalonFXConfiguration allConfigs)
543    {
544        int timeoutMs = 50;
545        return configAllSettings(allConfigs, timeoutMs);
546    }
547    /**
548     * Gets all persistant settings.
549     *
550     * @param allConfigs        Object with all of the persistant settings
551     * @param timeoutMs
552     *              Timeout value in ms. If nonzero, function will wait for
553     *              config success and report an error if it times out.
554     *              If zero, no blocking or checking is performed.
555     *
556     * @return Error Code generated by function. 0 indicates no error.
557     */
558    public ErrorCode getAllConfigs(TalonFXConfiguration allConfigs, int timeoutMs)
559    {
560        ErrorCollection ec = new ErrorCollection();
561
562        super.getAllConfigs(allConfigs, timeoutMs);
563        ec.NewError(configGetSupplyCurrentLimit(allConfigs.supplyCurrLimit, timeoutMs));
564        ec.NewError(configGetStatorCurrentLimit(allConfigs.statorCurrLimit, timeoutMs));
565        allConfigs.motorCommutation = configGetMotorCommutation(timeoutMs);
566        ec.NewError(getLastError());
567        allConfigs.absoluteSensorRange = AbsoluteSensorRange.valueOf((int)configGetParameter(ParamEnum.eAbsSensorRange, 0, timeoutMs));
568        ec.NewError(getLastError());
569        allConfigs.integratedSensorOffsetDegrees = configGetParameter(ParamEnum.eMagnetOffset, 0, timeoutMs);
570        ec.NewError(getLastError());
571        allConfigs.initializationStrategy = SensorInitializationStrategy.valueOf((int)configGetParameter(ParamEnum.eSensorInitStrategy, 0, timeoutMs));
572        ec.NewError(getLastError());
573
574        return ec._worstError;
575    }
576    /**
577     * Gets all persistant settings (overloaded so timeoutMs is 50 ms).
578     *
579         * @param allConfigs        Object with all of the persistant settings
580     *
581     * @return Error Code generated by function. 0 indicates no error.
582     */
583    public ErrorCode getAllConfigs(TalonFXConfiguration allConfigs) {
584        int timeoutMs = 50;
585        return getAllConfigs(allConfigs, timeoutMs);
586    }
587}