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;
010
011/**
012 * Class description for the Pigeon 2 IMU sensor that measures orientation.
013 *
014 * This defines all configurations for the {@link com.ctre.phoenix6.hardware.Pigeon2}.
015 */
016public class Pigeon2Configuration implements ParentConfiguration, Cloneable {
017    /**
018     * True if we should factory default newer unsupported configs,
019     * false to leave newer unsupported configs alone.
020     * <p>
021     * This flag addresses a corner case where the device may have
022     * firmware with newer configs that didn't exist when this
023     * version of the API was built. If this occurs and this
024     * flag is true, unsupported new configs will be factory
025     * defaulted to avoid unexpected behavior.
026     * <p>
027     * This is also the behavior in Phoenix 5, so this flag
028     * is defaulted to true to match.
029     */
030    public boolean FutureProofConfigs = true;
031
032    
033    /**
034     * Configs for Pigeon 2's Mount Pose configuration.
035     * <p>
036     * These configs allow the Pigeon2 to be mounted in whatever
037     * orientation that's desired and ensure the reported Yaw/Pitch/Roll
038     * is from the robot's reference.
039     * <p>
040     * Parameter list:
041     * 
042     * <ul>
043     *   <li> {@link MountPoseConfigs#MountPoseYaw}
044     *   <li> {@link MountPoseConfigs#MountPosePitch}
045     *   <li> {@link MountPoseConfigs#MountPoseRoll}
046     * </ul>
047     * 
048     */
049    public MountPoseConfigs MountPose = new MountPoseConfigs();
050    
051    /**
052     * Configs to trim the Pigeon2's gyroscope.
053     * <p>
054     * Pigeon2 allows the user to trim the gyroscope's sensitivity. While
055     * this isn't necessary for the Pigeon2, as it comes calibrated
056     * out-of-the-box, users can make use of this to make the Pigeon2 even
057     * more accurate for their application.
058     * <p>
059     * Parameter list:
060     * 
061     * <ul>
062     *   <li> {@link GyroTrimConfigs#GyroScalarX}
063     *   <li> {@link GyroTrimConfigs#GyroScalarY}
064     *   <li> {@link GyroTrimConfigs#GyroScalarZ}
065     * </ul>
066     * 
067     */
068    public GyroTrimConfigs GyroTrim = new GyroTrimConfigs();
069    
070    /**
071     * Configs to enable/disable various features of the Pigeon2.
072     * <p>
073     * These configs allow the user to enable or disable various aspects
074     * of the Pigeon2.
075     * <p>
076     * Parameter list:
077     * 
078     * <ul>
079     *   <li> {@link Pigeon2FeaturesConfigs#EnableCompass}
080     *   <li> {@link
081     * Pigeon2FeaturesConfigs#DisableTemperatureCompensation}
082     *   <li> {@link Pigeon2FeaturesConfigs#DisableNoMotionCalibration}
083     * </ul>
084     * 
085     */
086    public Pigeon2FeaturesConfigs Pigeon2Features = new Pigeon2FeaturesConfigs();
087    
088    /**
089     * Custom Params.
090     * <p>
091     * Custom paramaters that have no real impact on controller.
092     * <p>
093     * Parameter list:
094     * 
095     * <ul>
096     *   <li> {@link CustomParamsConfigs#CustomParam0}
097     *   <li> {@link CustomParamsConfigs#CustomParam1}
098     * </ul>
099     * 
100     */
101    public CustomParamsConfigs CustomParams = new CustomParamsConfigs();
102    
103    /**
104     * Modifies this configuration's MountPose parameter and returns itself for
105     * method-chaining and easier to use config API.
106     * <p>
107     * Configs for Pigeon 2's Mount Pose configuration.
108     * <p>
109     * These configs allow the Pigeon2 to be mounted in whatever
110     * orientation that's desired and ensure the reported Yaw/Pitch/Roll
111     * is from the robot's reference.
112     * <p>
113     * Parameter list:
114     * 
115     * <ul>
116     *   <li> {@link MountPoseConfigs#MountPoseYaw}
117     *   <li> {@link MountPoseConfigs#MountPosePitch}
118     *   <li> {@link MountPoseConfigs#MountPoseRoll}
119     * </ul>
120     * 
121     *
122     * @param newMountPose Parameter to modify
123     * @return Itself
124     */
125    public final Pigeon2Configuration withMountPose(MountPoseConfigs newMountPose)
126    {
127        MountPose = newMountPose;
128        return this;
129    }
130    
131    /**
132     * Modifies this configuration's GyroTrim parameter and returns itself for
133     * method-chaining and easier to use config API.
134     * <p>
135     * Configs to trim the Pigeon2's gyroscope.
136     * <p>
137     * Pigeon2 allows the user to trim the gyroscope's sensitivity. While
138     * this isn't necessary for the Pigeon2, as it comes calibrated
139     * out-of-the-box, users can make use of this to make the Pigeon2 even
140     * more accurate for their application.
141     * <p>
142     * Parameter list:
143     * 
144     * <ul>
145     *   <li> {@link GyroTrimConfigs#GyroScalarX}
146     *   <li> {@link GyroTrimConfigs#GyroScalarY}
147     *   <li> {@link GyroTrimConfigs#GyroScalarZ}
148     * </ul>
149     * 
150     *
151     * @param newGyroTrim Parameter to modify
152     * @return Itself
153     */
154    public final Pigeon2Configuration withGyroTrim(GyroTrimConfigs newGyroTrim)
155    {
156        GyroTrim = newGyroTrim;
157        return this;
158    }
159    
160    /**
161     * Modifies this configuration's Pigeon2Features parameter and returns itself for
162     * method-chaining and easier to use config API.
163     * <p>
164     * Configs to enable/disable various features of the Pigeon2.
165     * <p>
166     * These configs allow the user to enable or disable various aspects
167     * of the Pigeon2.
168     * <p>
169     * Parameter list:
170     * 
171     * <ul>
172     *   <li> {@link Pigeon2FeaturesConfigs#EnableCompass}
173     *   <li> {@link
174     * Pigeon2FeaturesConfigs#DisableTemperatureCompensation}
175     *   <li> {@link Pigeon2FeaturesConfigs#DisableNoMotionCalibration}
176     * </ul>
177     * 
178     *
179     * @param newPigeon2Features Parameter to modify
180     * @return Itself
181     */
182    public final Pigeon2Configuration withPigeon2Features(Pigeon2FeaturesConfigs newPigeon2Features)
183    {
184        Pigeon2Features = newPigeon2Features;
185        return this;
186    }
187    
188    /**
189     * Modifies this configuration's CustomParams parameter and returns itself for
190     * method-chaining and easier to use config API.
191     * <p>
192     * Custom Params.
193     * <p>
194     * Custom paramaters that have no real impact on controller.
195     * <p>
196     * Parameter list:
197     * 
198     * <ul>
199     *   <li> {@link CustomParamsConfigs#CustomParam0}
200     *   <li> {@link CustomParamsConfigs#CustomParam1}
201     * </ul>
202     * 
203     *
204     * @param newCustomParams Parameter to modify
205     * @return Itself
206     */
207    public final Pigeon2Configuration withCustomParams(CustomParamsConfigs newCustomParams)
208    {
209        CustomParams = newCustomParams;
210        return this;
211    }
212
213    @Override
214    public String toString() {
215        String ss = "Pigeon2Configuration\n";
216        ss += MountPose.toString();
217        ss += GyroTrim.toString();
218        ss += Pigeon2Features.toString();
219        ss += CustomParams.toString();
220        return ss;
221    }
222
223    /**
224     * Get the serialized form of this configuration.
225     *
226     * @return Serialized form of this config group
227     */
228    public final String serialize() {
229        String ss = "";
230        ss += MountPose.serialize();
231        ss += GyroTrim.serialize();
232        ss += Pigeon2Features.serialize();
233        ss += CustomParams.serialize();
234        return ss;
235    }
236
237    /**
238     * Take a string and deserialize it to this configuration.
239     *
240     * @return Return code of the deserialize method
241     */
242    public final StatusCode deserialize(String to_deserialize) {
243        StatusCode err = StatusCode.OK;
244        err = MountPose.deserialize(to_deserialize);
245        err = GyroTrim.deserialize(to_deserialize);
246        err = Pigeon2Features.deserialize(to_deserialize);
247        err = CustomParams.deserialize(to_deserialize);
248        return err;
249    }
250
251    @Override
252    public Pigeon2Configuration clone() {
253        var retval = new Pigeon2Configuration();
254        retval.FutureProofConfigs = FutureProofConfigs;
255        retval.MountPose = MountPose.clone();
256        retval.GyroTrim = GyroTrim.clone();
257        retval.Pigeon2Features = Pigeon2Features.clone();
258        retval.CustomParams = CustomParams.clone();
259        return retval;
260    }
261}