Skip to content

# File evamSteeringActuator.h

File List > src > evamSteeringActuator.h

Go to the documentation of this file

    #pragma once
    #include <Arduino.h>

    namespace evam
    {
        template <class Driver, signed short kLeftPos = -1000, signed short kCenterPos = 0, signed short kRightPos = 1000>
        class SteeringActuator : public Driver
        {
            static_assert(kLeftPos >= -1000 && kLeftPos <= 1000, "kLeftPos out of range");
            static_assert(kCenterPos >= -1000 && kCenterPos <= 1000, "kCenterPos out of range");
            static_assert(kRightPos >= -1000 && kRightPos <= 1000, "kRightPos out of range");

        private:
            signed short mLeftPos = kLeftPos;
            signed short mCenterPos = kCenterPos;
            signed short mRightPos = kRightPos;

            signed short compute(signed short aLevel) const
            {
                if (aLevel < 0)
                    return map(constrain(aLevel, -1000, 0), -1000, 0, mLeftPos, mCenterPos);
                else
                    return map(constrain(aLevel, 0, 1000), 0, 1000, mCenterPos, mRightPos);
            }

        public:
            void SetupRange(signed short aLeftPos, signed short aCenterPos, signed short aRightPos)
            {
                SetLeftPos(aLeftPos);
                SetCenterPos(aCenterPos);
                SetRightPos(aRightPos);
            }

            void SetLeftPos(signed short aValue)
            {
                mLeftPos = constrain(aValue, -1000, 1000);
            }

            signed short GetLeftPos() const
            {
                return mLeftPos;
            }

            void SetCenterPos(signed short aValue)
            {
                mCenterPos = constrain(aValue, -1000, 1000);
            }

            signed short GetCenterPos() const
            {
                return mCenterPos;
            }

            void SetRightPos(signed short aValue)
            {
                mRightPos = constrain(aValue, -1000, 1000);
            }

            signed short GetRightPos() const
            {
                return mRightPos;
            }

            void Go(signed short aLevel)
            {
                Driver::actBipolar(compute(aLevel));
            }
        };
    }