JointImpedance.h

Go to the documentation of this file.
00001 /* ============================================================
00002  *
00003  * This file is a part of RCI project
00004  *
00005  * Copyright (C) 2011 by Arne Nordmann <anordman at cor-lab dot uni-bielefeld dot de>
00006  *
00007  * This file may be licensed under the terms of the
00008  * GNU Lesser General Public License Version 3 (the ``LGPL''),
00009  * or (at your option) any later version.
00010  *
00011  * Software distributed under the License is distributed
00012  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
00013  * express or implied. See the LGPL for the specific language
00014  * governing rights and limitations.
00015  *
00016  * You should have received a copy of the LGPL along with this
00017  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
00018  * or write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  * The development of this software was supported by:
00022  *   CoR-Lab, Research Institute for Cognition and Robotics
00023  *     Bielefeld University
00024  *
00025  * ============================================================ */
00026 
00027 #pragma once
00028 
00029 #include "rci/dto/JointValues.h"
00030 
00031 namespace rci {
00032 
00033 class JointImpedance;
00034 typedef boost::shared_ptr<JointImpedance> JointImpedancePtr;
00035 class JointStiffness;
00036 typedef boost::shared_ptr<JointStiffness> JointStiffnessPtr;
00037 class JointDamping;
00038 typedef boost::shared_ptr<JointDamping> JointDampingPtr;
00039 
00047 class JointStiffness: public JointValues {
00048 
00049 public:
00054     JointStiffness();
00055 
00063     JointStiffness(const nemo::RealVector& values);
00064 
00072     JointStiffness(double stiffness);
00073 
00083     JointStiffness(unsigned int dim, double stiffness);
00084 
00090     JointStiffness operator[](unsigned int index) const;
00091 
00092 protected:
00096     virtual std::string print() const;
00097 };
00098 
00108 class JointDamping: public JointValues {
00109 
00110 public:
00115     JointDamping();
00116 
00124     JointDamping(const nemo::RealVector& values);
00125 
00133     JointDamping(double damping);
00134 
00144     JointDamping(unsigned int dim, double damping);
00145 
00153     JointDamping operator[](unsigned int index) const;
00154 
00155 protected:
00159     virtual std::string print() const;
00160 };
00161 
00169 class JointImpedance: public JointValues {
00170 
00171 public:
00176     JointImpedance();
00177 
00182     JointImpedance(double stiffness, double damping);
00183 
00195     JointImpedance(const nemo::RealVector& values);
00196 
00207     JointImpedance(const nemo::RealVector& stiffness,
00208             const nemo::RealVector& damping);
00209 
00219     JointImpedance(JointStiffness stiffness, JointDamping damping);
00220 
00229     static JointImpedancePtr copy(const JointImpedance& impedance);
00230 
00239     static JointImpedancePtr create(const nemo::RealVector& values);
00240 
00246     JointStiffness getStiffness() const;
00247 
00252     unsigned int getDimension() const;
00253 
00262     JointStiffness getStiffness(unsigned int index) const;
00263 
00269     JointDamping getDamping() const;
00270 
00279     JointDamping getDamping(unsigned int index) const;
00280 
00288     JointImpedance operator[](unsigned int index) const;
00289 
00303     virtual double asDouble(unsigned int index) const;
00304 
00313     virtual nemo::RealVector asDoubleVector() const;
00314 
00324     virtual void setValue(unsigned int index, double value);
00325 
00339     template<class DTOType>
00340     void merge(std::vector<boost::shared_ptr<DTOType> >& inputDTOs) {
00341         // Check dimensions of input DTOs and my own dimension
00342         unsigned int inputdimension = 0;
00343         for (unsigned int inputdto = 0; inputdto < inputDTOs.size();
00344                 ++inputdto) {
00345             inputdimension += inputDTOs[inputdto]->getDimension();
00346         }
00347         if (inputdimension != this->getDimension()) {
00348             throw std::runtime_error(
00349                     "Merging failed: My own dimension and the dimension of the summarized input JointImpedance DTOs doesn`t agree.");
00350         }
00351 
00352         // Start merging
00353         unsigned int cursor = 0;
00354         nemo::RealVector dampings(nemo::dim(this->getDimension())), stiffnesses(
00355                 nemo::dim(this->getDimension()));
00356         for (unsigned int inputdto = 0; inputdto < inputDTOs.size();
00357                 ++inputdto) {
00358             for (unsigned int inputdim = 0;
00359                     inputdim < inputDTOs[inputdto]->getDimension();
00360                     ++inputdim) {
00361                 this->_stiffness.setValue(cursor,
00362                         inputDTOs[inputdto]->asDouble(2 * inputdim));
00363                 this->_damping.setValue(cursor++,
00364                         inputDTOs[inputdto]->asDouble(2 * inputdim + 1));
00365             }
00366         }
00367     }
00368 
00379     template<class DTOType>
00380     std::vector<JointImpedancePtr> split() const {
00381         std::vector<JointImpedancePtr> vec;
00382 
00383         for (unsigned int cursor = 0; cursor < getDimension(); ++cursor) {
00384             nemo::RealVector values(nemo::dim(2), this->asDouble(2 * cursor));
00385             values[1] = this->asDouble(2 * cursor + 1);
00386             vec.push_back(JointImpedancePtr(new JointImpedance(values)));
00387         }
00388 
00389         return vec;
00390     }
00391 
00392 protected:
00396     virtual std::string print() const;
00397 
00401     JointStiffness _stiffness;
00402 
00406     JointDamping _damping;
00407 };
00408 
00409 }
Generated on Thu Aug 2 14:02:49 2012 for RCI by  doxygen 1.6.3