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.*;
012import com.ctre.phoenix6.signals.*;
013
014/**
015 * Configs related to sensors used for differential control of a
016 * mechanism.
017 * <p>
018 * Includes the differential sensor sources and IDs.
019 */
020public class DifferentialSensorsConfigs implements ParentConfiguration
021{
022    /**
023     * Choose what sensor source is used for differential control of a
024     * mechanism.  The default is Disabled.  All other options require
025     * setting the DifferentialTalonFXSensorID, as the average of this
026     * Talon FX's sensor and the remote TalonFX's sensor is used for the
027     * differential controller's primary targets.
028     * <p>
029     * Choose RemoteTalonFX_Diff to use another TalonFX on the same CAN
030     * bus.  Talon FX will update its differential position and velocity
031     * whenever the remote TalonFX publishes its information on CAN bus. 
032     * The differential controller will use the difference between this
033     * TalonFX's sensor and the remote Talon FX's sensor for the
034     * differential component of the output.
035     * <p>
036     * Choose RemotePigeon2_Yaw, RemotePigeon2_Pitch, and
037     * RemotePigeon2_Roll to use another Pigeon2 on the same CAN bus (this
038     * also requires setting DifferentialRemoteSensorID).  Talon FX will
039     * update its differential position to match the selected value
040     * whenever Pigeon2 publishes its information on CAN bus. Note that
041     * the Talon FX differential position will be in rotations and not
042     * degrees.
043     * <p>
044     * Choose RemoteCANcoder to use another CANcoder on the same CAN bus
045     * (this also requires setting DifferentialRemoteSensorID).  Talon FX
046     * will update its differential position and velocity to match the
047     * CANcoder whenever CANcoder publishes its information on CAN bus.
048     * 
049     */
050    public DifferentialSensorSourceValue DifferentialSensorSource = DifferentialSensorSourceValue.Disabled;
051    /**
052     * Device ID of which remote Talon FX to use.  This is used when the
053     * Differential Sensor Source is not disabled.
054     * 
055     * <ul>
056     *   <li> <b>Minimum Value:</b> 0
057     *   <li> <b>Maximum Value:</b> 62
058     *   <li> <b>Default Value:</b> 0
059     *   <li> <b>Units:</b> 
060     * </ul>
061     */
062    public int DifferentialTalonFXSensorID = 0;
063    /**
064     * Device ID of which remote sensor to use on the differential axis. 
065     * This is used when the Differential Sensor Source is not
066     * RemoteTalonFX_Diff.
067     * 
068     * <ul>
069     *   <li> <b>Minimum Value:</b> 0
070     *   <li> <b>Maximum Value:</b> 62
071     *   <li> <b>Default Value:</b> 0
072     *   <li> <b>Units:</b> 
073     * </ul>
074     */
075    public int DifferentialRemoteSensorID = 0;
076    
077    /**
078     * Modifies this configuration's DifferentialSensorSource parameter and returns itself for
079     * method-chaining and easier to use config API.
080     * <p>
081     * Choose what sensor source is used for differential control of a
082     * mechanism.  The default is Disabled.  All other options require
083     * setting the DifferentialTalonFXSensorID, as the average of this
084     * Talon FX's sensor and the remote TalonFX's sensor is used for the
085     * differential controller's primary targets.
086     * <p>
087     * Choose RemoteTalonFX_Diff to use another TalonFX on the same CAN
088     * bus.  Talon FX will update its differential position and velocity
089     * whenever the remote TalonFX publishes its information on CAN bus. 
090     * The differential controller will use the difference between this
091     * TalonFX's sensor and the remote Talon FX's sensor for the
092     * differential component of the output.
093     * <p>
094     * Choose RemotePigeon2_Yaw, RemotePigeon2_Pitch, and
095     * RemotePigeon2_Roll to use another Pigeon2 on the same CAN bus (this
096     * also requires setting DifferentialRemoteSensorID).  Talon FX will
097     * update its differential position to match the selected value
098     * whenever Pigeon2 publishes its information on CAN bus. Note that
099     * the Talon FX differential position will be in rotations and not
100     * degrees.
101     * <p>
102     * Choose RemoteCANcoder to use another CANcoder on the same CAN bus
103     * (this also requires setting DifferentialRemoteSensorID).  Talon FX
104     * will update its differential position and velocity to match the
105     * CANcoder whenever CANcoder publishes its information on CAN bus.
106     * 
107     *
108     * @param newDifferentialSensorSource Parameter to modify
109     * @return Itself
110     */
111    public DifferentialSensorsConfigs withDifferentialSensorSource(DifferentialSensorSourceValue newDifferentialSensorSource)
112    {
113        DifferentialSensorSource = newDifferentialSensorSource;
114        return this;
115    }
116    
117    /**
118     * Modifies this configuration's DifferentialTalonFXSensorID parameter and returns itself for
119     * method-chaining and easier to use config API.
120     * <p>
121     * Device ID of which remote Talon FX to use.  This is used when the
122     * Differential Sensor Source is not disabled.
123     * 
124     * <ul>
125     *   <li> <b>Minimum Value:</b> 0
126     *   <li> <b>Maximum Value:</b> 62
127     *   <li> <b>Default Value:</b> 0
128     *   <li> <b>Units:</b> 
129     * </ul>
130     *
131     * @param newDifferentialTalonFXSensorID Parameter to modify
132     * @return Itself
133     */
134    public DifferentialSensorsConfigs withDifferentialTalonFXSensorID(int newDifferentialTalonFXSensorID)
135    {
136        DifferentialTalonFXSensorID = newDifferentialTalonFXSensorID;
137        return this;
138    }
139    
140    /**
141     * Modifies this configuration's DifferentialRemoteSensorID parameter and returns itself for
142     * method-chaining and easier to use config API.
143     * <p>
144     * Device ID of which remote sensor to use on the differential axis. 
145     * This is used when the Differential Sensor Source is not
146     * RemoteTalonFX_Diff.
147     * 
148     * <ul>
149     *   <li> <b>Minimum Value:</b> 0
150     *   <li> <b>Maximum Value:</b> 62
151     *   <li> <b>Default Value:</b> 0
152     *   <li> <b>Units:</b> 
153     * </ul>
154     *
155     * @param newDifferentialRemoteSensorID Parameter to modify
156     * @return Itself
157     */
158    public DifferentialSensorsConfigs withDifferentialRemoteSensorID(int newDifferentialRemoteSensorID)
159    {
160        DifferentialRemoteSensorID = newDifferentialRemoteSensorID;
161        return this;
162    }
163
164    
165
166    @Override
167    public String toString()
168    {
169        String ss = "Config Group: DifferentialSensors\n";
170        ss += "    DifferentialSensorSource: " + DifferentialSensorSource + "\n";
171        ss += "    DifferentialTalonFXSensorID: " + DifferentialTalonFXSensorID + "\n";
172        ss += "    DifferentialRemoteSensorID: " + DifferentialRemoteSensorID + "\n";
173        return ss;
174    }
175
176    /**
177     *
178     */
179    public StatusCode deserialize(String to_deserialize)
180    {
181        DifferentialSensorSource = DifferentialSensorSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_DifferentialSensorSource.value, to_deserialize));
182        DifferentialTalonFXSensorID = ConfigJNI.Deserializeint(SpnValue.Config_DifferentialTalonFXSensorID.value, to_deserialize);
183        DifferentialRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_DifferentialRemoteSensorID.value, to_deserialize);
184        return  StatusCode.OK;
185    }
186
187    /**
188     *
189     */
190    public String serialize()
191    {
192        String ss = "";
193        ss += ConfigJNI.Serializeint(SpnValue.Config_DifferentialSensorSource.value, DifferentialSensorSource.value);
194        ss += ConfigJNI.Serializeint(SpnValue.Config_DifferentialTalonFXSensorID.value, DifferentialTalonFXSensorID);
195        ss += ConfigJNI.Serializeint(SpnValue.Config_DifferentialRemoteSensorID.value, DifferentialRemoteSensorID);
196        return ss;
197    }
198}
199