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