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 to trim the Pigeon2's gyroscope.
015 * <p>
016 * Pigeon2 allows the user to trim the gyroscope's sensitivity. While
017 * this isn't necessary for the Pigeon2, as it comes calibrated
018 * out-of-the-box, users can make use of this to make the Pigeon2 even
019 * more accurate for their application.
020 */
021public class GyroTrimConfigs implements ParentConfiguration
022{
023    /**
024     * The gyro scalar component for the X axis.
025     * 
026     * <ul>
027     *   <li> <b>Minimum Value:</b> -180
028     *   <li> <b>Maximum Value:</b> 180
029     *   <li> <b>Default Value:</b> 0
030     *   <li> <b>Units:</b> deg per rotation
031     * </ul>
032     */
033    public double GyroScalarX = 0;
034    /**
035     * The gyro scalar component for the Y axis.
036     * 
037     * <ul>
038     *   <li> <b>Minimum Value:</b> -180
039     *   <li> <b>Maximum Value:</b> 180
040     *   <li> <b>Default Value:</b> 0
041     *   <li> <b>Units:</b> deg per rotation
042     * </ul>
043     */
044    public double GyroScalarY = 0;
045    /**
046     * The gyro scalar component for the Z axis.
047     * 
048     * <ul>
049     *   <li> <b>Minimum Value:</b> -180
050     *   <li> <b>Maximum Value:</b> 180
051     *   <li> <b>Default Value:</b> 0
052     *   <li> <b>Units:</b> deg per rotation
053     * </ul>
054     */
055    public double GyroScalarZ = 0;
056    
057    /**
058     * Modifies this configuration's GyroScalarX parameter and returns itself for
059     * method-chaining and easier to use config API.
060     * <p>
061     * The gyro scalar component for the X axis.
062     * 
063     * <ul>
064     *   <li> <b>Minimum Value:</b> -180
065     *   <li> <b>Maximum Value:</b> 180
066     *   <li> <b>Default Value:</b> 0
067     *   <li> <b>Units:</b> deg per rotation
068     * </ul>
069     *
070     * @param newGyroScalarX Parameter to modify
071     * @return Itself
072     */
073    public GyroTrimConfigs withGyroScalarX(double newGyroScalarX)
074    {
075        GyroScalarX = newGyroScalarX;
076        return this;
077    }
078    
079    /**
080     * Modifies this configuration's GyroScalarY parameter and returns itself for
081     * method-chaining and easier to use config API.
082     * <p>
083     * The gyro scalar component for the Y axis.
084     * 
085     * <ul>
086     *   <li> <b>Minimum Value:</b> -180
087     *   <li> <b>Maximum Value:</b> 180
088     *   <li> <b>Default Value:</b> 0
089     *   <li> <b>Units:</b> deg per rotation
090     * </ul>
091     *
092     * @param newGyroScalarY Parameter to modify
093     * @return Itself
094     */
095    public GyroTrimConfigs withGyroScalarY(double newGyroScalarY)
096    {
097        GyroScalarY = newGyroScalarY;
098        return this;
099    }
100    
101    /**
102     * Modifies this configuration's GyroScalarZ parameter and returns itself for
103     * method-chaining and easier to use config API.
104     * <p>
105     * The gyro scalar component for the Z axis.
106     * 
107     * <ul>
108     *   <li> <b>Minimum Value:</b> -180
109     *   <li> <b>Maximum Value:</b> 180
110     *   <li> <b>Default Value:</b> 0
111     *   <li> <b>Units:</b> deg per rotation
112     * </ul>
113     *
114     * @param newGyroScalarZ Parameter to modify
115     * @return Itself
116     */
117    public GyroTrimConfigs withGyroScalarZ(double newGyroScalarZ)
118    {
119        GyroScalarZ = newGyroScalarZ;
120        return this;
121    }
122
123    
124
125    @Override
126    public String toString()
127    {
128        String ss = "Config Group: GyroTrim\n";
129        ss += "    GyroScalarX: " + GyroScalarX + " deg per rotation" + "\n";
130        ss += "    GyroScalarY: " + GyroScalarY + " deg per rotation" + "\n";
131        ss += "    GyroScalarZ: " + GyroScalarZ + " deg per rotation" + "\n";
132        return ss;
133    }
134
135    /**
136     *
137     */
138    public StatusCode deserialize(String to_deserialize)
139    {
140        GyroScalarX = ConfigJNI.Deserializedouble(SpnValue.Pigeon2GyroScalarX.value, to_deserialize);
141        GyroScalarY = ConfigJNI.Deserializedouble(SpnValue.Pigeon2GyroScalarY.value, to_deserialize);
142        GyroScalarZ = ConfigJNI.Deserializedouble(SpnValue.Pigeon2GyroScalarZ.value, to_deserialize);
143        return  StatusCode.OK;
144    }
145
146    /**
147     *
148     */
149    public String serialize()
150    {
151        String ss = "";
152        ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2GyroScalarX.value, GyroScalarX);
153        ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2GyroScalarY.value, GyroScalarY);
154        ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2GyroScalarZ.value, GyroScalarZ);
155        return ss;
156    }
157}
158