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.*;
012
013/**
014 * Configs for Motion Magic®.
015 * <p>
016 * Includes Velocity, Acceleration, Jerk, and Expo parameters.
017 */
018public class MotionMagicConfigs implements ParentConfiguration
019{
020    /**
021     * This is the maximum velocity Motion Magic® based control modes are
022     * allowed to use.  Motion Magic® Velocity control modes do not use
023     * this config.  When using Motion Magic® Expo control modes, setting
024     * this to 0 will allow the profile to run to the max possible
025     * velocity based on Expo_kV.
026     * 
027     * <ul>
028     *   <li> <b>Minimum Value:</b> 0
029     *   <li> <b>Maximum Value:</b> 9999
030     *   <li> <b>Default Value:</b> 0
031     *   <li> <b>Units:</b> rps
032     * </ul>
033     */
034    public double MotionMagicCruiseVelocity = 0;
035    /**
036     * This is the target acceleration Motion Magic® based control modes
037     * are allowed to use.  Motion Magic® Expo control modes do not use
038     * this config.
039     * 
040     * <ul>
041     *   <li> <b>Minimum Value:</b> 0
042     *   <li> <b>Maximum Value:</b> 9999
043     *   <li> <b>Default Value:</b> 0
044     *   <li> <b>Units:</b> rot per sec²
045     * </ul>
046     */
047    public double MotionMagicAcceleration = 0;
048    /**
049     * This is the target jerk (acceleration derivative) Motion Magic®
050     * based control modes are allowed to use.  Motion Magic® Expo control
051     * modes do not use this config.  This allows Motion Magic® support of
052     * S-Curves.  If this is set to zero, then Motion Magic® will not
053     * apply a Jerk limit.
054     * 
055     * <ul>
056     *   <li> <b>Minimum Value:</b> 0
057     *   <li> <b>Maximum Value:</b> 9999
058     *   <li> <b>Default Value:</b> 0
059     *   <li> <b>Units:</b> rot per sec³
060     * </ul>
061     */
062    public double MotionMagicJerk = 0;
063    /**
064     * This is the target kV used only by Motion Magic® Expo control
065     * modes, in units of V/rps. This represents the amount of voltage
066     * necessary to hold a velocity. In terms of the Motion Magic® Expo
067     * profile, a higher kV results in a slower maximum velocity. A kV of
068     * 0 will be promoted to a reasonable default of 0.12.
069     * 
070     * <ul>
071     *   <li> <b>Minimum Value:</b> 0.001
072     *   <li> <b>Maximum Value:</b> 100
073     *   <li> <b>Default Value:</b> 0
074     *   <li> <b>Units:</b> V/rps
075     * </ul>
076     */
077    public double MotionMagicExpo_kV = 0;
078    /**
079     * This is the target kA used only by Motion Magic® Expo control
080     * modes, in units of V/rps². This represents the amount of voltage
081     * necessary to achieve an acceleration. In terms of the Motion Magic®
082     * Expo profile, a higher kA results in a slower acceleration. A kA of
083     * 0 will be promoted to a reasonable default of 0.1.
084     * 
085     * <ul>
086     *   <li> <b>Minimum Value:</b> 1e-05
087     *   <li> <b>Maximum Value:</b> 100
088     *   <li> <b>Default Value:</b> 0
089     *   <li> <b>Units:</b> V/rps²
090     * </ul>
091     */
092    public double MotionMagicExpo_kA = 0;
093    
094    /**
095     * Modifies this configuration's MotionMagicCruiseVelocity parameter and returns itself for
096     * method-chaining and easier to use config API.
097     * <p>
098     * This is the maximum velocity Motion Magic® based control modes are
099     * allowed to use.  Motion Magic® Velocity control modes do not use
100     * this config.  When using Motion Magic® Expo control modes, setting
101     * this to 0 will allow the profile to run to the max possible
102     * velocity based on Expo_kV.
103     * 
104     * <ul>
105     *   <li> <b>Minimum Value:</b> 0
106     *   <li> <b>Maximum Value:</b> 9999
107     *   <li> <b>Default Value:</b> 0
108     *   <li> <b>Units:</b> rps
109     * </ul>
110     *
111     * @param newMotionMagicCruiseVelocity Parameter to modify
112     * @return Itself
113     */
114    public MotionMagicConfigs withMotionMagicCruiseVelocity(double newMotionMagicCruiseVelocity)
115    {
116        MotionMagicCruiseVelocity = newMotionMagicCruiseVelocity;
117        return this;
118    }
119    /**
120     * Modifies this configuration's MotionMagicAcceleration parameter and returns itself for
121     * method-chaining and easier to use config API.
122     * <p>
123     * This is the target acceleration Motion Magic® based control modes
124     * are allowed to use.  Motion Magic® Expo control modes do not use
125     * this config.
126     * 
127     * <ul>
128     *   <li> <b>Minimum Value:</b> 0
129     *   <li> <b>Maximum Value:</b> 9999
130     *   <li> <b>Default Value:</b> 0
131     *   <li> <b>Units:</b> rot per sec²
132     * </ul>
133     *
134     * @param newMotionMagicAcceleration Parameter to modify
135     * @return Itself
136     */
137    public MotionMagicConfigs withMotionMagicAcceleration(double newMotionMagicAcceleration)
138    {
139        MotionMagicAcceleration = newMotionMagicAcceleration;
140        return this;
141    }
142    /**
143     * Modifies this configuration's MotionMagicJerk parameter and returns itself for
144     * method-chaining and easier to use config API.
145     * <p>
146     * This is the target jerk (acceleration derivative) Motion Magic®
147     * based control modes are allowed to use.  Motion Magic® Expo control
148     * modes do not use this config.  This allows Motion Magic® support of
149     * S-Curves.  If this is set to zero, then Motion Magic® will not
150     * apply a Jerk limit.
151     * 
152     * <ul>
153     *   <li> <b>Minimum Value:</b> 0
154     *   <li> <b>Maximum Value:</b> 9999
155     *   <li> <b>Default Value:</b> 0
156     *   <li> <b>Units:</b> rot per sec³
157     * </ul>
158     *
159     * @param newMotionMagicJerk Parameter to modify
160     * @return Itself
161     */
162    public MotionMagicConfigs withMotionMagicJerk(double newMotionMagicJerk)
163    {
164        MotionMagicJerk = newMotionMagicJerk;
165        return this;
166    }
167    /**
168     * Modifies this configuration's MotionMagicExpo_kV parameter and returns itself for
169     * method-chaining and easier to use config API.
170     * <p>
171     * This is the target kV used only by Motion Magic® Expo control
172     * modes, in units of V/rps. This represents the amount of voltage
173     * necessary to hold a velocity. In terms of the Motion Magic® Expo
174     * profile, a higher kV results in a slower maximum velocity. A kV of
175     * 0 will be promoted to a reasonable default of 0.12.
176     * 
177     * <ul>
178     *   <li> <b>Minimum Value:</b> 0.001
179     *   <li> <b>Maximum Value:</b> 100
180     *   <li> <b>Default Value:</b> 0
181     *   <li> <b>Units:</b> V/rps
182     * </ul>
183     *
184     * @param newMotionMagicExpo_kV Parameter to modify
185     * @return Itself
186     */
187    public MotionMagicConfigs withMotionMagicExpo_kV(double newMotionMagicExpo_kV)
188    {
189        MotionMagicExpo_kV = newMotionMagicExpo_kV;
190        return this;
191    }
192    /**
193     * Modifies this configuration's MotionMagicExpo_kA parameter and returns itself for
194     * method-chaining and easier to use config API.
195     * <p>
196     * This is the target kA used only by Motion Magic® Expo control
197     * modes, in units of V/rps². This represents the amount of voltage
198     * necessary to achieve an acceleration. In terms of the Motion Magic®
199     * Expo profile, a higher kA results in a slower acceleration. A kA of
200     * 0 will be promoted to a reasonable default of 0.1.
201     * 
202     * <ul>
203     *   <li> <b>Minimum Value:</b> 1e-05
204     *   <li> <b>Maximum Value:</b> 100
205     *   <li> <b>Default Value:</b> 0
206     *   <li> <b>Units:</b> V/rps²
207     * </ul>
208     *
209     * @param newMotionMagicExpo_kA Parameter to modify
210     * @return Itself
211     */
212    public MotionMagicConfigs withMotionMagicExpo_kA(double newMotionMagicExpo_kA)
213    {
214        MotionMagicExpo_kA = newMotionMagicExpo_kA;
215        return this;
216    }
217
218    
219
220    @Override
221    public String toString()
222    {
223        String ss = "Config Group: MotionMagic\n";
224        ss += "Name: \"MotionMagicCruiseVelocity\" Value: \"" + MotionMagicCruiseVelocity + "rps\"" + "\n";
225        ss += "Name: \"MotionMagicAcceleration\" Value: \"" + MotionMagicAcceleration + "rot per sec²\"" + "\n";
226        ss += "Name: \"MotionMagicJerk\" Value: \"" + MotionMagicJerk + "rot per sec³\"" + "\n";
227        ss += "Name: \"MotionMagicExpo_kV\" Value: \"" + MotionMagicExpo_kV + "V/rps\"" + "\n";
228        ss += "Name: \"MotionMagicExpo_kA\" Value: \"" + MotionMagicExpo_kA + "V/rps²\"" + "\n";
229        return ss;
230    }
231
232    /**
233     *
234     */
235    public StatusCode deserialize(String to_deserialize)
236    {
237        MotionMagicCruiseVelocity = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicCruiseVelocity.value, to_deserialize);
238        MotionMagicAcceleration = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicAcceleration.value, to_deserialize);
239        MotionMagicJerk = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicJerk.value, to_deserialize);
240        MotionMagicExpo_kV = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicExpo_kV.value, to_deserialize);
241        MotionMagicExpo_kA = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicExpo_kA.value, to_deserialize);
242        return  StatusCode.OK;
243    }
244
245    /**
246     *
247     */
248    public String serialize()
249    {
250        String ss = "";
251        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicCruiseVelocity.value, MotionMagicCruiseVelocity);
252        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicAcceleration.value, MotionMagicAcceleration);
253        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicJerk.value, MotionMagicJerk);
254        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicExpo_kV.value, MotionMagicExpo_kV);
255        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicExpo_kA.value, MotionMagicExpo_kA);
256        return ss;
257    }
258}
259