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 FX.
015 * <p>
016 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus (this also
017 * requires setting FeedbackRemoteSensorID).  Talon FX will update its position
018 * and velocity whenever CANcoder publishes its information on CAN bus.
019 * <p>
020 * Choose FusedCANcoder (requires Phoenix Pro) and Talon FX will fuse another
021 * CANcoder's information with the internal rotor, which provides the best
022 * possible position and velocity for accuracy and bandwidth (this also requires
023 * setting FeedbackRemoteSensorID).  FusedCANcoder was developed for
024 * applications such as swerve-azimuth.
025 * <p>
026 * Choose SyncCANcoder (requires Phoenix Pro) and Talon FX will synchronize its
027 * internal rotor position against another CANcoder, then continue to use the
028 * rotor sensor for closed loop control (this also requires setting
029 * FeedbackRemoteSensorID).  The TalonFX will report if its internal position
030 * differs significantly from the reported CANcoder position.  SyncCANcoder was
031 * developed for mechanisms where there is a risk of the CANcoder failing in
032 * such a way that it reports a position that does not match the mechanism, such
033 * as the sensor mounting assembly breaking off.
034 * <p>
035 * Choose RemotePigeon2_Yaw, RemotePigeon2_Pitch, and RemotePigeon2_Roll to use
036 * another Pigeon2 on the same CAN bus (this also requires setting
037 * FeedbackRemoteSensorID).  Talon FX will update its position to match the
038 * selected value whenever Pigeon2 publishes its information on CAN bus. Note
039 * that the Talon FX position will be in rotations and not degrees.
040 * <p>
041 * Note: When the feedback source is changed to FusedCANcoder, the Talon FX
042 * needs a period of time to fuse before sensor-based (soft-limit, closed loop,
043 * etc.) features are used. This period of time is determined by the update
044 * frequency of the CANcoder's Position signal.
045 */
046public enum FeedbackSensorSourceValue
047{
048    RotorSensor(0),
049    RemoteCANcoder(1),
050    RemotePigeon2_Yaw(2),
051    RemotePigeon2_Pitch(3),
052    RemotePigeon2_Roll(4),
053    FusedCANcoder(5),
054    SyncCANcoder(6),;
055
056    public final int value;
057
058    FeedbackSensorSourceValue(int initValue)
059    {
060        this.value = initValue;
061    }
062
063    private static HashMap<Integer, FeedbackSensorSourceValue> _map = null;
064    static
065    {
066        _map = new HashMap<Integer, FeedbackSensorSourceValue>();
067        for (FeedbackSensorSourceValue type : FeedbackSensorSourceValue.values())
068        {
069            _map.put(type.value, type);
070        }
071    }
072
073    /**
074     * Gets FeedbackSensorSourceValue from specified value
075     * @param value Value of FeedbackSensorSourceValue
076     * @return FeedbackSensorSourceValue of specified value
077     */
078    public static FeedbackSensorSourceValue valueOf(int value)
079    {
080        FeedbackSensorSourceValue retval = _map.get(value);
081        if (retval != null) return retval;
082        return FeedbackSensorSourceValue.values()[0];
083    }
084}