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
013import edu.wpi.first.units.*;
014
015import edu.wpi.first.units.measure.*;
016import static edu.wpi.first.units.Units.*;
017
018/**
019 * Configs for Motion Magic®.
020 * <p>
021 * Includes Velocity, Acceleration, Jerk, and Expo parameters.
022 */
023public class MotionMagicConfigs implements ParentConfiguration
024{
025    /**
026     * This is the maximum velocity Motion Magic® based control modes are
027     * allowed to use.  Motion Magic® Velocity control modes do not use
028     * this config.
029     * <p>
030     * When using Motion Magic® Expo control modes, setting this to 0 will
031     * allow the profile to run to the max possible velocity based on
032     * Expo_kV.
033     * 
034     * <ul>
035     *   <li> <b>Minimum Value:</b> 0
036     *   <li> <b>Maximum Value:</b> 9999
037     *   <li> <b>Default Value:</b> 0
038     *   <li> <b>Units:</b> rot per sec
039     * </ul>
040     */
041    public double MotionMagicCruiseVelocity = 0;
042    /**
043     * This is the target acceleration Motion Magic® based control modes
044     * are allowed to use.  Motion Magic® Expo control modes do not use
045     * this config.
046     * 
047     * <ul>
048     *   <li> <b>Minimum Value:</b> 0
049     *   <li> <b>Maximum Value:</b> 9999
050     *   <li> <b>Default Value:</b> 0
051     *   <li> <b>Units:</b> rot per sec²
052     * </ul>
053     */
054    public double MotionMagicAcceleration = 0;
055    /**
056     * This is the target jerk (acceleration derivative) Motion Magic®
057     * based control modes are allowed to use.  Motion Magic® Expo control
058     * modes do not use this config.  This allows Motion Magic® to
059     * generate S-Curve profiles.
060     * <p>
061     * Jerk is optional; if this is set to zero, then Motion Magic® will
062     * not apply a Jerk limit.
063     * 
064     * <ul>
065     *   <li> <b>Minimum Value:</b> 0
066     *   <li> <b>Maximum Value:</b> 9999
067     *   <li> <b>Default Value:</b> 0
068     *   <li> <b>Units:</b> rot per sec³
069     * </ul>
070     */
071    public double MotionMagicJerk = 0;
072    /**
073     * This is the target kV used only by Motion Magic® Expo control
074     * modes. Unlike the kV slot gain, this is always in units of V/rps.
075     * <p>
076     * This represents the amount of voltage necessary to hold a velocity.
077     * In terms of the Motion Magic® Expo profile, a higher kV results in
078     * a slower maximum velocity.
079     * 
080     * <ul>
081     *   <li> <b>Minimum Value:</b> 0.001
082     *   <li> <b>Maximum Value:</b> 100
083     *   <li> <b>Default Value:</b> 0.12
084     *   <li> <b>Units:</b> V/rps
085     * </ul>
086     */
087    public double MotionMagicExpo_kV = 0.12;
088    /**
089     * This is the target kA used only by Motion Magic® Expo control
090     * modes. Unlike the kA slot gain, this is always in units of V/rps².
091     * <p>
092     * This represents the amount of voltage necessary to achieve an
093     * acceleration. In terms of the Motion Magic® Expo profile, a higher
094     * kA results in a slower acceleration.
095     * 
096     * <ul>
097     *   <li> <b>Minimum Value:</b> 1e-05
098     *   <li> <b>Maximum Value:</b> 100
099     *   <li> <b>Default Value:</b> 0.1
100     *   <li> <b>Units:</b> V/rps²
101     * </ul>
102     */
103    public double MotionMagicExpo_kA = 0.1;
104    
105    /**
106     * Modifies this configuration's MotionMagicCruiseVelocity parameter and returns itself for
107     * method-chaining and easier to use config API.
108     * <p>
109     * This is the maximum velocity Motion Magic® based control modes are
110     * allowed to use.  Motion Magic® Velocity control modes do not use
111     * this config.
112     * <p>
113     * When using Motion Magic® Expo control modes, setting this to 0 will
114     * allow the profile to run to the max possible velocity based on
115     * Expo_kV.
116     * 
117     * <ul>
118     *   <li> <b>Minimum Value:</b> 0
119     *   <li> <b>Maximum Value:</b> 9999
120     *   <li> <b>Default Value:</b> 0
121     *   <li> <b>Units:</b> rot per sec
122     * </ul>
123     *
124     * @param newMotionMagicCruiseVelocity Parameter to modify
125     * @return Itself
126     */
127    public MotionMagicConfigs withMotionMagicCruiseVelocity(double newMotionMagicCruiseVelocity)
128    {
129        MotionMagicCruiseVelocity = newMotionMagicCruiseVelocity;
130        return this;
131    }
132    
133    /**
134     * Modifies this configuration's MotionMagicCruiseVelocity parameter and returns itself for
135     * method-chaining and easier to use config API.
136     * <p>
137     * This is the maximum velocity Motion Magic® based control modes are
138     * allowed to use.  Motion Magic® Velocity control modes do not use
139     * this config.
140     * <p>
141     * When using Motion Magic® Expo control modes, setting this to 0 will
142     * allow the profile to run to the max possible velocity based on
143     * Expo_kV.
144     * 
145     * <ul>
146     *   <li> <b>Minimum Value:</b> 0
147     *   <li> <b>Maximum Value:</b> 9999
148     *   <li> <b>Default Value:</b> 0
149     *   <li> <b>Units:</b> rot per sec
150     * </ul>
151     *
152     * @param newMotionMagicCruiseVelocity Parameter to modify
153     * @return Itself
154     */
155    public MotionMagicConfigs withMotionMagicCruiseVelocity(AngularVelocity newMotionMagicCruiseVelocity)
156    {
157        MotionMagicCruiseVelocity = newMotionMagicCruiseVelocity.in(RotationsPerSecond);
158        return this;
159    }
160    
161    /**
162     * Helper method to get this configuration's MotionMagicCruiseVelocity parameter converted
163     * to a unit type. If not using the Java units library, {@link #MotionMagicCruiseVelocity}
164     * can be accessed directly instead.
165     * <p>
166     * This is the maximum velocity Motion Magic® based control modes are
167     * allowed to use.  Motion Magic® Velocity control modes do not use
168     * this config.
169     * <p>
170     * When using Motion Magic® Expo control modes, setting this to 0 will
171     * allow the profile to run to the max possible velocity based on
172     * Expo_kV.
173     * 
174     * <ul>
175     *   <li> <b>Minimum Value:</b> 0
176     *   <li> <b>Maximum Value:</b> 9999
177     *   <li> <b>Default Value:</b> 0
178     *   <li> <b>Units:</b> rot per sec
179     * </ul>
180     *
181     * @return MotionMagicCruiseVelocity
182     */
183    public AngularVelocity getMotionMagicCruiseVelocityMeasure()
184    {
185        return RotationsPerSecond.of(MotionMagicCruiseVelocity);
186    }
187    
188    /**
189     * Modifies this configuration's MotionMagicAcceleration parameter and returns itself for
190     * method-chaining and easier to use config API.
191     * <p>
192     * This is the target acceleration Motion Magic® based control modes
193     * are allowed to use.  Motion Magic® Expo control modes do not use
194     * this config.
195     * 
196     * <ul>
197     *   <li> <b>Minimum Value:</b> 0
198     *   <li> <b>Maximum Value:</b> 9999
199     *   <li> <b>Default Value:</b> 0
200     *   <li> <b>Units:</b> rot per sec²
201     * </ul>
202     *
203     * @param newMotionMagicAcceleration Parameter to modify
204     * @return Itself
205     */
206    public MotionMagicConfigs withMotionMagicAcceleration(double newMotionMagicAcceleration)
207    {
208        MotionMagicAcceleration = newMotionMagicAcceleration;
209        return this;
210    }
211    
212    /**
213     * Modifies this configuration's MotionMagicAcceleration parameter and returns itself for
214     * method-chaining and easier to use config API.
215     * <p>
216     * This is the target acceleration Motion Magic® based control modes
217     * are allowed to use.  Motion Magic® Expo control modes do not use
218     * this config.
219     * 
220     * <ul>
221     *   <li> <b>Minimum Value:</b> 0
222     *   <li> <b>Maximum Value:</b> 9999
223     *   <li> <b>Default Value:</b> 0
224     *   <li> <b>Units:</b> rot per sec²
225     * </ul>
226     *
227     * @param newMotionMagicAcceleration Parameter to modify
228     * @return Itself
229     */
230    public MotionMagicConfigs withMotionMagicAcceleration(AngularAcceleration newMotionMagicAcceleration)
231    {
232        MotionMagicAcceleration = newMotionMagicAcceleration.in(RotationsPerSecondPerSecond);
233        return this;
234    }
235    
236    /**
237     * Helper method to get this configuration's MotionMagicAcceleration parameter converted
238     * to a unit type. If not using the Java units library, {@link #MotionMagicAcceleration}
239     * can be accessed directly instead.
240     * <p>
241     * This is the target acceleration Motion Magic® based control modes
242     * are allowed to use.  Motion Magic® Expo control modes do not use
243     * this config.
244     * 
245     * <ul>
246     *   <li> <b>Minimum Value:</b> 0
247     *   <li> <b>Maximum Value:</b> 9999
248     *   <li> <b>Default Value:</b> 0
249     *   <li> <b>Units:</b> rot per sec²
250     * </ul>
251     *
252     * @return MotionMagicAcceleration
253     */
254    public AngularAcceleration getMotionMagicAccelerationMeasure()
255    {
256        return RotationsPerSecondPerSecond.of(MotionMagicAcceleration);
257    }
258    
259    /**
260     * Modifies this configuration's MotionMagicJerk parameter and returns itself for
261     * method-chaining and easier to use config API.
262     * <p>
263     * This is the target jerk (acceleration derivative) Motion Magic®
264     * based control modes are allowed to use.  Motion Magic® Expo control
265     * modes do not use this config.  This allows Motion Magic® to
266     * generate S-Curve profiles.
267     * <p>
268     * Jerk is optional; if this is set to zero, then Motion Magic® will
269     * not apply a Jerk limit.
270     * 
271     * <ul>
272     *   <li> <b>Minimum Value:</b> 0
273     *   <li> <b>Maximum Value:</b> 9999
274     *   <li> <b>Default Value:</b> 0
275     *   <li> <b>Units:</b> rot per sec³
276     * </ul>
277     *
278     * @param newMotionMagicJerk Parameter to modify
279     * @return Itself
280     */
281    public MotionMagicConfigs withMotionMagicJerk(double newMotionMagicJerk)
282    {
283        MotionMagicJerk = newMotionMagicJerk;
284        return this;
285    }
286    
287    /**
288     * Modifies this configuration's MotionMagicJerk parameter and returns itself for
289     * method-chaining and easier to use config API.
290     * <p>
291     * This is the target jerk (acceleration derivative) Motion Magic®
292     * based control modes are allowed to use.  Motion Magic® Expo control
293     * modes do not use this config.  This allows Motion Magic® to
294     * generate S-Curve profiles.
295     * <p>
296     * Jerk is optional; if this is set to zero, then Motion Magic® will
297     * not apply a Jerk limit.
298     * 
299     * <ul>
300     *   <li> <b>Minimum Value:</b> 0
301     *   <li> <b>Maximum Value:</b> 9999
302     *   <li> <b>Default Value:</b> 0
303     *   <li> <b>Units:</b> rot per sec³
304     * </ul>
305     *
306     * @param newMotionMagicJerk Parameter to modify
307     * @return Itself
308     */
309    public MotionMagicConfigs withMotionMagicJerk(Velocity<AngularAccelerationUnit> newMotionMagicJerk)
310    {
311        MotionMagicJerk = newMotionMagicJerk.in(RotationsPerSecondPerSecond.per(Second));
312        return this;
313    }
314    
315    /**
316     * Helper method to get this configuration's MotionMagicJerk parameter converted
317     * to a unit type. If not using the Java units library, {@link #MotionMagicJerk}
318     * can be accessed directly instead.
319     * <p>
320     * This is the target jerk (acceleration derivative) Motion Magic®
321     * based control modes are allowed to use.  Motion Magic® Expo control
322     * modes do not use this config.  This allows Motion Magic® to
323     * generate S-Curve profiles.
324     * <p>
325     * Jerk is optional; if this is set to zero, then Motion Magic® will
326     * not apply a Jerk limit.
327     * 
328     * <ul>
329     *   <li> <b>Minimum Value:</b> 0
330     *   <li> <b>Maximum Value:</b> 9999
331     *   <li> <b>Default Value:</b> 0
332     *   <li> <b>Units:</b> rot per sec³
333     * </ul>
334     *
335     * @return MotionMagicJerk
336     */
337    public Velocity<AngularAccelerationUnit> getMotionMagicJerkMeasure()
338    {
339        return RotationsPerSecondPerSecond.per(Second).of(MotionMagicJerk);
340    }
341    
342    /**
343     * Modifies this configuration's MotionMagicExpo_kV parameter and returns itself for
344     * method-chaining and easier to use config API.
345     * <p>
346     * This is the target kV used only by Motion Magic® Expo control
347     * modes. Unlike the kV slot gain, this is always in units of V/rps.
348     * <p>
349     * This represents the amount of voltage necessary to hold a velocity.
350     * In terms of the Motion Magic® Expo profile, a higher kV results in
351     * a slower maximum velocity.
352     * 
353     * <ul>
354     *   <li> <b>Minimum Value:</b> 0.001
355     *   <li> <b>Maximum Value:</b> 100
356     *   <li> <b>Default Value:</b> 0.12
357     *   <li> <b>Units:</b> V/rps
358     * </ul>
359     *
360     * @param newMotionMagicExpo_kV Parameter to modify
361     * @return Itself
362     */
363    public MotionMagicConfigs withMotionMagicExpo_kV(double newMotionMagicExpo_kV)
364    {
365        MotionMagicExpo_kV = newMotionMagicExpo_kV;
366        return this;
367    }
368    
369    /**
370     * Modifies this configuration's MotionMagicExpo_kV parameter and returns itself for
371     * method-chaining and easier to use config API.
372     * <p>
373     * This is the target kV used only by Motion Magic® Expo control
374     * modes. Unlike the kV slot gain, this is always in units of V/rps.
375     * <p>
376     * This represents the amount of voltage necessary to hold a velocity.
377     * In terms of the Motion Magic® Expo profile, a higher kV results in
378     * a slower maximum velocity.
379     * 
380     * <ul>
381     *   <li> <b>Minimum Value:</b> 0.001
382     *   <li> <b>Maximum Value:</b> 100
383     *   <li> <b>Default Value:</b> 0.12
384     *   <li> <b>Units:</b> V/rps
385     * </ul>
386     *
387     * @param newMotionMagicExpo_kV Parameter to modify
388     * @return Itself
389     */
390    public MotionMagicConfigs withMotionMagicExpo_kV(Per<VoltageUnit, AngularVelocityUnit> newMotionMagicExpo_kV)
391    {
392        MotionMagicExpo_kV = newMotionMagicExpo_kV.in(Volts.per(RotationsPerSecond));
393        return this;
394    }
395    
396    /**
397     * Helper method to get this configuration's MotionMagicExpo_kV parameter converted
398     * to a unit type. If not using the Java units library, {@link #MotionMagicExpo_kV}
399     * can be accessed directly instead.
400     * <p>
401     * This is the target kV used only by Motion Magic® Expo control
402     * modes. Unlike the kV slot gain, this is always in units of V/rps.
403     * <p>
404     * This represents the amount of voltage necessary to hold a velocity.
405     * In terms of the Motion Magic® Expo profile, a higher kV results in
406     * a slower maximum velocity.
407     * 
408     * <ul>
409     *   <li> <b>Minimum Value:</b> 0.001
410     *   <li> <b>Maximum Value:</b> 100
411     *   <li> <b>Default Value:</b> 0.12
412     *   <li> <b>Units:</b> V/rps
413     * </ul>
414     *
415     * @return MotionMagicExpo_kV
416     */
417    public Per<VoltageUnit, AngularVelocityUnit> getMotionMagicExpo_kVMeasure()
418    {
419        return Volts.per(RotationsPerSecond).ofNative(MotionMagicExpo_kV);
420    }
421    
422    /**
423     * Modifies this configuration's MotionMagicExpo_kA parameter and returns itself for
424     * method-chaining and easier to use config API.
425     * <p>
426     * This is the target kA used only by Motion Magic® Expo control
427     * modes. Unlike the kA slot gain, this is always in units of V/rps².
428     * <p>
429     * This represents the amount of voltage necessary to achieve an
430     * acceleration. In terms of the Motion Magic® Expo profile, a higher
431     * kA results in a slower acceleration.
432     * 
433     * <ul>
434     *   <li> <b>Minimum Value:</b> 1e-05
435     *   <li> <b>Maximum Value:</b> 100
436     *   <li> <b>Default Value:</b> 0.1
437     *   <li> <b>Units:</b> V/rps²
438     * </ul>
439     *
440     * @param newMotionMagicExpo_kA Parameter to modify
441     * @return Itself
442     */
443    public MotionMagicConfigs withMotionMagicExpo_kA(double newMotionMagicExpo_kA)
444    {
445        MotionMagicExpo_kA = newMotionMagicExpo_kA;
446        return this;
447    }
448    
449    /**
450     * Modifies this configuration's MotionMagicExpo_kA parameter and returns itself for
451     * method-chaining and easier to use config API.
452     * <p>
453     * This is the target kA used only by Motion Magic® Expo control
454     * modes. Unlike the kA slot gain, this is always in units of V/rps².
455     * <p>
456     * This represents the amount of voltage necessary to achieve an
457     * acceleration. In terms of the Motion Magic® Expo profile, a higher
458     * kA results in a slower acceleration.
459     * 
460     * <ul>
461     *   <li> <b>Minimum Value:</b> 1e-05
462     *   <li> <b>Maximum Value:</b> 100
463     *   <li> <b>Default Value:</b> 0.1
464     *   <li> <b>Units:</b> V/rps²
465     * </ul>
466     *
467     * @param newMotionMagicExpo_kA Parameter to modify
468     * @return Itself
469     */
470    public MotionMagicConfigs withMotionMagicExpo_kA(Per<VoltageUnit, AngularAccelerationUnit> newMotionMagicExpo_kA)
471    {
472        MotionMagicExpo_kA = newMotionMagicExpo_kA.in(Volts.per(RotationsPerSecondPerSecond));
473        return this;
474    }
475    
476    /**
477     * Helper method to get this configuration's MotionMagicExpo_kA parameter converted
478     * to a unit type. If not using the Java units library, {@link #MotionMagicExpo_kA}
479     * can be accessed directly instead.
480     * <p>
481     * This is the target kA used only by Motion Magic® Expo control
482     * modes. Unlike the kA slot gain, this is always in units of V/rps².
483     * <p>
484     * This represents the amount of voltage necessary to achieve an
485     * acceleration. In terms of the Motion Magic® Expo profile, a higher
486     * kA results in a slower acceleration.
487     * 
488     * <ul>
489     *   <li> <b>Minimum Value:</b> 1e-05
490     *   <li> <b>Maximum Value:</b> 100
491     *   <li> <b>Default Value:</b> 0.1
492     *   <li> <b>Units:</b> V/rps²
493     * </ul>
494     *
495     * @return MotionMagicExpo_kA
496     */
497    public Per<VoltageUnit, AngularAccelerationUnit> getMotionMagicExpo_kAMeasure()
498    {
499        return Volts.per(RotationsPerSecondPerSecond).ofNative(MotionMagicExpo_kA);
500    }
501
502    
503
504    @Override
505    public String toString()
506    {
507        String ss = "Config Group: MotionMagic\n";
508        ss += "    MotionMagicCruiseVelocity: " + MotionMagicCruiseVelocity + " rot per sec" + "\n";
509        ss += "    MotionMagicAcceleration: " + MotionMagicAcceleration + " rot per sec²" + "\n";
510        ss += "    MotionMagicJerk: " + MotionMagicJerk + " rot per sec³" + "\n";
511        ss += "    MotionMagicExpo_kV: " + MotionMagicExpo_kV + " V/rps" + "\n";
512        ss += "    MotionMagicExpo_kA: " + MotionMagicExpo_kA + " V/rps²" + "\n";
513        return ss;
514    }
515
516    /**
517     *
518     */
519    public StatusCode deserialize(String to_deserialize)
520    {
521        MotionMagicCruiseVelocity = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicCruiseVelocity.value, to_deserialize);
522        MotionMagicAcceleration = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicAcceleration.value, to_deserialize);
523        MotionMagicJerk = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicJerk.value, to_deserialize);
524        MotionMagicExpo_kV = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicExpo_kV.value, to_deserialize);
525        MotionMagicExpo_kA = ConfigJNI.Deserializedouble(SpnValue.Config_MotionMagicExpo_kA.value, to_deserialize);
526        return  StatusCode.OK;
527    }
528
529    /**
530     *
531     */
532    public String serialize()
533    {
534        String ss = "";
535        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicCruiseVelocity.value, MotionMagicCruiseVelocity);
536        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicAcceleration.value, MotionMagicAcceleration);
537        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicJerk.value, MotionMagicJerk);
538        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicExpo_kV.value, MotionMagicExpo_kV);
539        ss += ConfigJNI.Serializedouble(SpnValue.Config_MotionMagicExpo_kA.value, MotionMagicExpo_kA);
540        return ss;
541    }
542}
543