001package com.ctre.phoenix.motorcontrol.can;
002
003/**
004 * Configurables available to a slot
005 */
006public class SlotConfiguration{
007
008    /**
009     * P Gain
010         *
011         * This is multiplied by closed loop error in sensor units.  
012         * Note the closed loop output interprets a final value of 1023 as full output.  
013         * So use a gain of '0.25' to get full output if err is 4096u (Mag Encoder 1 rotation)
014     */
015    public double kP;
016    /**
017     * I Gain
018     *
019         * This is multiplied by accumulated closed loop error in sensor units every PID Loop.  
020         * Note the closed loop output interprets a final value of 1023 as full output.  
021         * So use a gain of '0.00025' to get full output if err is 4096u for 1000 loops (accumulater holds 4,096,000),
022         * [which is equivalent to one CTRE mag encoder rotation for 1000 milliseconds].
023     */
024    public double kI;
025    /**
026     * D Gain
027         *
028         * This is multiplied by derivative error (sensor units per PID loop, typically 1ms).  
029         * Note the closed loop output interprets a final value of 1023 as full output.  
030         * So use a gain of '250' to get full output if derr is 4096u (Mag Encoder 1 rotation) per 1000 loops (typ 1 sec)
031     */
032    public double kD;
033    /**
034     * F Gain
035         *
036         * See documentation for calculation details.  
037         * If using velocity, motion magic, or motion profile, 
038         * use (1023 * duty-cycle / sensor-velocity-sensor-units-per-100ms).
039         *
040     */
041    public double kF;
042    /**
043     * Integral zone (in native units)
044         * 
045         * If the (absolute) closed-loop error is outside of this zone, integral
046         * accumulator is automatically cleared. This ensures than integral wind up
047         * events will stop after the sensor gets far enough from its target.
048         *
049     */
050    public double integralZone;
051    /**
052     * Allowable closed loop error to neutral (in native units)
053     */
054    public double allowableClosedloopError;
055    /**
056     * Max integral accumulator (in native units)
057     */
058    public double maxIntegralAccumulator;
059    /**
060     * Peak output from closed loop [0,1]
061     */
062    public double closedLoopPeakOutput;
063    /**
064     * Desired period of closed loop [1,64]ms
065     */
066    public int closedLoopPeriod;
067
068    public SlotConfiguration() {
069
070        kP = 0.0;
071        kI = 0.0;
072        kD = 0.0;
073        kF = 0.0;
074        integralZone = 0;
075        allowableClosedloopError = 0;
076        maxIntegralAccumulator = 0.0;
077        closedLoopPeakOutput = 1.0;
078        closedLoopPeriod = 1;
079    }
080
081    /**
082     * @return String representation of configs
083     */
084        public String toString() {
085                return toString("");
086        }
087
088    /**
089     * @param prependString
090     *              String to prepend to configs
091     * @return String representation of configs
092     */
093    public String toString(String prependString) {
094
095        String retstr = prependString + ".kP = " + String.valueOf(kP) + ";\n";
096        retstr += prependString + ".kI = " + String.valueOf(kI) + ";\n";
097        retstr += prependString + ".kD = " + String.valueOf(kD) + ";\n";
098        retstr += prependString + ".kF = " + String.valueOf(kF) + ";\n";
099        retstr += prependString + ".integralZone = " + String.valueOf(integralZone) + ";\n";
100        retstr += prependString + ".allowableClosedloopError = " + String.valueOf(allowableClosedloopError) + ";\n";
101        retstr += prependString + ".maxIntegralAccumulator = " + String.valueOf(maxIntegralAccumulator) + ";\n";
102        retstr += prependString + ".closedLoopPeakOutput = " + String.valueOf(closedLoopPeakOutput) + ";\n";
103        retstr += prependString + ".closedLoopPeriod = " + String.valueOf(closedLoopPeriod) + ";\n";
104
105        return retstr;
106
107    }
108
109} // class SlotConfiguration
110