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.phoenixpro.configs;
008
009import com.ctre.phoenix6.StatusCode;
010import com.ctre.phoenix6.configs.jni.ConfigJNI;
011import com.ctre.phoenix6.spns.*;
012import com.ctre.phoenixpro.signals.*;
013
014/**
015 *  Configs that directly affect motor-output.
016 * <p>
017 *  Includes Motor Invert and various limit features.
018 *
019 * @deprecated Classes in the phoenixpro package will be removed in 2024.
020 *             Users should instead use classes from the phoenix6 package.
021 */
022@Deprecated(forRemoval = true)
023public class FeedbackConfigs implements ParentConfiguration
024{
025    /**
026     * This offset is applied to the absolute integrated rotor sensor. 
027     * This can be used to zero the rotor in applications that are within
028     * one rotor rotation.
029     *
030     *  <ul>
031     *  <li> <b>Minimum Value:</b> -1
032     *  <li> <b>Maximum Value:</b> 1
033     *  <li> <b>Default Value:</b> 0.0
034     *  <li> <b>Units:</b> rotations
035     *  </ul>
036     */
037    public double FeedbackRotorOffset = 0.0;
038    /**
039     * This is the ratio of sensor rotations to the mechanism's output. 
040     * This is equivalent to the mechanism's gear ratio if the sensor is
041     * located on the input of a gearbox.  If sensor is on the output of a
042     * gearbox, then this is typically set to 1.  Note if this is set to
043     * zero, device will reset back to one.
044     *
045     *  <ul>
046     *  <li> <b>Minimum Value:</b> -1000
047     *  <li> <b>Maximum Value:</b> 1000
048     *  <li> <b>Default Value:</b> 1.0
049     *  <li> <b>Units:</b> scalar
050     *  </ul>
051     */
052    public double SensorToMechanismRatio = 1.0;
053    /**
054     * Talon FX is capable of fusing a remote CANcoder with its rotor
055     * sensor to produce a high-bandwidth sensor source.  This feature
056     * requires specifying the ratio between the remote sensor and the
057     * motor rotor.  Note if this is set to zero, device will reset back
058     * to one.
059     *
060     *  <ul>
061     *  <li> <b>Minimum Value:</b> -1000
062     *  <li> <b>Maximum Value:</b> 1000
063     *  <li> <b>Default Value:</b> 1.0
064     *  <li> <b>Units:</b> scalar
065     *  </ul>
066     */
067    public double RotorToSensorRatio = 1.0;
068    /**
069     * Choose what sensor source is reported via API and used by
070     * closed-loop and limit features.  The default is RotorSensor, which
071     * uses the internal rotor sensor in the Talon FX.  Choose
072     * RemoteCANcoder to use another CANcoder on the same CAN bus (this
073     * also requires setting FeedbackRemoteSensorID).  Talon FX will
074     * update its position and velocity whenever CANcoder publishes its
075     * information on CAN bus.  Choose FusedCANcoder and Talon FX will
076     * fuse another CANcoder's information with the internal rotor, which
077     * provides the best possible position and velocity for accuracy and
078     * bandwidth (note this requires setting FeedbackRemoteSensorID). 
079     * FusedCANcoder was developed for applications such as
080     * swerve-azimuth.
081     * <p>
082     * Note: When the Talon Source is changed to FusedCANcoder, the Talon
083     * needs a period of time to fuse before sensor-based (soft-limit,
084     * closed loop, etc.) features are used. This period of time is
085     * determined by the update frequency of the CANcoder's Position
086     * signal.
087     *
088     */
089    public FeedbackSensorSourceValue FeedbackSensorSource = FeedbackSensorSourceValue.RotorSensor;
090    /**
091     * Device ID of which remote device to use.  This is not used if the
092     * Sensor Source is the internal rotor sensor.
093     *
094     *  <ul>
095     *  <li> <b>Minimum Value:</b> 0
096     *  <li> <b>Maximum Value:</b> 62
097     *  <li> <b>Default Value:</b> 0
098     *  <li> <b>Units:</b> 
099     *  </ul>
100     */
101    public int FeedbackRemoteSensorID = 0;
102
103    @Override
104    public String toString()
105    {
106        String ss = "Config Group: Feedback\n";
107        ss += "Name: \"FeedbackRotorOffset\" Value: \"" + FeedbackRotorOffset + "rotations\"" + "\n";
108        ss += "Name: \"SensorToMechanismRatio\" Value: \"" + SensorToMechanismRatio + "scalar\"" + "\n";
109        ss += "Name: \"RotorToSensorRatio\" Value: \"" + RotorToSensorRatio + "scalar\"" + "\n";
110        ss += "Name: \"FeedbackSensorSource\" Value: \"" + FeedbackSensorSource + "\"" + "\n";
111        ss += "Name: \"FeedbackRemoteSensorID\" Value: \"" + FeedbackRemoteSensorID + "\"" + "\n";
112        return ss;
113    }
114
115    /**
116     *
117     */
118    public StatusCode deserialize(String string)
119    {
120        FeedbackRotorOffset = ConfigJNI.Deserializedouble(SpnValue.Config_FeedbackRotorOffset.value, string);
121        SensorToMechanismRatio = ConfigJNI.Deserializedouble(SpnValue.Config_SensorToMechanismRatio.value, string);
122        RotorToSensorRatio = ConfigJNI.Deserializedouble(SpnValue.Config_RotorToSensorRatio.value, string);
123        FeedbackSensorSource = FeedbackSensorSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_FeedbackSensorSource.value, string));
124        FeedbackRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_FeedbackRemoteSensorID.value, string);
125        return  StatusCode.OK;
126    }
127
128    /**
129     *
130     */
131    public String serialize()
132    {
133        String ss = "";
134        ss += ConfigJNI.Serializedouble(1438, FeedbackRotorOffset);
135        ss += ConfigJNI.Serializedouble(1439, SensorToMechanismRatio);
136        ss += ConfigJNI.Serializedouble(1440, RotorToSensorRatio);
137        ss += ConfigJNI.Serializeint(1441, FeedbackSensorSource.value);
138        ss += ConfigJNI.Serializeint(1442, FeedbackRemoteSensorID);
139        return ss;
140    }
141}
142