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.*;
012import com.ctre.phoenix6.signals.*;
013
014/**
015 * Configs that directly affect motor output.
016 * <p>
017 * Includes motor invert, neutral mode, and other features related to
018 * motor output.
019 */
020public class MotorOutputConfigs implements ParentConfiguration
021{
022    /**
023     * Invert state of the device.
024     * 
025     */
026    public InvertedValue Inverted = InvertedValue.CounterClockwise_Positive;
027    /**
028     * The state of the motor controller bridge when output is neutral or
029     * disabled.
030     * 
031     */
032    public NeutralModeValue NeutralMode = NeutralModeValue.Coast;
033    /**
034     * Configures the output deadband duty cycle during duty cycle and
035     * voltage based control modes.
036     * 
037     * <ul>
038     *   <li> <b>Minimum Value:</b> 0.0
039     *   <li> <b>Maximum Value:</b> 0.25
040     *   <li> <b>Default Value:</b> 0
041     *   <li> <b>Units:</b> fractional
042     * </ul>
043     */
044    public double DutyCycleNeutralDeadband = 0;
045    /**
046     * Maximum (forward) output during duty cycle based control modes.
047     * 
048     * <ul>
049     *   <li> <b>Minimum Value:</b> -1.0
050     *   <li> <b>Maximum Value:</b> 1.0
051     *   <li> <b>Default Value:</b> 1
052     *   <li> <b>Units:</b> fractional
053     * </ul>
054     */
055    public double PeakForwardDutyCycle = 1;
056    /**
057     * Minimum (reverse) output during duty cycle based control modes.
058     * 
059     * <ul>
060     *   <li> <b>Minimum Value:</b> -1.0
061     *   <li> <b>Maximum Value:</b> 1.0
062     *   <li> <b>Default Value:</b> -1
063     *   <li> <b>Units:</b> fractional
064     * </ul>
065     */
066    public double PeakReverseDutyCycle = -1;
067    
068    /**
069     * Modifies this configuration's Inverted parameter and returns itself for
070     * method-chaining and easier to use config API.
071     * <p>
072     * Invert state of the device.
073     * 
074     *
075     * @param newInverted Parameter to modify
076     * @return Itself
077     */
078    public MotorOutputConfigs withInverted(InvertedValue newInverted)
079    {
080        Inverted = newInverted;
081        return this;
082    }
083    /**
084     * Modifies this configuration's NeutralMode parameter and returns itself for
085     * method-chaining and easier to use config API.
086     * <p>
087     * The state of the motor controller bridge when output is neutral or
088     * disabled.
089     * 
090     *
091     * @param newNeutralMode Parameter to modify
092     * @return Itself
093     */
094    public MotorOutputConfigs withNeutralMode(NeutralModeValue newNeutralMode)
095    {
096        NeutralMode = newNeutralMode;
097        return this;
098    }
099    /**
100     * Modifies this configuration's DutyCycleNeutralDeadband parameter and returns itself for
101     * method-chaining and easier to use config API.
102     * <p>
103     * Configures the output deadband duty cycle during duty cycle and
104     * voltage based control modes.
105     * 
106     * <ul>
107     *   <li> <b>Minimum Value:</b> 0.0
108     *   <li> <b>Maximum Value:</b> 0.25
109     *   <li> <b>Default Value:</b> 0
110     *   <li> <b>Units:</b> fractional
111     * </ul>
112     *
113     * @param newDutyCycleNeutralDeadband Parameter to modify
114     * @return Itself
115     */
116    public MotorOutputConfigs withDutyCycleNeutralDeadband(double newDutyCycleNeutralDeadband)
117    {
118        DutyCycleNeutralDeadband = newDutyCycleNeutralDeadband;
119        return this;
120    }
121    /**
122     * Modifies this configuration's PeakForwardDutyCycle parameter and returns itself for
123     * method-chaining and easier to use config API.
124     * <p>
125     * Maximum (forward) output during duty cycle based control modes.
126     * 
127     * <ul>
128     *   <li> <b>Minimum Value:</b> -1.0
129     *   <li> <b>Maximum Value:</b> 1.0
130     *   <li> <b>Default Value:</b> 1
131     *   <li> <b>Units:</b> fractional
132     * </ul>
133     *
134     * @param newPeakForwardDutyCycle Parameter to modify
135     * @return Itself
136     */
137    public MotorOutputConfigs withPeakForwardDutyCycle(double newPeakForwardDutyCycle)
138    {
139        PeakForwardDutyCycle = newPeakForwardDutyCycle;
140        return this;
141    }
142    /**
143     * Modifies this configuration's PeakReverseDutyCycle parameter and returns itself for
144     * method-chaining and easier to use config API.
145     * <p>
146     * Minimum (reverse) output during duty cycle based control modes.
147     * 
148     * <ul>
149     *   <li> <b>Minimum Value:</b> -1.0
150     *   <li> <b>Maximum Value:</b> 1.0
151     *   <li> <b>Default Value:</b> -1
152     *   <li> <b>Units:</b> fractional
153     * </ul>
154     *
155     * @param newPeakReverseDutyCycle Parameter to modify
156     * @return Itself
157     */
158    public MotorOutputConfigs withPeakReverseDutyCycle(double newPeakReverseDutyCycle)
159    {
160        PeakReverseDutyCycle = newPeakReverseDutyCycle;
161        return this;
162    }
163
164    
165
166    @Override
167    public String toString()
168    {
169        String ss = "Config Group: MotorOutput\n";
170        ss += "Name: \"Inverted\" Value: \"" + Inverted + "\"" + "\n";
171        ss += "Name: \"NeutralMode\" Value: \"" + NeutralMode + "\"" + "\n";
172        ss += "Name: \"DutyCycleNeutralDeadband\" Value: \"" + DutyCycleNeutralDeadband + "fractional\"" + "\n";
173        ss += "Name: \"PeakForwardDutyCycle\" Value: \"" + PeakForwardDutyCycle + "fractional\"" + "\n";
174        ss += "Name: \"PeakReverseDutyCycle\" Value: \"" + PeakReverseDutyCycle + "fractional\"" + "\n";
175        return ss;
176    }
177
178    /**
179     *
180     */
181    public StatusCode deserialize(String to_deserialize)
182    {
183        Inverted = InvertedValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_Inverted.value, to_deserialize));
184        NeutralMode = NeutralModeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_NeutralMode.value, to_deserialize));
185        DutyCycleNeutralDeadband = ConfigJNI.Deserializedouble(SpnValue.Config_DutyCycleNeutralDB.value, to_deserialize);
186        PeakForwardDutyCycle = ConfigJNI.Deserializedouble(SpnValue.Config_PeakForwardDC.value, to_deserialize);
187        PeakReverseDutyCycle = ConfigJNI.Deserializedouble(SpnValue.Config_PeakReverseDC.value, to_deserialize);
188        return  StatusCode.OK;
189    }
190
191    /**
192     *
193     */
194    public String serialize()
195    {
196        String ss = "";
197        ss += ConfigJNI.Serializeint(SpnValue.Config_Inverted.value, Inverted.value);
198        ss += ConfigJNI.Serializeint(SpnValue.Config_NeutralMode.value, NeutralMode.value);
199        ss += ConfigJNI.Serializedouble(SpnValue.Config_DutyCycleNeutralDB.value, DutyCycleNeutralDeadband);
200        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakForwardDC.value, PeakForwardDutyCycle);
201        ss += ConfigJNI.Serializedouble(SpnValue.Config_PeakReverseDC.value, PeakReverseDutyCycle);
202        return ss;
203    }
204}
205