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.phoenix6.StatusCode;
010import com.ctre.phoenix6.configs.jni.ConfigJNI;
011import com.ctre.phoenix6.spns.*;
012
013/**
014 *  What the gains for slot 0 are
015 * <p>
016 *  If this slot is selected, these gains are used in closed loop
017 *  control requests.
018 *
019 * @deprecated Classes in the phoenixpro package will be removed in 2024.
020 *             Users should instead use classes from the phoenix6 package.
021 */
022@Deprecated(forRemoval = true)
023public class Slot0Configs implements ParentConfiguration
024{
025    /**
026     * Proportional Gain
027     * <p>
028     * The units for this gain is dependent on the control mode. Since
029     * this gain is multiplied by error in the input, the units should be
030     * defined as units of output per unit of input error. For example,
031     * when controlling velocity using a duty cycle closed loop, the units
032     * for the proportional gain will be duty cycle per rps of error, or
033     * 1/rps.
034     *
035     *  <ul>
036     *  <li> <b>Minimum Value:</b> 0
037     *  <li> <b>Maximum Value:</b> 3.4e+38
038     *  <li> <b>Default Value:</b> 0
039     *  <li> <b>Units:</b> 
040     *  </ul>
041     */
042    public double kP = 0;
043    /**
044     * Integral Gain
045     * <p>
046     * The units for this gain is dependent on the control mode. Since
047     * this gain is multiplied by error in the input integrated over time
048     * (in units of seconds), the units should be defined as units of
049     * output per unit of integrated input error. For example, when
050     * controlling velocity using a duty cycle closed loop, integrating
051     * velocity over time results in rps * s = rotations. Therefore, the
052     * units for the integral gain will be duty cycle per rotation of
053     * accumulated error, or 1/rot.
054     *
055     *  <ul>
056     *  <li> <b>Minimum Value:</b> 0
057     *  <li> <b>Maximum Value:</b> 3.4e+38
058     *  <li> <b>Default Value:</b> 0
059     *  <li> <b>Units:</b> 
060     *  </ul>
061     */
062    public double kI = 0;
063    /**
064     * Derivative Gain
065     * <p>
066     * The units for this gain is dependent on the control mode. Since
067     * this gain is multiplied by the derivative of error in the input
068     * with respect to time (in units of seconds), the units should be
069     * defined as units of output per unit of the differentiated input
070     * error. For example, when controlling velocity using a duty cycle
071     * closed loop, the derivative of velocity with respect to time is
072     * rps/s, which is acceleration. Therefore, the units for the
073     * derivative gain will be duty cycle per unit of acceleration error,
074     * or 1/(rps/s).
075     *
076     *  <ul>
077     *  <li> <b>Minimum Value:</b> 0
078     *  <li> <b>Maximum Value:</b> 3.4e+38
079     *  <li> <b>Default Value:</b> 0
080     *  <li> <b>Units:</b> 
081     *  </ul>
082     */
083    public double kD = 0;
084    /**
085     * Velocity Feed Forward Gain
086     * <p>
087     * The units for this gain is dependent on the control mode. Since
088     * this gain is multiplied by the requested velocity, the units should
089     * be defined as units of output per unit of requested input velocity.
090     * For example, when controlling velocity using a duty cycle closed
091     * loop, the units for the velocity feed foward gain will be duty
092     * cycle per requested rps, or 1/rps.
093     *
094     *  <ul>
095     *  <li> <b>Minimum Value:</b> 0
096     *  <li> <b>Maximum Value:</b> 3.4e+38
097     *  <li> <b>Default Value:</b> 0
098     *  <li> <b>Units:</b> 
099     *  </ul>
100     */
101    public double kV = 0;
102    /**
103     * Static Constant
104     * <p>
105     * This is added to the closed loop output.  The sign is determined by
106     * target velocity. The unit for this constant is dependent on the
107     * control mode, typically fractional duty cycle, voltage, or torque
108     * current.
109     *
110     *  <ul>
111     *  <li> <b>Minimum Value:</b> -512
112     *  <li> <b>Maximum Value:</b> 511
113     *  <li> <b>Default Value:</b> 0
114     *  <li> <b>Units:</b> 
115     *  </ul>
116     */
117    public double kS = 0;
118
119    @Override
120    public String toString()
121    {
122        String ss = "Config Group: Slot0\n";
123        ss += "Name: \"kP\" Value: \"" + kP + "\"" + "\n";
124        ss += "Name: \"kI\" Value: \"" + kI + "\"" + "\n";
125        ss += "Name: \"kD\" Value: \"" + kD + "\"" + "\n";
126        ss += "Name: \"kV\" Value: \"" + kV + "\"" + "\n";
127        ss += "Name: \"kS\" Value: \"" + kS + "\"" + "\n";
128        return ss;
129    }
130
131    /**
132     *
133     */
134    public StatusCode deserialize(String string)
135    {
136        kP = ConfigJNI.Deserializedouble(SpnValue.Slot0_kP.value, string);
137        kI = ConfigJNI.Deserializedouble(SpnValue.Slot0_kI.value, string);
138        kD = ConfigJNI.Deserializedouble(SpnValue.Slot0_kD.value, string);
139        kV = ConfigJNI.Deserializedouble(SpnValue.Slot0_kV.value, string);
140        kS = ConfigJNI.Deserializedouble(SpnValue.Slot0_kS.value, string);
141        return  StatusCode.OK;
142    }
143
144    /**
145     *
146     */
147    public String serialize()
148    {
149        String ss = "";
150        ss += ConfigJNI.Serializedouble(1407, kP);
151        ss += ConfigJNI.Serializedouble(1408, kI);
152        ss += ConfigJNI.Serializedouble(1409, kD);
153        ss += ConfigJNI.Serializedouble(1410, kV);
154        ss += ConfigJNI.Serializedouble(1411, kS);
155        return ss;
156    }
157}
158