/*    
    This file is a part of Stonefish.

    Stonefish is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Stonefish is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

//
//  SimpleThruster.h
//  Stonefish
//
//  Created by Patryk Cieslak on 07/04/2024.
//  Copyright (c) 2024 Patryk Cieslak. All rights reserved.
//

#ifndef __Stonefish_SimpleThruster__
#define __Stonefish_SimpleThruster__

#include "actuators/LinkActuator.h"

namespace sf
{
    //! A class representing a thruster.
    class SimpleThruster : public LinkActuator
    {
    public:
        //! A constructor.
        /*!
         \param uniqueName a name for the thruster
         \param propeller a pointer to a rigid body representing the propeller
         \param rightHand a flag to indicate if the propeller is right hand (clockwise rotation)
        */
        SimpleThruster(std::string uniqueName, SolidEntity* propeller, bool rightHand, bool inverted = false);
        
        //! A destructor.
        ~SimpleThruster();
        
        //! A method used to update the internal state of the thruster.
        /*!
         \param dt a time step of the simulation [s]
         */
        void Update(Scalar dt);
        
        //! A method implementing the rendering of the thruster.
        std::vector<Renderable> Render();
        
        //! A method setting the new value of the setpoint.
        /*!
         \param thrust the thrust generated by the thruster
         \param torque the torque generated by the thruster
         */
        void setSetpoint(Scalar thrust, Scalar torque);

        //! A method used to set the thrust limits.
        void setThrustLimits(Scalar lower, Scalar upper);

        //! A method returning the requested setpoint.
        Scalar getThrustSetpoint() const;

        //! A method returning the generated thrust.
        Scalar getThrust() const;

        //! A method returning the generated torque.
        Scalar getTorque() const;
        
        //! A method returning the angular position of the propeller (for visualization only) [rad]
        Scalar getAngle() const;

        //! A method returning the type of the actuator.
        ActuatorType getType() const;
        
    private:
        void WatchdogTimeout() override;

        //Params
        SolidEntity* prop;
        bool RH;
        bool inv;
        std::pair<Scalar, Scalar> limits;
        
        //States
        Scalar theta;
        Scalar thrust;
        Scalar torque;
        Scalar sThrust;
        Scalar sTorque;
    };
}

#endif
