001/*
002 * Copyright (C) Cross The Road Electronics.  All rights reserved.
003 * License information can be found in CTRE_LICENSE.txt
004 * For support and suggestions contact support@ctr-electronics.com or file
005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
006 */
007package com.ctre.phoenixpro.configs;
008
009import com.ctre.phoenixpro.StatusCode;
010
011/**
012 * Class description for the Talon FX integrated motor controller that runs on
013 * associated Falcon motors.
014 *
015 * This handles the configurations for the {@link com.ctre.phoenixpro.hardware.TalonFX}
016 */
017public class TalonFXConfiguration implements ParentConfiguration
018{
019    /**
020     * True if we should factory default newer unsupported configs,
021     * false to leave newer unsupported configs alone.
022     * <p>
023     * This flag addresses a corner case where the device may have
024     * firmware with newer configs that didn't exist when this
025     * version of the API was built. If this occurs and this
026     * flag is true, unsupported new configs will be factory
027     * defaulted to avoid unexpected behavior.
028     * <p>
029     * This is also the behavior in Phoenix 5, so this flag
030     * is defaulted to true to match.
031     */
032    public boolean FutureProofConfigs = true;
033
034    
035    /**
036     *  What the gains for slot 0 are
037     * <p>
038     *  If this slot is selected, these gains are used in closed loop
039     *  control requests.
040     */
041    public Slot0Configs Slot0 = new Slot0Configs();
042    
043    /**
044     *  What the gains for slot 1 are
045     * <p>
046     *  If this slot is selected, these gains are used in closed loop
047     *  control requests.
048     */
049    public Slot1Configs Slot1 = new Slot1Configs();
050    
051    /**
052     *  What the gains for slot 2 are
053     * <p>
054     *  If this slot is selected, these gains are used in closed loop
055     *  control requests.
056     */
057    public Slot2Configs Slot2 = new Slot2Configs();
058    
059    /**
060     *  Configs that directly affect motor-output.
061     * <p>
062     *  Includes Motor Invert and various limit features.
063     */
064    public MotorOutputConfigs MotorOutput = new MotorOutputConfigs();
065    
066    /**
067     *  Configs that directly affect current limiting features.
068     * <p>
069     *  Includes Motor Invert and various limit features.
070     */
071    public CurrentLimitsConfigs CurrentLimits = new CurrentLimitsConfigs();
072    
073    /**
074     *  Voltage-specific configs
075     * <p>
076     *  Voltage-specific configs
077     */
078    public VoltageConfigs Voltage = new VoltageConfigs();
079    
080    /**
081     *  Configs that directly affect motor-output.
082     * <p>
083     *  Includes Motor Invert and various limit features.
084     */
085    public TorqueCurrentConfigs TorqueCurrent = new TorqueCurrentConfigs();
086    
087    /**
088     *  Configs that directly affect motor-output.
089     * <p>
090     *  Includes Motor Invert and various limit features.
091     */
092    public FeedbackConfigs Feedback = new FeedbackConfigs();
093    
094    /**
095     *  Configs that directly affect motor-output.
096     * <p>
097     *  Includes Motor Invert and various limit features.
098     */
099    public OpenLoopRampsConfigs OpenLoopRamps = new OpenLoopRampsConfigs();
100    
101    /**
102     *  Configs that directly affect motor-output.
103     * <p>
104     *  Includes Motor Invert and various limit features.
105     */
106    public ClosedLoopRampsConfigs ClosedLoopRamps = new ClosedLoopRampsConfigs();
107    
108    /**
109     *  Configs that directly affect motor-output.
110     * <p>
111     *  Includes Motor Invert and various limit features.
112     */
113    public HardwareLimitSwitchConfigs HardwareLimitSwitch = new HardwareLimitSwitchConfigs();
114    
115    /**
116     *  Configs that directly affect motor-output.
117     * <p>
118     *  Includes Motor Invert and various limit features.
119     */
120    public AudioConfigs Audio = new AudioConfigs();
121    
122    /**
123     *  Configs that directly affect motor-output.
124     * <p>
125     *  Includes Motor Invert and various limit features.
126     */
127    public SoftwareLimitSwitchConfigs SoftwareLimitSwitch = new SoftwareLimitSwitchConfigs();
128    
129    /**
130     *  Configs that directly affect motor-output.
131     * <p>
132     *  Includes Motor Invert and various limit features.
133     */
134    public MotionMagicConfigs MotionMagic = new MotionMagicConfigs();
135    
136    /**
137     *  Configs that directly affect motor-output.
138     * <p>
139     *  Includes Motor Invert and various limit features.
140     */
141    public CustomParamsConfigs CustomParams = new CustomParamsConfigs();
142    
143    /**
144     *  Configs that affect general behavior during closed-looping.
145     * <p>
146     *  Includes Continuous Wrap features.
147     */
148    public ClosedLoopGeneralConfigs ClosedLoopGeneral = new ClosedLoopGeneralConfigs();
149
150    @Override
151    public String toString()
152    {
153        String ss = "";
154        ss += Slot0.toString();
155        ss += Slot1.toString();
156        ss += Slot2.toString();
157        ss += MotorOutput.toString();
158        ss += CurrentLimits.toString();
159        ss += Voltage.toString();
160        ss += TorqueCurrent.toString();
161        ss += Feedback.toString();
162        ss += OpenLoopRamps.toString();
163        ss += ClosedLoopRamps.toString();
164        ss += HardwareLimitSwitch.toString();
165        ss += Audio.toString();
166        ss += SoftwareLimitSwitch.toString();
167        ss += MotionMagic.toString();
168        ss += CustomParams.toString();
169        ss += ClosedLoopGeneral.toString();
170        return ss;
171    }
172
173    /**
174     * Get the serialized form of this configuration
175     *
176     * @return Serialized form of this config group
177     */
178    public String serialize()
179    {
180        String ss = "";
181        ss += Slot0.serialize();
182        ss += Slot1.serialize();
183        ss += Slot2.serialize();
184        ss += MotorOutput.serialize();
185        ss += CurrentLimits.serialize();
186        ss += Voltage.serialize();
187        ss += TorqueCurrent.serialize();
188        ss += Feedback.serialize();
189        ss += OpenLoopRamps.serialize();
190        ss += ClosedLoopRamps.serialize();
191        ss += HardwareLimitSwitch.serialize();
192        ss += Audio.serialize();
193        ss += SoftwareLimitSwitch.serialize();
194        ss += MotionMagic.serialize();
195        ss += CustomParams.serialize();
196        ss += ClosedLoopGeneral.serialize();
197        return ss;
198    }
199
200    /**
201     * Take a string and deserialize it to this configuration
202     *
203     * @return Return code of the deserialize method
204     */
205    public StatusCode deserialize(String string)
206    {
207        StatusCode err = StatusCode.OK;
208        err = Slot0.deserialize(string);
209        err = Slot1.deserialize(string);
210        err = Slot2.deserialize(string);
211        err = MotorOutput.deserialize(string);
212        err = CurrentLimits.deserialize(string);
213        err = Voltage.deserialize(string);
214        err = TorqueCurrent.deserialize(string);
215        err = Feedback.deserialize(string);
216        err = OpenLoopRamps.deserialize(string);
217        err = ClosedLoopRamps.deserialize(string);
218        err = HardwareLimitSwitch.deserialize(string);
219        err = Audio.deserialize(string);
220        err = SoftwareLimitSwitch.deserialize(string);
221        err = MotionMagic.deserialize(string);
222        err = CustomParams.deserialize(string);
223        err = ClosedLoopGeneral.deserialize(string);
224        return err;
225    }
226};