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.signals;
008
009import java.util.HashMap;
010
011/**
012 * Choose what sensor source is reported via API and used by closed-loop and
013 * limit features.  The default is RotorSensor, which uses the internal rotor
014 * sensor in the Talon.
015 * <p>
016 * Choose Remote* to use another sensor on the same CAN bus (this also requires
017 * setting FeedbackRemoteSensorID).  Talon will update its position and velocity
018 * whenever the remote sensor publishes its information on CAN bus, and the
019 * Talon internal rotor will not be used.
020 * <p>
021 * Choose Fused* (requires Phoenix Pro) and Talon will fuse another sensor's
022 * information with the internal rotor, which provides the best possible
023 * position and velocity for accuracy and bandwidth (this also requires setting
024 * FeedbackRemoteSensorID).  This was developed for applications such as
025 * swerve-azimuth.
026 * <p>
027 * Choose Sync* (requires Phoenix Pro) and Talon will synchronize its internal
028 * rotor position against another sensor, then continue to use the rotor sensor
029 * for closed loop control (this also requires setting FeedbackRemoteSensorID). 
030 * The Talon will report if its internal position differs significantly from the
031 * reported remote sensor position.  This was developed for mechanisms where
032 * there is a risk of the sensor failing in such a way that it reports a
033 * position that does not match the mechanism, such as the sensor mounting
034 * assembly breaking off.
035 * <p>
036 * Choose RemotePigeon2Yaw, RemotePigeon2Pitch, and RemotePigeon2Roll to use
037 * another Pigeon2 on the same CAN bus (this also requires setting
038 * FeedbackRemoteSensorID).  Talon will update its position to match the
039 * selected value whenever Pigeon2 publishes its information on CAN bus. Note
040 * that the Talon position will be in rotations and not degrees.
041 * <p>
042 * Note: When the feedback source is changed to Fused* or Sync*, the Talon needs
043 * a period of time to fuse before sensor-based (soft-limit, closed loop, etc.)
044 * features are used. This period of time is determined by the update frequency
045 * of the remote sensor's Position signal.
046 */
047public enum FeedbackSensorSourceValue
048{
049    /**
050     * Use the internal rotor sensor in the Talon.
051     */
052    RotorSensor(0),
053    /**
054     * Use another CANcoder on the same CAN bus (this also requires setting
055     * FeedbackRemoteSensorID).  Talon will update its position and velocity
056     * whenever CANcoder publishes its information on CAN bus, and the Talon
057     * internal rotor will not be used.
058     */
059    RemoteCANcoder(1),
060    /**
061     * Use another Pigeon2 on the same CAN bus (this also requires setting
062     * FeedbackRemoteSensorID).  Talon will update its position to match the Pigeon2
063     * yaw whenever Pigeon2 publishes its information on CAN bus. Note that the
064     * Talon position will be in rotations and not degrees.
065     */
066    RemotePigeon2Yaw(2),
067    /**
068     * Use another Pigeon2 on the same CAN bus (this also requires setting
069     * FeedbackRemoteSensorID).  Talon will update its position to match the Pigeon2
070     * pitch whenever Pigeon2 publishes its information on CAN bus. Note that the
071     * Talon position will be in rotations and not degrees.
072     */
073    RemotePigeon2Pitch(3),
074    /**
075     * Use another Pigeon2 on the same CAN bus (this also requires setting
076     * FeedbackRemoteSensorID).  Talon will update its position to match the Pigeon2
077     * roll whenever Pigeon2 publishes its information on CAN bus. Note that the
078     * Talon position will be in rotations and not degrees.
079     */
080    RemotePigeon2Roll(4),
081    /**
082     * Requires Phoenix Pro; Talon will fuse another CANcoder's information with the
083     * internal rotor, which provides the best possible position and velocity for
084     * accuracy and bandwidth (this also requires setting FeedbackRemoteSensorID). 
085     * FusedCANcoder was developed for applications such as swerve-azimuth.
086     */
087    FusedCANcoder(5),
088    /**
089     * Requires Phoenix Pro; Talon will synchronize its internal rotor position
090     * against another CANcoder, then continue to use the rotor sensor for closed
091     * loop control (this also requires setting FeedbackRemoteSensorID).  The Talon
092     * will report if its internal position differs significantly from the reported
093     * CANcoder position.  SyncCANcoder was developed for mechanisms where there is
094     * a risk of the CANcoder failing in such a way that it reports a position that
095     * does not match the mechanism, such as the sensor mounting assembly breaking
096     * off.
097     */
098    SyncCANcoder(6),
099    /**
100     * Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN) on
101     * the CTR Electronics' CANdi™ (this also requires setting
102     * FeedbackRemoteSensorID). Talon will update its position and velocity whenever
103     * the CTR Electronics' CANdi™ publishes its information on CAN bus, and the
104     * Talon internal rotor will not be used.
105     */
106    RemoteCANdiPWM1(9),
107    /**
108     * Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN) on
109     * the CTR Electronics' CANdi™ (this also requires setting
110     * FeedbackRemoteSensorID). Talon will update its position and velocity whenever
111     * the CTR Electronics' CANdi™ publishes its information on CAN bus, and the
112     * Talon internal rotor will not be used.
113     */
114    RemoteCANdiPWM2(10),
115    /**
116     * Use a quadrature encoder remotely attached to the two Sensor Inputs on the
117     * CTR Electronics' CANdi™ (this also requires setting FeedbackRemoteSensorID).
118     * Talon will update its position and velocity whenever the CTR Electronics'
119     * CANdi™ publishes its information on CAN bus, and the Talon internal rotor
120     * will not be used.
121     */
122    RemoteCANdiQuadrature(11),
123    /**
124     * Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached
125     * to the Sensor Input 1 (S1IN) on the CTR Electronics' CANdi™, which provides
126     * the best possible position and velocity for accuracy and bandwidth (this also
127     * requires setting FeedbackRemoteSensorID).  FusedCANdi was developed for
128     * applications such as swerve-azimuth.
129     */
130    FusedCANdiPWM1(12),
131    /**
132     * Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached
133     * to the Sensor Input 2 (S2IN) on the CTR Electronics' CANdi™, which provides
134     * the best possible position and velocity for accuracy and bandwidth (this also
135     * requires setting FeedbackRemoteSensorID).  FusedCANdi was developed for
136     * applications such as swerve-azimuth.
137     */
138    FusedCANdiPWM2(13),
139    /**
140     * Requires Phoenix Pro; Talon will fuse a qaudrature encoder remotely attached
141     * to the two Sensor Inputs on the CTR Electronics' CANdi™. This provides
142     * velocity and relative position measurements. This also requires setting
143     * FeedbackRemoteSensorID.
144     */
145    FusedCANdiQuadrature(14),
146    /**
147     * Requires Phoenix Pro; Talon will synchronize its internal rotor position
148     * against the pulse-width encoder attached to Sensor Input 1 (S1IN), then
149     * continue to use the rotor sensor for closed loop control (this also requires
150     * setting FeedbackRemoteSensorID).  The Talon will report if its internal
151     * position differs significantly from the reported PWM position.  SyncCANdi was
152     * developed for mechanisms where there is a risk of the CTR Electronics' CANdi™
153     * failing in such a way that it reports a position that does not match the
154     * mechanism, such as the sensor mounting assembly breaking off.
155     */
156    SyncCANdiPWM1(15),
157    /**
158     * Requires Phoenix Pro; Talon will synchronize its internal rotor position
159     * against the pulse-width encoder attached to Sensor Input 1 (S1IN), then
160     * continue to use the rotor sensor for closed loop control (this also requires
161     * setting FeedbackRemoteSensorID).  The Talon will report if its internal
162     * position differs significantly from the reported PWM position.  SyncCANdi was
163     * developed for mechanisms where there is a risk of the CTR Electronics' CANdi™
164     * failing in such a way that it reports a position that does not match the
165     * mechanism, such as the sensor mounting assembly breaking off.
166     */
167    SyncCANdiPWM2(16),;
168
169    public final int value;
170
171    FeedbackSensorSourceValue(int initValue)
172    {
173        this.value = initValue;
174    }
175
176    private static HashMap<Integer, FeedbackSensorSourceValue> _map = null;
177    static
178    {
179        _map = new HashMap<Integer, FeedbackSensorSourceValue>();
180        for (FeedbackSensorSourceValue type : FeedbackSensorSourceValue.values())
181        {
182            _map.put(type.value, type);
183        }
184    }
185
186    /**
187     * Gets FeedbackSensorSourceValue from specified value
188     * @param value Value of FeedbackSensorSourceValue
189     * @return FeedbackSensorSourceValue of specified value
190     */
191    public static FeedbackSensorSourceValue valueOf(int value)
192    {
193        FeedbackSensorSourceValue retval = _map.get(value);
194        if (retval != null) return retval;
195        return FeedbackSensorSourceValue.values()[0];
196    }
197}