Blender V2.61 - r43446
|
00001 00005 /*************************************************************************** 00006 frames_io.h - description 00007 ------------------------- 00008 begin : June 2006 00009 copyright : (C) 2006 Erwin Aertbelien 00010 email : firstname.lastname@mech.kuleuven.ac.be 00011 00012 History (only major changes)( AUTHOR-Description ) : 00013 00014 *************************************************************************** 00015 * This library is free software; you can redistribute it and/or * 00016 * modify it under the terms of the GNU Lesser General Public * 00017 * License as published by the Free Software Foundation; either * 00018 * version 2.1 of the License, or (at your option) any later version. * 00019 * * 00020 * This library is distributed in the hope that it will be useful, * 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00023 * Lesser General Public License for more details. * 00024 * * 00025 * You should have received a copy of the GNU Lesser General Public * 00026 * License along with this library; if not, write to the Free Software * 00027 * Foundation, Inc., 51 Franklin Street, * 00028 * Fifth Floor, Boston, MA 02110-1301, USA. * 00029 * * 00030 ***************************************************************************/ 00031 00032 #include "utilities/error.h" 00033 #include "utilities/error_stack.h" 00034 #include "frames.hpp" 00035 #include "frames_io.hpp" 00036 00037 #include <stdlib.h> 00038 #include <ctype.h> 00039 #include <string.h> 00040 #include <iostream> 00041 00042 namespace KDL { 00043 00044 00045 std::ostream& operator << (std::ostream& os,const Vector& v) { 00046 os << "[" << std::setw(KDL_FRAME_WIDTH) << v(0) << "," << std::setw(KDL_FRAME_WIDTH)<<v(1) 00047 << "," << std::setw(KDL_FRAME_WIDTH) << v(2) << "]"; 00048 return os; 00049 } 00050 00051 std::ostream& operator << (std::ostream& os,const Twist& v) { 00052 os << "[" << std::setw(KDL_FRAME_WIDTH) << v.vel(0) 00053 << "," << std::setw(KDL_FRAME_WIDTH) << v.vel(1) 00054 << "," << std::setw(KDL_FRAME_WIDTH) << v.vel(2) 00055 << "," << std::setw(KDL_FRAME_WIDTH) << v.rot(0) 00056 << "," << std::setw(KDL_FRAME_WIDTH) << v.rot(1) 00057 << "," << std::setw(KDL_FRAME_WIDTH) << v.rot(2) 00058 << "]"; 00059 return os; 00060 } 00061 00062 std::ostream& operator << (std::ostream& os,const Wrench& v) { 00063 os << "[" << std::setw(KDL_FRAME_WIDTH) << v.force(0) 00064 << "," << std::setw(KDL_FRAME_WIDTH) << v.force(1) 00065 << "," << std::setw(KDL_FRAME_WIDTH) << v.force(2) 00066 << "," << std::setw(KDL_FRAME_WIDTH) << v.torque(0) 00067 << "," << std::setw(KDL_FRAME_WIDTH) << v.torque(1) 00068 << "," << std::setw(KDL_FRAME_WIDTH) << v.torque(2) 00069 << "]"; 00070 return os; 00071 } 00072 00073 00074 std::ostream& operator << (std::ostream& os,const Rotation& R) { 00075 #ifdef KDL_ROTATION_PROPERTIES_RPY 00076 double r,p,y; 00077 R.GetRPY(r,p,y); 00078 os << "[RPY]"<<endl; 00079 os << "["; 00080 os << std::setw(KDL_FRAME_WIDTH) << r << ","; 00081 os << std::setw(KDL_FRAME_WIDTH) << p << ","; 00082 os << std::setw(KDL_FRAME_WIDTH) << y << "]"; 00083 #else 00084 # ifdef KDL_ROTATION_PROPERTIES_EULER 00085 double z,y,x; 00086 R.GetEulerZYX(z,y,x); 00087 os << "[EULERZYX]"<<endl; 00088 os << "["; 00089 os << std::setw(KDL_FRAME_WIDTH) << z << ","; 00090 os << std::setw(KDL_FRAME_WIDTH) << y << ","; 00091 os << std::setw(KDL_FRAME_WIDTH) << x << "]"; 00092 # else 00093 os << "["; 00094 for (int i=0;i<=2;i++) { 00095 os << std::setw(KDL_FRAME_WIDTH) << R(i,0) << "," << 00096 std::setw(KDL_FRAME_WIDTH) << R(i,1) << "," << 00097 std::setw(KDL_FRAME_WIDTH) << R(i,2); 00098 if (i<2) 00099 os << ";"<< std::endl << " "; 00100 else 00101 os << "]"; 00102 } 00103 # endif 00104 #endif 00105 return os; 00106 } 00107 00108 std::ostream& operator << (std::ostream& os, const Frame& T) 00109 { 00110 os << "[" << T.M << std::endl<< T.p << "]"; 00111 return os; 00112 } 00113 00114 std::ostream& operator << (std::ostream& os,const Vector2& v) { 00115 os << "[" << std::setw(KDL_FRAME_WIDTH) << v(0) << "," << std::setw(KDL_FRAME_WIDTH)<<v(1) 00116 << "]"; 00117 return os; 00118 } 00119 00120 // Rotation2 gives back an angle in degrees with the << and >> operators. 00121 std::ostream& operator << (std::ostream& os,const Rotation2& R) { 00122 os << "[" << R.GetRot()*rad2deg << "]"; 00123 return os; 00124 } 00125 00126 std::ostream& operator << (std::ostream& os, const Frame2& T) 00127 { 00128 os << T.M << T.p; 00129 return os; 00130 } 00131 00132 std::istream& operator >> (std::istream& is,Vector& v) 00133 { IOTrace("Stream input Vector (vector or ZERO)"); 00134 char storage[10]; 00135 EatWord(is,"[]",storage,10); 00136 if (storage[0]=='\0') { 00137 Eat(is,'['); 00138 is >> v(0); 00139 Eat(is,','); 00140 is >> v(1); 00141 Eat(is,','); 00142 is >> v(2); 00143 EatEnd(is,']'); 00144 IOTracePop(); 00145 return is; 00146 } 00147 if (strcmp(storage,"ZERO")==0) { 00148 v = Vector::Zero(); 00149 IOTracePop(); 00150 return is; 00151 } 00152 throw Error_Frame_Vector_Unexpected_id(); 00153 } 00154 00155 std::istream& operator >> (std::istream& is,Twist& v) 00156 { IOTrace("Stream input Twist"); 00157 Eat(is,'['); 00158 is >> v.vel(0); 00159 Eat(is,','); 00160 is >> v.vel(1); 00161 Eat(is,','); 00162 is >> v.vel(2); 00163 Eat(is,','); 00164 is >> v.rot(0); 00165 Eat(is,','); 00166 is >> v.rot(1); 00167 Eat(is,','); 00168 is >> v.rot(2); 00169 EatEnd(is,']'); 00170 IOTracePop(); 00171 return is; 00172 } 00173 00174 std::istream& operator >> (std::istream& is,Wrench& v) 00175 { IOTrace("Stream input Wrench"); 00176 Eat(is,'['); 00177 is >> v.force(0); 00178 Eat(is,','); 00179 is >> v.force(1); 00180 Eat(is,','); 00181 is >> v.force(2); 00182 Eat(is,','); 00183 is >> v.torque(0); 00184 Eat(is,','); 00185 is >> v.torque(1); 00186 Eat(is,','); 00187 is >> v.torque(2); 00188 EatEnd(is,']'); 00189 IOTracePop(); 00190 return is; 00191 } 00192 00193 std::istream& operator >> (std::istream& is,Rotation& r) 00194 { IOTrace("Stream input Rotation (Matrix or EULERZYX, EULERZYZ,RPY, ROT, IDENTITY)"); 00195 char storage[10]; 00196 EatWord(is,"[]",storage,10); 00197 if (storage[0]=='\0') { 00198 Eat(is,'['); 00199 for (int i=0;i<3;i++) { 00200 is >> r(i,0); 00201 Eat(is,',') ; 00202 is >> r(i,1); 00203 Eat(is,','); 00204 is >> r(i,2); 00205 if (i<2) 00206 Eat(is,';'); 00207 else 00208 EatEnd(is,']'); 00209 } 00210 IOTracePop(); 00211 return is; 00212 } 00213 Vector v; 00214 if (strcmp(storage,"EULERZYX")==0) { 00215 is >> v; 00216 v=v*deg2rad; 00217 r = Rotation::EulerZYX(v(0),v(1),v(2)); 00218 IOTracePop(); 00219 return is; 00220 } 00221 if (strcmp(storage,"EULERZYZ")==0) { 00222 is >> v; 00223 v=v*deg2rad; 00224 r = Rotation::EulerZYZ(v(0),v(1),v(2)); 00225 IOTracePop(); 00226 return is; 00227 } 00228 if (strcmp(storage,"RPY")==0) { 00229 is >> v; 00230 v=v*deg2rad; 00231 r = Rotation::RPY(v(0),v(1),v(2)); 00232 IOTracePop(); 00233 return is; 00234 } 00235 if (strcmp(storage,"ROT")==0) { 00236 is >> v; 00237 double angle; 00238 Eat(is,'['); 00239 is >> angle; 00240 EatEnd(is,']'); 00241 r = Rotation::Rot(v,angle*deg2rad); 00242 IOTracePop(); 00243 return is; 00244 } 00245 if (strcmp(storage,"IDENTITY")==0) { 00246 r = Rotation::Identity(); 00247 IOTracePop(); 00248 return is; 00249 } 00250 throw Error_Frame_Rotation_Unexpected_id(); 00251 return is; 00252 } 00253 00254 std::istream& operator >> (std::istream& is,Frame& T) 00255 { IOTrace("Stream input Frame (Rotation,Vector) or DH[...]"); 00256 char storage[10]; 00257 EatWord(is,"[",storage,10); 00258 if (storage[0]=='\0') { 00259 Eat(is,'['); 00260 is >> T.M; 00261 is >> T.p; 00262 EatEnd(is,']'); 00263 IOTracePop(); 00264 return is; 00265 } 00266 if (strcmp(storage,"DH")==0) { 00267 double a,alpha,d,theta; 00268 Eat(is,'['); 00269 is >> a; 00270 Eat(is,','); 00271 is >> alpha; 00272 Eat(is,','); 00273 is >> d; 00274 Eat(is,','); 00275 is >> theta; 00276 EatEnd(is,']'); 00277 T = Frame::DH(a,alpha*deg2rad,d,theta*deg2rad); 00278 IOTracePop(); 00279 return is; 00280 } 00281 throw Error_Frame_Frame_Unexpected_id(); 00282 return is; 00283 } 00284 00285 std::istream& operator >> (std::istream& is,Vector2& v) 00286 { IOTrace("Stream input Vector2"); 00287 Eat(is,'['); 00288 is >> v(0); 00289 Eat(is,','); 00290 is >> v(1); 00291 EatEnd(is,']'); 00292 IOTracePop(); 00293 return is; 00294 } 00295 std::istream& operator >> (std::istream& is,Rotation2& r) 00296 { IOTrace("Stream input Rotation2"); 00297 Eat(is,'['); 00298 double val; 00299 is >> val; 00300 r.Rot(val*deg2rad); 00301 EatEnd(is,']'); 00302 IOTracePop(); 00303 return is; 00304 } 00305 std::istream& operator >> (std::istream& is,Frame2& T) 00306 { IOTrace("Stream input Frame2"); 00307 is >> T.M; 00308 is >> T.p; 00309 IOTracePop(); 00310 return is; 00311 } 00312 00313 } // namespace Frame