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.phoenix6.configs;
008
009import com.ctre.phoenix6.StatusCode;
010import com.ctre.phoenix6.configs.jni.ConfigJNI;
011import com.ctre.phoenix6.spns.*;
012
013import edu.wpi.first.units.*;
014
015import edu.wpi.first.units.measure.*;
016import static edu.wpi.first.units.Units.*;
017
018/**
019 * Configs that affect Torque Current control types.
020 * <p>
021 * Includes the maximum and minimum applied torque output and the
022 * neutral deadband used during TorqueCurrentFOC requests.
023 */
024public class TorqueCurrentConfigs implements ParentConfiguration
025{
026    /**
027     * Maximum (forward) output during torque current based control modes.
028     * 
029     * <ul>
030     *   <li> <b>Minimum Value:</b> -800
031     *   <li> <b>Maximum Value:</b> 800
032     *   <li> <b>Default Value:</b> 800
033     *   <li> <b>Units:</b> A
034     * </ul>
035     */
036    public double PeakForwardTorqueCurrent = 800;
037    /**
038     * Minimum (reverse) output during torque current based control modes.
039     * 
040     * <ul>
041     *   <li> <b>Minimum Value:</b> -800
042     *   <li> <b>Maximum Value:</b> 800
043     *   <li> <b>Default Value:</b> -800
044     *   <li> <b>Units:</b> A
045     * </ul>
046     */
047    public double PeakReverseTorqueCurrent = -800;
048    /**
049     * Configures the output deadband during torque current based control
050     * modes.
051     * 
052     * <ul>
053     *   <li> <b>Minimum Value:</b> 0
054     *   <li> <b>Maximum Value:</b> 25
055     *   <li> <b>Default Value:</b> 0.0
056     *   <li> <b>Units:</b> A
057     * </ul>
058     */
059    public double TorqueNeutralDeadband = 0.0;
060    
061    /**
062     * Modifies this configuration's PeakForwardTorqueCurrent parameter and returns itself for
063     * method-chaining and easier to use config API.
064     * <p>
065     * Maximum (forward) output during torque current based control modes.
066     * 
067     * <ul>
068     *   <li> <b>Minimum Value:</b> -800
069     *   <li> <b>Maximum Value:</b> 800
070     *   <li> <b>Default Value:</b> 800
071     *   <li> <b>Units:</b> A
072     * </ul>
073     *
074     * @param newPeakForwardTorqueCurrent Parameter to modify
075     * @return Itself
076     */
077    public TorqueCurrentConfigs withPeakForwardTorqueCurrent(double newPeakForwardTorqueCurrent)
078    {
079        PeakForwardTorqueCurrent = newPeakForwardTorqueCurrent;
080        return this;
081    }
082    
083    /**
084     * Modifies this configuration's PeakForwardTorqueCurrent parameter and returns itself for
085     * method-chaining and easier to use config API.
086     * <p>
087     * Maximum (forward) output during torque current based control modes.
088     * 
089     * <ul>
090     *   <li> <b>Minimum Value:</b> -800
091     *   <li> <b>Maximum Value:</b> 800
092     *   <li> <b>Default Value:</b> 800
093     *   <li> <b>Units:</b> A
094     * </ul>
095     *
096     * @param newPeakForwardTorqueCurrent Parameter to modify
097     * @return Itself
098     */
099    public TorqueCurrentConfigs withPeakForwardTorqueCurrent(Current newPeakForwardTorqueCurrent)
100    {
101        PeakForwardTorqueCurrent = newPeakForwardTorqueCurrent.in(Amps);
102        return this;
103    }
104    
105    /**
106     * Helper method to get this configuration's PeakForwardTorqueCurrent parameter converted
107     * to a unit type. If not using the Java units library, {@link #PeakForwardTorqueCurrent}
108     * can be accessed directly instead.
109     * <p>
110     * Maximum (forward) output during torque current based control modes.
111     * 
112     * <ul>
113     *   <li> <b>Minimum Value:</b> -800
114     *   <li> <b>Maximum Value:</b> 800
115     *   <li> <b>Default Value:</b> 800
116     *   <li> <b>Units:</b> A
117     * </ul>
118     *
119     * @return PeakForwardTorqueCurrent
120     */
121    public Current getPeakForwardTorqueCurrentMeasure()
122    {
123        return Amps.of(PeakForwardTorqueCurrent);
124    }
125    
126    /**
127     * Modifies this configuration's PeakReverseTorqueCurrent parameter and returns itself for
128     * method-chaining and easier to use config API.
129     * <p>
130     * Minimum (reverse) output during torque current based control modes.
131     * 
132     * <ul>
133     *   <li> <b>Minimum Value:</b> -800
134     *   <li> <b>Maximum Value:</b> 800
135     *   <li> <b>Default Value:</b> -800
136     *   <li> <b>Units:</b> A
137     * </ul>
138     *
139     * @param newPeakReverseTorqueCurrent Parameter to modify
140     * @return Itself
141     */
142    public TorqueCurrentConfigs withPeakReverseTorqueCurrent(double newPeakReverseTorqueCurrent)
143    {
144        PeakReverseTorqueCurrent = newPeakReverseTorqueCurrent;
145        return this;
146    }
147    
148    /**
149     * Modifies this configuration's PeakReverseTorqueCurrent parameter and returns itself for
150     * method-chaining and easier to use config API.
151     * <p>
152     * Minimum (reverse) output during torque current based control modes.
153     * 
154     * <ul>
155     *   <li> <b>Minimum Value:</b> -800
156     *   <li> <b>Maximum Value:</b> 800
157     *   <li> <b>Default Value:</b> -800
158     *   <li> <b>Units:</b> A
159     * </ul>
160     *
161     * @param newPeakReverseTorqueCurrent Parameter to modify
162     * @return Itself
163     */
164    public TorqueCurrentConfigs withPeakReverseTorqueCurrent(Current newPeakReverseTorqueCurrent)
165    {
166        PeakReverseTorqueCurrent = newPeakReverseTorqueCurrent.in(Amps);
167        return this;
168    }
169    
170    /**
171     * Helper method to get this configuration's PeakReverseTorqueCurrent parameter converted
172     * to a unit type. If not using the Java units library, {@link #PeakReverseTorqueCurrent}
173     * can be accessed directly instead.
174     * <p>
175     * Minimum (reverse) output during torque current based control modes.
176     * 
177     * <ul>
178     *   <li> <b>Minimum Value:</b> -800
179     *   <li> <b>Maximum Value:</b> 800
180     *   <li> <b>Default Value:</b> -800
181     *   <li> <b>Units:</b> A
182     * </ul>
183     *
184     * @return PeakReverseTorqueCurrent
185     */
186    public Current getPeakReverseTorqueCurrentMeasure()
187    {
188        return Amps.of(PeakReverseTorqueCurrent);
189    }
190    
191    /**
192     * Modifies this configuration's TorqueNeutralDeadband parameter and returns itself for
193     * method-chaining and easier to use config API.
194     * <p>
195     * Configures the output deadband during torque current based control
196     * modes.
197     * 
198     * <ul>
199     *   <li> <b>Minimum Value:</b> 0
200     *   <li> <b>Maximum Value:</b> 25
201     *   <li> <b>Default Value:</b> 0.0
202     *   <li> <b>Units:</b> A
203     * </ul>
204     *
205     * @param newTorqueNeutralDeadband Parameter to modify
206     * @return Itself
207     */
208    public TorqueCurrentConfigs withTorqueNeutralDeadband(double newTorqueNeutralDeadband)
209    {
210        TorqueNeutralDeadband = newTorqueNeutralDeadband;
211        return this;
212    }
213    
214    /**
215     * Modifies this configuration's TorqueNeutralDeadband parameter and returns itself for
216     * method-chaining and easier to use config API.
217     * <p>
218     * Configures the output deadband during torque current based control
219     * modes.
220     * 
221     * <ul>
222     *   <li> <b>Minimum Value:</b> 0
223     *   <li> <b>Maximum Value:</b> 25
224     *   <li> <b>Default Value:</b> 0.0
225     *   <li> <b>Units:</b> A
226     * </ul>
227     *
228     * @param newTorqueNeutralDeadband Parameter to modify
229     * @return Itself
230     */
231    public TorqueCurrentConfigs withTorqueNeutralDeadband(Current newTorqueNeutralDeadband)
232    {
233        TorqueNeutralDeadband = newTorqueNeutralDeadband.in(Amps);
234        return this;
235    }
236    
237    /**
238     * Helper method to get this configuration's TorqueNeutralDeadband parameter converted
239     * to a unit type. If not using the Java units library, {@link #TorqueNeutralDeadband}
240     * can be accessed directly instead.
241     * <p>
242     * Configures the output deadband during torque current based control
243     * modes.
244     * 
245     * <ul>
246     *   <li> <b>Minimum Value:</b> 0
247     *   <li> <b>Maximum Value:</b> 25
248     *   <li> <b>Default Value:</b> 0.0
249     *   <li> <b>Units:</b> A
250     * </ul>
251     *
252     * @return TorqueNeutralDeadband
253     */
254    public Current getTorqueNeutralDeadbandMeasure()
255    {
256        return Amps.of(TorqueNeutralDeadband);
257    }
258
259    
260
261    @Override
262    public String toString()
263    {
264        String ss = "Config Group: TorqueCurrent\n";
265        ss += "    PeakForwardTorqueCurrent: " + PeakForwardTorqueCurrent + " A" + "\n";
266        ss += "    PeakReverseTorqueCurrent: " + PeakReverseTorqueCurrent + " A" + "\n";
267        ss += "    TorqueNeutralDeadband: " + TorqueNeutralDeadband + " A" + "\n";
268        return ss;
269    }
270
271    /**
272     *
273     */
274    public StatusCode deserialize(String to_deserialize)
275    {
276        PeakForwardTorqueCurrent = ConfigJNI.Deserializedouble(SpnValue.Config_PeakForTorqCurr.value, to_deserialize);
277        PeakReverseTorqueCurrent = ConfigJNI.Deserializedouble(SpnValue.Config_PeakRevTorqCurr.value, to_deserialize);
278        TorqueNeutralDeadband = ConfigJNI.Deserializedouble(SpnValue.Config_TorqueNeutralDB.value, to_deserialize);
279        return  StatusCode.OK;
280    }
281
282    /**
283     *
284     */
285    public String serialize()
286    {
287        String ss = "";
288        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakForTorqCurr.value, PeakForwardTorqueCurrent);
289        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakRevTorqCurr.value, PeakReverseTorqueCurrent);
290        ss += ConfigJNI.Serializedouble(SpnValue.Config_TorqueNeutralDB.value, TorqueNeutralDeadband);
291        return ss;
292    }
293}
294