Source

KODE / src / joints / Motor.cpp

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
*/

#include <stdexcept>

#include <kode/joints/Motor.hpp>

namespace kode {


    bool
    Motor::testPowerLimit(Real pos)
    {
        if (pos <= loStop) {
            limited = State::LowStop;
            limitError = pos - loStop;
        } else if (pos >= hiStop) {
            limited = State::HighStop;
            limitError = pos - hiStop;
        } else
            limited = State::Unlimited;

        powered = maxForce > 0;

        // simultaneously constrained on both stops
        if (loStop == hiStop)
            powered = false;

        return limited!=State::Unlimited || powered;
    }


    void
    Motor::setTargetVel(Real v)
    {
        targetVel = v;
    }


    void
    Motor::setMaxForce(Real f)
    {
        maxForce = f;
    }



    void
    Motor::setBounciness(Real b)
    {
        if (b < 0)
            throw std::domain_error{"bounciness can't be negative"};
        bounciness = b;
    }


    Real
    Motor::getBounciness() const noexcept
    {
        return bounciness;
    }

}