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 * Static Feedforward Sign during position closed loop
013 * <p>
014 * This determines the sign of the applied kS during position closed-loop modes.
015 * The default behavior uses the velocity reference sign. This works well with
016 * velocity closed loop, Motion Magic® controls, and position closed loop when
017 * velocity reference is specified (motion profiling).
018 * <p>
019 * However, when using position closed loop with zero velocity reference (no
020 * motion profiling), the application may want to apply static feedforward based
021 * on the closed loop error sign instead. When doing so, we recommend the
022 * minimal amount of kS, otherwise the motor output may dither when closed loop
023 * error is near zero.
024 */
025public enum StaticFeedforwardSignValue
026{
027    UseVelocitySign(0),
028    UseClosedLoopSign(1),;
029
030    public final int value;
031
032    StaticFeedforwardSignValue(int initValue)
033    {
034        this.value = initValue;
035    }
036
037    private static HashMap<Integer, StaticFeedforwardSignValue> _map = null;
038    static
039    {
040        _map = new HashMap<Integer, StaticFeedforwardSignValue>();
041        for (StaticFeedforwardSignValue type : StaticFeedforwardSignValue.values())
042        {
043            _map.put(type.value, type);
044        }
045    }
046
047    /**
048     * Gets StaticFeedforwardSignValue from specified value
049     * @param value Value of StaticFeedforwardSignValue
050     * @return StaticFeedforwardSignValue of specified value
051     */
052    public static StaticFeedforwardSignValue valueOf(int value)
053    {
054        StaticFeedforwardSignValue retval = _map.get(value);
055        if (retval != null) return retval;
056        return StaticFeedforwardSignValue.values()[0];
057    }
058}