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
013/**
014 * Configs that affect Voltage control types.
015 * <p>
016 * Includes peak output voltages and other configs affecting voltage
017 * measurements.
018 */
019public class VoltageConfigs implements ParentConfiguration
020{
021    /**
022     * The time constant (in seconds) of the low-pass filter for the
023     * supply voltage.
024     * <p>
025     * This impacts the filtering for the reported supply voltage, and any
026     * control strategies that use the supply voltage (such as voltage
027     * control on a motor controller).
028     * 
029     * <ul>
030     *   <li> <b>Minimum Value:</b> 0.0
031     *   <li> <b>Maximum Value:</b> 0.1
032     *   <li> <b>Default Value:</b> 0
033     *   <li> <b>Units:</b> sec
034     * </ul>
035     */
036    public double SupplyVoltageTimeConstant = 0;
037    /**
038     * Maximum (forward) output during voltage based control modes.
039     * 
040     * <ul>
041     *   <li> <b>Minimum Value:</b> -16
042     *   <li> <b>Maximum Value:</b> 16
043     *   <li> <b>Default Value:</b> 16
044     *   <li> <b>Units:</b> V
045     * </ul>
046     */
047    public double PeakForwardVoltage = 16;
048    /**
049     * Minimum (reverse) output during voltage based control modes.
050     * 
051     * <ul>
052     *   <li> <b>Minimum Value:</b> -16
053     *   <li> <b>Maximum Value:</b> 16
054     *   <li> <b>Default Value:</b> -16
055     *   <li> <b>Units:</b> V
056     * </ul>
057     */
058    public double PeakReverseVoltage = -16;
059    
060    /**
061     * Modifies this configuration's SupplyVoltageTimeConstant parameter and returns itself for
062     * method-chaining and easier to use config API.
063     * <p>
064     * The time constant (in seconds) of the low-pass filter for the
065     * supply voltage.
066     * <p>
067     * This impacts the filtering for the reported supply voltage, and any
068     * control strategies that use the supply voltage (such as voltage
069     * control on a motor controller).
070     * 
071     * <ul>
072     *   <li> <b>Minimum Value:</b> 0.0
073     *   <li> <b>Maximum Value:</b> 0.1
074     *   <li> <b>Default Value:</b> 0
075     *   <li> <b>Units:</b> sec
076     * </ul>
077     *
078     * @param newSupplyVoltageTimeConstant Parameter to modify
079     * @return Itself
080     */
081    public VoltageConfigs withSupplyVoltageTimeConstant(double newSupplyVoltageTimeConstant)
082    {
083        SupplyVoltageTimeConstant = newSupplyVoltageTimeConstant;
084        return this;
085    }
086    /**
087     * Modifies this configuration's PeakForwardVoltage parameter and returns itself for
088     * method-chaining and easier to use config API.
089     * <p>
090     * Maximum (forward) output during voltage based control modes.
091     * 
092     * <ul>
093     *   <li> <b>Minimum Value:</b> -16
094     *   <li> <b>Maximum Value:</b> 16
095     *   <li> <b>Default Value:</b> 16
096     *   <li> <b>Units:</b> V
097     * </ul>
098     *
099     * @param newPeakForwardVoltage Parameter to modify
100     * @return Itself
101     */
102    public VoltageConfigs withPeakForwardVoltage(double newPeakForwardVoltage)
103    {
104        PeakForwardVoltage = newPeakForwardVoltage;
105        return this;
106    }
107    /**
108     * Modifies this configuration's PeakReverseVoltage parameter and returns itself for
109     * method-chaining and easier to use config API.
110     * <p>
111     * Minimum (reverse) output during voltage based control modes.
112     * 
113     * <ul>
114     *   <li> <b>Minimum Value:</b> -16
115     *   <li> <b>Maximum Value:</b> 16
116     *   <li> <b>Default Value:</b> -16
117     *   <li> <b>Units:</b> V
118     * </ul>
119     *
120     * @param newPeakReverseVoltage Parameter to modify
121     * @return Itself
122     */
123    public VoltageConfigs withPeakReverseVoltage(double newPeakReverseVoltage)
124    {
125        PeakReverseVoltage = newPeakReverseVoltage;
126        return this;
127    }
128
129    
130
131    @Override
132    public String toString()
133    {
134        String ss = "Config Group: Voltage\n";
135        ss += "Name: \"SupplyVoltageTimeConstant\" Value: \"" + SupplyVoltageTimeConstant + "sec\"" + "\n";
136        ss += "Name: \"PeakForwardVoltage\" Value: \"" + PeakForwardVoltage + "V\"" + "\n";
137        ss += "Name: \"PeakReverseVoltage\" Value: \"" + PeakReverseVoltage + "V\"" + "\n";
138        return ss;
139    }
140
141    /**
142     *
143     */
144    public StatusCode deserialize(String to_deserialize)
145    {
146        SupplyVoltageTimeConstant = ConfigJNI.Deserializedouble(SpnValue.Config_SupplyVLowpassTau.value, to_deserialize);
147        PeakForwardVoltage = ConfigJNI.Deserializedouble(SpnValue.Config_PeakForwardV.value, to_deserialize);
148        PeakReverseVoltage = ConfigJNI.Deserializedouble(SpnValue.Config_PeakReverseV.value, to_deserialize);
149        return  StatusCode.OK;
150    }
151
152    /**
153     *
154     */
155    public String serialize()
156    {
157        String ss = "";
158        ss += ConfigJNI.Serializedouble(SpnValue.Config_SupplyVLowpassTau.value, SupplyVoltageTimeConstant);
159        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakForwardV.value, PeakForwardVoltage);
160        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakReverseV.value, PeakReverseVoltage);
161        return ss;
162    }
163}
164