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.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.  Choose RemoteCANcoder to use another CANcoder on
015 *  the same CAN bus (this also requires setting FeedbackRemoteSensorID).  Talon
016 *  FX will update its position and velocity whenever CANcoder publishes its
017 *  information on CAN bus.  Choose FusedCANcoder and Talon FX will fuse another
018 *  CANcoder's information with the internal rotor, which provides the best
019 *  possible position and velocity for accuracy and bandwidth (note this
020 *  requires setting FeedbackRemoteSensorID).  FusedCANcoder was developed for
021 *  applications such as swerve-azimuth.
022 * <p>
023 *  Note: When the Talon Source is changed to FusedCANcoder, the Talon needs a
024 *  period of time to fuse before sensor-based (soft-limit, closed loop, etc.)
025 *  features are used. This period of time is determined by the update frequency
026 *  of the CANcoder's Position signal.
027 */
028public enum FeedbackSensorSourceValue
029{
030    RotorSensor(0),
031    RemoteCANcoder(1),
032    FusedCANcoder(5),;
033
034    public final int value;
035
036    FeedbackSensorSourceValue(int initValue)
037    {
038        this.value = initValue;
039    }
040
041    private static HashMap<Integer, FeedbackSensorSourceValue> _map = null;
042    static
043    {
044        _map = new HashMap<Integer, FeedbackSensorSourceValue>();
045        for (FeedbackSensorSourceValue type : FeedbackSensorSourceValue.values())
046        {
047            _map.put(type.value, type);
048        }
049    }
050
051    /**
052     * Gets FeedbackSensorSourceValue from specified value
053     * @param value Value of FeedbackSensorSourceValue
054     * @return FeedbackSensorSourceValue of specified value
055     */
056    public static FeedbackSensorSourceValue valueOf(int value)
057    {
058        FeedbackSensorSourceValue retval = _map.get(value);
059        if(retval != null) return retval;
060        return FeedbackSensorSourceValue.values()[0];
061    }
062}