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 Voltage control types.
020 * <p>
021 * Includes peak output voltages and other configs affecting voltage
022 * measurements.
023 */
024public class VoltageConfigs implements ParentConfiguration
025{
026    /**
027     * The time constant (in seconds) of the low-pass filter for the
028     * supply voltage.
029     * <p>
030     * This impacts the filtering for the reported supply voltage, and any
031     * control strategies that use the supply voltage (such as voltage
032     * control on a motor controller).
033     * 
034     * <ul>
035     *   <li> <b>Minimum Value:</b> 0.0
036     *   <li> <b>Maximum Value:</b> 0.1
037     *   <li> <b>Default Value:</b> 0
038     *   <li> <b>Units:</b> seconds
039     * </ul>
040     */
041    public double SupplyVoltageTimeConstant = 0;
042    /**
043     * Maximum (forward) output during voltage based control modes.
044     * 
045     * <ul>
046     *   <li> <b>Minimum Value:</b> -16
047     *   <li> <b>Maximum Value:</b> 16
048     *   <li> <b>Default Value:</b> 16
049     *   <li> <b>Units:</b> V
050     * </ul>
051     */
052    public double PeakForwardVoltage = 16;
053    /**
054     * Minimum (reverse) output during voltage based control modes.
055     * 
056     * <ul>
057     *   <li> <b>Minimum Value:</b> -16
058     *   <li> <b>Maximum Value:</b> 16
059     *   <li> <b>Default Value:</b> -16
060     *   <li> <b>Units:</b> V
061     * </ul>
062     */
063    public double PeakReverseVoltage = -16;
064    
065    /**
066     * Modifies this configuration's SupplyVoltageTimeConstant parameter and returns itself for
067     * method-chaining and easier to use config API.
068     * <p>
069     * The time constant (in seconds) of the low-pass filter for the
070     * supply voltage.
071     * <p>
072     * This impacts the filtering for the reported supply voltage, and any
073     * control strategies that use the supply voltage (such as voltage
074     * control on a motor controller).
075     * 
076     * <ul>
077     *   <li> <b>Minimum Value:</b> 0.0
078     *   <li> <b>Maximum Value:</b> 0.1
079     *   <li> <b>Default Value:</b> 0
080     *   <li> <b>Units:</b> seconds
081     * </ul>
082     *
083     * @param newSupplyVoltageTimeConstant Parameter to modify
084     * @return Itself
085     */
086    public VoltageConfigs withSupplyVoltageTimeConstant(double newSupplyVoltageTimeConstant)
087    {
088        SupplyVoltageTimeConstant = newSupplyVoltageTimeConstant;
089        return this;
090    }
091    
092    /**
093     * Modifies this configuration's SupplyVoltageTimeConstant parameter and returns itself for
094     * method-chaining and easier to use config API.
095     * <p>
096     * The time constant (in seconds) of the low-pass filter for the
097     * supply voltage.
098     * <p>
099     * This impacts the filtering for the reported supply voltage, and any
100     * control strategies that use the supply voltage (such as voltage
101     * control on a motor controller).
102     * 
103     * <ul>
104     *   <li> <b>Minimum Value:</b> 0.0
105     *   <li> <b>Maximum Value:</b> 0.1
106     *   <li> <b>Default Value:</b> 0
107     *   <li> <b>Units:</b> seconds
108     * </ul>
109     *
110     * @param newSupplyVoltageTimeConstant Parameter to modify
111     * @return Itself
112     */
113    public VoltageConfigs withSupplyVoltageTimeConstant(Time newSupplyVoltageTimeConstant)
114    {
115        SupplyVoltageTimeConstant = newSupplyVoltageTimeConstant.in(Seconds);
116        return this;
117    }
118    
119    /**
120     * Helper method to get this configuration's SupplyVoltageTimeConstant parameter converted
121     * to a unit type. If not using the Java units library, {@link #SupplyVoltageTimeConstant}
122     * can be accessed directly instead.
123     * <p>
124     * The time constant (in seconds) of the low-pass filter for the
125     * supply voltage.
126     * <p>
127     * This impacts the filtering for the reported supply voltage, and any
128     * control strategies that use the supply voltage (such as voltage
129     * control on a motor controller).
130     * 
131     * <ul>
132     *   <li> <b>Minimum Value:</b> 0.0
133     *   <li> <b>Maximum Value:</b> 0.1
134     *   <li> <b>Default Value:</b> 0
135     *   <li> <b>Units:</b> seconds
136     * </ul>
137     *
138     * @return SupplyVoltageTimeConstant
139     */
140    public Time getSupplyVoltageTimeConstantMeasure()
141    {
142        return Seconds.of(SupplyVoltageTimeConstant);
143    }
144    
145    /**
146     * Modifies this configuration's PeakForwardVoltage parameter and returns itself for
147     * method-chaining and easier to use config API.
148     * <p>
149     * Maximum (forward) output during voltage based control modes.
150     * 
151     * <ul>
152     *   <li> <b>Minimum Value:</b> -16
153     *   <li> <b>Maximum Value:</b> 16
154     *   <li> <b>Default Value:</b> 16
155     *   <li> <b>Units:</b> V
156     * </ul>
157     *
158     * @param newPeakForwardVoltage Parameter to modify
159     * @return Itself
160     */
161    public VoltageConfigs withPeakForwardVoltage(double newPeakForwardVoltage)
162    {
163        PeakForwardVoltage = newPeakForwardVoltage;
164        return this;
165    }
166    
167    /**
168     * Modifies this configuration's PeakForwardVoltage parameter and returns itself for
169     * method-chaining and easier to use config API.
170     * <p>
171     * Maximum (forward) output during voltage based control modes.
172     * 
173     * <ul>
174     *   <li> <b>Minimum Value:</b> -16
175     *   <li> <b>Maximum Value:</b> 16
176     *   <li> <b>Default Value:</b> 16
177     *   <li> <b>Units:</b> V
178     * </ul>
179     *
180     * @param newPeakForwardVoltage Parameter to modify
181     * @return Itself
182     */
183    public VoltageConfigs withPeakForwardVoltage(Voltage newPeakForwardVoltage)
184    {
185        PeakForwardVoltage = newPeakForwardVoltage.in(Volts);
186        return this;
187    }
188    
189    /**
190     * Helper method to get this configuration's PeakForwardVoltage parameter converted
191     * to a unit type. If not using the Java units library, {@link #PeakForwardVoltage}
192     * can be accessed directly instead.
193     * <p>
194     * Maximum (forward) output during voltage based control modes.
195     * 
196     * <ul>
197     *   <li> <b>Minimum Value:</b> -16
198     *   <li> <b>Maximum Value:</b> 16
199     *   <li> <b>Default Value:</b> 16
200     *   <li> <b>Units:</b> V
201     * </ul>
202     *
203     * @return PeakForwardVoltage
204     */
205    public Voltage getPeakForwardVoltageMeasure()
206    {
207        return Volts.of(PeakForwardVoltage);
208    }
209    
210    /**
211     * Modifies this configuration's PeakReverseVoltage parameter and returns itself for
212     * method-chaining and easier to use config API.
213     * <p>
214     * Minimum (reverse) output during voltage based control modes.
215     * 
216     * <ul>
217     *   <li> <b>Minimum Value:</b> -16
218     *   <li> <b>Maximum Value:</b> 16
219     *   <li> <b>Default Value:</b> -16
220     *   <li> <b>Units:</b> V
221     * </ul>
222     *
223     * @param newPeakReverseVoltage Parameter to modify
224     * @return Itself
225     */
226    public VoltageConfigs withPeakReverseVoltage(double newPeakReverseVoltage)
227    {
228        PeakReverseVoltage = newPeakReverseVoltage;
229        return this;
230    }
231    
232    /**
233     * Modifies this configuration's PeakReverseVoltage parameter and returns itself for
234     * method-chaining and easier to use config API.
235     * <p>
236     * Minimum (reverse) output during voltage based control modes.
237     * 
238     * <ul>
239     *   <li> <b>Minimum Value:</b> -16
240     *   <li> <b>Maximum Value:</b> 16
241     *   <li> <b>Default Value:</b> -16
242     *   <li> <b>Units:</b> V
243     * </ul>
244     *
245     * @param newPeakReverseVoltage Parameter to modify
246     * @return Itself
247     */
248    public VoltageConfigs withPeakReverseVoltage(Voltage newPeakReverseVoltage)
249    {
250        PeakReverseVoltage = newPeakReverseVoltage.in(Volts);
251        return this;
252    }
253    
254    /**
255     * Helper method to get this configuration's PeakReverseVoltage parameter converted
256     * to a unit type. If not using the Java units library, {@link #PeakReverseVoltage}
257     * can be accessed directly instead.
258     * <p>
259     * Minimum (reverse) output during voltage based control modes.
260     * 
261     * <ul>
262     *   <li> <b>Minimum Value:</b> -16
263     *   <li> <b>Maximum Value:</b> 16
264     *   <li> <b>Default Value:</b> -16
265     *   <li> <b>Units:</b> V
266     * </ul>
267     *
268     * @return PeakReverseVoltage
269     */
270    public Voltage getPeakReverseVoltageMeasure()
271    {
272        return Volts.of(PeakReverseVoltage);
273    }
274
275    
276
277    @Override
278    public String toString()
279    {
280        String ss = "Config Group: Voltage\n";
281        ss += "    SupplyVoltageTimeConstant: " + SupplyVoltageTimeConstant + " seconds" + "\n";
282        ss += "    PeakForwardVoltage: " + PeakForwardVoltage + " V" + "\n";
283        ss += "    PeakReverseVoltage: " + PeakReverseVoltage + " V" + "\n";
284        return ss;
285    }
286
287    /**
288     *
289     */
290    public StatusCode deserialize(String to_deserialize)
291    {
292        SupplyVoltageTimeConstant = ConfigJNI.Deserializedouble(SpnValue.Config_SupplyVLowpassTau.value, to_deserialize);
293        PeakForwardVoltage = ConfigJNI.Deserializedouble(SpnValue.Config_PeakForwardV.value, to_deserialize);
294        PeakReverseVoltage = ConfigJNI.Deserializedouble(SpnValue.Config_PeakReverseV.value, to_deserialize);
295        return  StatusCode.OK;
296    }
297
298    /**
299     *
300     */
301    public String serialize()
302    {
303        String ss = "";
304        ss += ConfigJNI.Serializedouble(SpnValue.Config_SupplyVLowpassTau.value, SupplyVoltageTimeConstant);
305        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakForwardV.value, PeakForwardVoltage);
306        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakReverseV.value, PeakReverseVoltage);
307        return ss;
308    }
309}
310