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     * Modifies this configuration's GyroScalarY parameter and returns itself for
080     * method-chaining and easier to use config API.
081     * <p>
082     * The gyro scalar component for the Y axis
083     * 
084     * <ul>
085     *   <li> <b>Minimum Value:</b> -180
086     *   <li> <b>Maximum Value:</b> 180
087     *   <li> <b>Default Value:</b> 0
088     *   <li> <b>Units:</b> deg per rotation
089     * </ul>
090     *
091     * @param newGyroScalarY Parameter to modify
092     * @return Itself
093     */
094    public GyroTrimConfigs withGyroScalarY(double newGyroScalarY)
095    {
096        GyroScalarY = newGyroScalarY;
097        return this;
098    }
099    /**
100     * Modifies this configuration's GyroScalarZ parameter and returns itself for
101     * method-chaining and easier to use config API.
102     * <p>
103     * The gyro scalar component for the Z axis
104     * 
105     * <ul>
106     *   <li> <b>Minimum Value:</b> -180
107     *   <li> <b>Maximum Value:</b> 180
108     *   <li> <b>Default Value:</b> 0
109     *   <li> <b>Units:</b> deg per rotation
110     * </ul>
111     *
112     * @param newGyroScalarZ Parameter to modify
113     * @return Itself
114     */
115    public GyroTrimConfigs withGyroScalarZ(double newGyroScalarZ)
116    {
117        GyroScalarZ = newGyroScalarZ;
118        return this;
119    }
120
121    
122
123    @Override
124    public String toString()
125    {
126        String ss = "Config Group: GyroTrim\n";
127        ss += "Name: \"GyroScalarX\" Value: \"" + GyroScalarX + "deg per rotation\"" + "\n";
128        ss += "Name: \"GyroScalarY\" Value: \"" + GyroScalarY + "deg per rotation\"" + "\n";
129        ss += "Name: \"GyroScalarZ\" Value: \"" + GyroScalarZ + "deg per rotation\"" + "\n";
130        return ss;
131    }
132
133    /**
134     *
135     */
136    public StatusCode deserialize(String to_deserialize)
137    {
138        GyroScalarX = ConfigJNI.Deserializedouble(SpnValue.Pigeon2GyroScalarX.value, to_deserialize);
139        GyroScalarY = ConfigJNI.Deserializedouble(SpnValue.Pigeon2GyroScalarY.value, to_deserialize);
140        GyroScalarZ = ConfigJNI.Deserializedouble(SpnValue.Pigeon2GyroScalarZ.value, to_deserialize);
141        return  StatusCode.OK;
142    }
143
144    /**
145     *
146     */
147    public String serialize()
148    {
149        String ss = "";
150        ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2GyroScalarX.value, GyroScalarX);
151        ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2GyroScalarY.value, GyroScalarY);
152        ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2GyroScalarZ.value, GyroScalarZ);
153        return ss;
154    }
155}
156