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