JointTorques.cpp
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 #include "JointTorques.h" 00028 00029 using namespace std; 00030 using namespace nemo; 00031 00032 namespace rci { 00033 00034 JointTorquesPtr JointTorques::fromNm(double value) { 00035 return JointTorquesPtr(new JointTorques(RealVector(value))); 00036 } 00037 00038 JointTorquesPtr JointTorques::fromNm(const nemo::RealVector& values) { 00039 return JointTorquesPtr(new JointTorques(values)); 00040 } 00041 00042 JointTorques::JointTorques() : 00043 JointValues() { 00044 } 00045 00046 JointTorques::JointTorques(double value) : 00047 JointValues(value) { 00048 } 00049 00050 JointTorques::JointTorques(const RealVector& values) : 00051 JointValues(values) { 00052 } 00053 00054 JointTorquesPtr JointTorques::create(unsigned int dimension, double value) { 00055 RealVector values = RealVector(dim(dimension), value); 00056 return JointTorques::fromNm(values); 00057 } 00058 00059 double JointTorques::Nm(unsigned int index) const { 00060 if (index >= _values.dimension()) { 00061 std::stringstream errMsg; 00062 errMsg << "[JointTorques::Nm] index=" << index << " out of bounds 0.." 00063 << _values.dimension() << "!"; 00064 throw std::runtime_error(errMsg.str()); 00065 } 00066 return _values[index]; 00067 } 00068 00069 nemo::RealVector JointTorques::NmVector() const { 00070 return _values; 00071 } 00072 00073 std::string JointTorques::print() const { 00074 ostringstream outstream(ostringstream::out); 00075 outstream.precision(3); // Precision when printing double values 00076 outstream << "JointTorques<"; 00077 for (unsigned int i = 0; i < this->getDimension(); ++i) { 00078 if (i > 0) { 00079 outstream << ","; 00080 } 00081 outstream << this->asDouble(i); 00082 } 00083 outstream << ">(N*cm)" << std::endl; 00084 return outstream.str(); 00085 } 00086 00087 void JointTorques::setFromNm(unsigned int index, double value) { 00088 if (index >= _values.dimension()) { 00089 std::stringstream errMsg; 00090 errMsg << "[JointTorques::setFromNm] index=" << index 00091 << " out of bounds 0.." << _values.dimension() << "!"; 00092 throw std::runtime_error(errMsg.str()); 00093 } 00094 _values[index] = value; 00095 } 00096 00097 void JointTorques::setFromNm(const nemo::RealVector& values) { 00098 if (values.dimension() != _values.dimension()) { 00099 std::stringstream errMsg; 00100 errMsg << "[JointTorques::setFromNm] Dimension mismatch! Expected dim=" 00101 << _values.dimension() << " but got dim=" << values.dimension() 00102 << "!"; 00103 throw std::runtime_error(errMsg.str()); 00104 } 00105 _values = values; 00106 } 00107 00108 JointTorquesPtr JointTorques::copy(const JointTorques& torques) { 00109 return JointTorquesPtr(new JointTorques(torques)); 00110 } 00111 00112 }
Generated on Thu Aug 2 14:02:49 2012 for RCI by 1.6.3