Source

KODE / include / kode / joints / Motor.hpp

Full commit
/*
  This file is part of the KODE.

    KODE Physics Library
    Copyright (C) 2013-2014  Daniel Kohler Osmari

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

        * the Apache License, Version 2.0.

    This program 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 Lesser General Public License and the Apache License for more
    details.

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

    You may obtain a copy of the Apache License at
       http://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef KODE_MOTOR_H
#define KODE_MOTOR_H

#include <utility>

#include <kode/joints/Joint.hpp>


namespace kode {

    class Joint;
    class Hinge;

    class Motor {
    protected:
        enum class State {
            Unlimited = 0,
            LowStop = -1,
            HighStop = 1
        };

        State limited    = State::Unlimited;
        Real  loStop     = -Math::Infinity;
        Real  hiStop     = +Math::Infinity;
        Real  limitError = 0;
        Real  stopERP    = 0;
        Real  stopCFM    = 0;
        Real  bounciness = 0;

        bool powered     = false;
        Real targetVel   = 0;
        Real maxForce    = 0;
        Real normalCFM   = 0;
        Real fudgeFactor = 1;

        // do not allow slicing
        Motor() noexcept = default;
        Motor(Motor&&) noexcept = default;
        Motor& operator=(Motor&&) noexcept = default;
        // the above also suppresses the default copy constructor/assignment

    public:

        bool testPowerLimit(Real pos); /// return false if the motor will do nothing

        void setTargetVel(Real v);
        void setMaxForce(Real f);

        void setBounciness(Real b);
        Real getBounciness() const noexcept;        

    };

}

#endif