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 1 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 Slot1Configs 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, or 1/rps.
033     *
034     *  <ul>
035     *  <li> <b>Minimum Value:</b> 0
036     *  <li> <b>Maximum Value:</b> 3.4e+38
037     *  <li> <b>Default Value:</b> 0
038     *  <li> <b>Units:</b> 
039     *  </ul>
040     */
041    public double kP = 0;
042    /**
043     * Integral Gain
044     * <p>
045     * The units for this gain is dependent on the control mode. Since
046     * this gain is multiplied by error in the input integrated over time
047     * (in units of seconds), the units should be defined as units of
048     * output per unit of integrated input error. For example, when
049     * controlling velocity using a duty cycle closed loop, integrating
050     * velocity over time results in rps * s = rotations. Therefore, the
051     * units for the integral gain will be duty cycle per rotation of
052     * accumulated error, or 1/rot.
053     *
054     *  <ul>
055     *  <li> <b>Minimum Value:</b> 0
056     *  <li> <b>Maximum Value:</b> 3.4e+38
057     *  <li> <b>Default Value:</b> 0
058     *  <li> <b>Units:</b> 
059     *  </ul>
060     */
061    public double kI = 0;
062    /**
063     * Derivative Gain
064     * <p>
065     * The units for this gain is dependent on the control mode. Since
066     * this gain is multiplied by the derivative of error in the input
067     * with respect to time (in units of seconds), the units should be
068     * defined as units of output per unit of the differentiated input
069     * error. For example, when controlling velocity using a duty cycle
070     * closed loop, the derivative of velocity with respect to time is
071     * rps/s, which is acceleration. Therefore, the units for the
072     * derivative gain will be duty cycle per unit of acceleration error,
073     * or 1/(rps/s).
074     *
075     *  <ul>
076     *  <li> <b>Minimum Value:</b> 0
077     *  <li> <b>Maximum Value:</b> 3.4e+38
078     *  <li> <b>Default Value:</b> 0
079     *  <li> <b>Units:</b> 
080     *  </ul>
081     */
082    public double kD = 0;
083    /**
084     * Velocity Feed Forward Gain
085     * <p>
086     * The units for this gain is dependent on the control mode. Since
087     * this gain is multiplied by the requested velocity, the units should
088     * be defined as units of output per unit of requested input velocity.
089     * For example, when controlling velocity using a duty cycle closed
090     * loop, the units for the velocity feed foward gain will be duty
091     * cycle per requested rps, or 1/rps.
092     *
093     *  <ul>
094     *  <li> <b>Minimum Value:</b> 0
095     *  <li> <b>Maximum Value:</b> 3.4e+38
096     *  <li> <b>Default Value:</b> 0
097     *  <li> <b>Units:</b> 
098     *  </ul>
099     */
100    public double kV = 0;
101    /**
102     * Static Constant
103     * <p>
104     * This is added to the closed loop output.  The sign is determined by
105     * target velocity. The unit for this constant is dependent on the
106     * control mode, typically fractional duty cycle, voltage, or torque
107     * current.
108     *
109     *  <ul>
110     *  <li> <b>Minimum Value:</b> -512
111     *  <li> <b>Maximum Value:</b> 511
112     *  <li> <b>Default Value:</b> 0
113     *  <li> <b>Units:</b> 
114     *  </ul>
115     */
116    public double kS = 0;
117
118    @Override
119    public String toString()
120    {
121        String ss = "Config Group: Slot1\n";
122        ss += "Name: \"kP\" Value: \"" + kP + "\"" + "\n";
123        ss += "Name: \"kI\" Value: \"" + kI + "\"" + "\n";
124        ss += "Name: \"kD\" Value: \"" + kD + "\"" + "\n";
125        ss += "Name: \"kV\" Value: \"" + kV + "\"" + "\n";
126        ss += "Name: \"kS\" Value: \"" + kS + "\"" + "\n";
127        return ss;
128    }
129
130    /**
131     *
132     */
133    public StatusCode deserialize(String string)
134    {
135        kP = ConfigJNI.Deserializedouble(SpnValue.Slot1_kP.value, string);
136        kI = ConfigJNI.Deserializedouble(SpnValue.Slot1_kI.value, string);
137        kD = ConfigJNI.Deserializedouble(SpnValue.Slot1_kD.value, string);
138        kV = ConfigJNI.Deserializedouble(SpnValue.Slot1_kV.value, string);
139        kS = ConfigJNI.Deserializedouble(SpnValue.Slot1_kS.value, string);
140        return  StatusCode.OK;
141    }
142
143    /**
144     *
145     */
146    public String serialize()
147    {
148        String ss = "";
149        ss += ConfigJNI.Serializedouble(1412, kP);
150        ss += ConfigJNI.Serializedouble(1413, kI);
151        ss += ConfigJNI.Serializedouble(1414, kD);
152        ss += ConfigJNI.Serializedouble(1415, kV);
153        ss += ConfigJNI.Serializedouble(1416, kS);
154        return ss;
155    }
156}
157