Libbarrett  1.2.4
include/barrett/systems/detail/ramp-inl.h
00001 /*
00002         Copyright 2009, 2010 Barrett Technology <support@barrett.com>
00003 
00004         This file is part of libbarrett.
00005 
00006         This version of libbarrett is free software: you can redistribute it
00007         and/or modify it under the terms of the GNU General Public License as
00008         published by the Free Software Foundation, either version 3 of the
00009         License, or (at your option) any later version.
00010 
00011         This version of libbarrett is distributed in the hope that it will be
00012         useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License along
00017         with this version of libbarrett.  If not, see
00018         <http://www.gnu.org/licenses/>.
00019 
00020         Further, non-binding information about licensing is available at:
00021         <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes>
00022 */
00023 
00024 /*
00025  * ramp-inl.h
00026  *
00027  *  Created on: May 18, 2011
00028  *      Author: dc
00029  */
00030 
00031 
00032 namespace barrett {
00033 namespace systems {
00034 
00035 
00036 inline bool Ramp::isRunning() {
00037         return curGain != 0.0  ||  finalGain != 0.0;
00038 }
00039 
00040 inline void Ramp::start() {
00041         // curGain is written and read in operate(), so it needs to be locked.
00042         BARRETT_SCOPED_LOCK(getEmMutex());
00043         curGain = finalGain = gain;
00044 }
00045 inline void Ramp::stop() {
00046         // curGain is written and read in operate(), so it needs to be locked.
00047         BARRETT_SCOPED_LOCK(getEmMutex());
00048         curGain = finalGain = 0.0;
00049 }
00050 inline void Ramp::setSlope(double slope) {
00051         gain = slope;
00052         if (isRunning()) {
00053                 start();
00054         }
00055 }
00056 
00057 inline void Ramp::reset() {
00058         setOutput(0.0);
00059 }
00060 inline void Ramp::setOutput(double newOutput) {
00061         // y is written and read in operate(), so it needs to be locked.
00062         BARRETT_SCOPED_LOCK(getEmMutex());
00063         y = newOutput;
00064 }
00065 
00066 inline void Ramp::smoothStart(double transitionDuration) {
00067         finalGain = gain;
00068         setCurvature(transitionDuration);
00069 }
00070 inline void Ramp::smoothStop(double transitionDuration) {
00071         finalGain = 0.0;
00072         setCurvature(transitionDuration);
00073 }
00074 inline void Ramp::smoothSetSlope(double slope, double transitionDuration) {
00075         gain = slope;
00076         if (isRunning()) {
00077                 smoothStart(transitionDuration);
00078         }
00079 }
00080 
00081 
00082 inline void Ramp::setCurvature(double transitionDuration) {
00083         assert(transitionDuration > 0.0);
00084 
00085         // curvature is written and read in operate(), so it needs to be locked.
00086         BARRETT_SCOPED_LOCK(getEmMutex());
00087         curvature = (finalGain - curGain) / transitionDuration;
00088 }
00089 
00090 
00091 }
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines