urdf2gazebo.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 * 
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 * 
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 * 
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 * 
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 #ifndef URDF2GAZEBO_HH
00035 #define URDF2GAZEBO_HH
00036 
00037 #include <cstdio>
00038 #include <cstdlib>
00039 #include <cmath>
00040 
00041 #include <vector>
00042 #include <string>
00043 
00044 #include <sstream>
00045 #include <map>
00046 #include <vector>
00047 
00048 #include <urdf/model.h>
00049 #include <urdf_interface/link.h>
00050 
00051 //#include "LinearMath/btTransform.h"
00052 //#include "LinearMath/btVector3.h"
00053 
00054 #include "ode/mass.h"
00055 #include "ode/rotation.h"
00056 
00057 #include "math/Pose.hh"
00058 
00059 namespace urdf2gazebo
00060 {
00061   double rad2deg(double v) { return v * 180.0 / M_PI; };
00062 
00063   class GazeboExtension
00064   {
00065     public:
00066       // HACK: add for now, since we are reducing fixed joints and removing links
00067       std::string original_reference;
00068       gazebo::math::Pose reduction_transform;
00069 
00070       // visual
00071       std::string material;
00072 
00073       // body, default off
00074       bool setStaticFlag;
00075       bool turnGravityOff;
00076       bool is_dampingFactor;
00077       double dampingFactor;
00078       bool is_maxVel;
00079       double maxVel;
00080       bool is_minDepth;
00081       double minDepth;
00082       bool selfCollide;
00083 
00084       // geom, contact dynamics
00085       bool is_mu1, is_mu2, is_kp, is_kd, is_genTexCoord;
00086       double mu1, mu2, kp, kd;
00087       std::string fdir1;
00088       bool genTexCoord;
00089       bool is_laserRetro;
00090       double laserRetro;
00091 
00092       // joint, joint limit dynamics
00093       bool is_stopKp, is_stopKd, is_initial_joint_position, is_fudgeFactor;
00094       double stopKp, stopKd, initial_joint_position, fudgeFactor;
00095       bool provideFeedback;
00096 
00097       // blobs into body or robot
00098       std::vector<TiXmlElement*> blobs;
00099 
00100       GazeboExtension()
00101       {
00102         //initialize
00103         material.clear();
00104         setStaticFlag = false;
00105         turnGravityOff = false;
00106         is_dampingFactor = false;
00107         is_maxVel = false;
00108         is_minDepth = false;
00109         is_mu1 = false;
00110         fdir1.clear();
00111         is_mu2 = false;
00112         is_kp = false;
00113         is_kd = false;
00114         is_genTexCoord = false;
00115         selfCollide = false;
00116         is_laserRetro = false;
00117         is_stopKp = false;
00118         is_stopKd = false;
00119         is_initial_joint_position = false;
00120         is_fudgeFactor = false;
00121         provideFeedback = false;
00122         blobs.clear();
00123       };
00124 
00125       GazeboExtension(const GazeboExtension &ge)
00126       {
00127         //initialize
00128         material = ge.material;
00129         setStaticFlag = ge.setStaticFlag;
00130         turnGravityOff = ge.turnGravityOff;
00131         is_dampingFactor = ge.is_dampingFactor;
00132         is_maxVel = ge.is_maxVel;
00133         is_minDepth = ge.is_minDepth;
00134         is_mu1 = ge.is_mu1;
00135         is_mu2 = ge.is_mu2;
00136         is_kp = ge.is_kp;
00137         is_kd = ge.is_kd;
00138         is_genTexCoord = ge.is_genTexCoord;
00139         selfCollide = ge.selfCollide;
00140         is_laserRetro = ge.is_laserRetro;
00141         is_stopKp = ge.is_stopKp;
00142         is_stopKd = ge.is_stopKd;
00143         is_initial_joint_position = ge.is_initial_joint_position;
00144         is_fudgeFactor = ge.is_fudgeFactor;
00145         provideFeedback = ge.provideFeedback;
00146         original_reference = ge.original_reference;
00147         reduction_transform = ge.reduction_transform;
00148         blobs = ge.blobs;
00149       };
00150   };
00151 
00152 /*
00153       gazebo::math::Pose InverseTimes(const gazebo::math::Pose &_pose_a, const gazebo::math::Pose &_pose_b) const;
00154       gazebo::math::Pose GetInverse(const gazebo::math::Pose &_pose) const;
00155 
00157   urdf::Pose URDF2Gazebo::InverseTimes(const urdf::Pose &_pose_a, const urdf::Pose &_pose_b) const
00158   {
00159     urdf::Vector3 v = _pose_b.position + _pose_a.position*-1;
00160     return urdf::Pose(_pose_a.rotation.RotateVector(v), _pose_a.rotation.GetInverse()*_pose_b.rotation);
00161   }
00162   urdf::Pose URDF2Gazebo::GetInverse(const urdf::Pose &_pose) const
00163   {
00164     urdf::Rotation inv = _pose.rotation.GetInverse();
00165     return urdf::Pose(-1*_pose.position, inv);
00166   }
00167   urdf::Vector3 URDF2Gazebo::RotateVector(const urdf::Rotation &_rot, const urdf::Vector3 &_vector) const
00168   {
00169     urdf::Rotation tmp(_vector.x, _vector.y, _vector.z, 0.0);
00170     tmp =  _rot * ( tmp * _rot.GetInverse() );
00171     return urdf::Vector3( tmp.x, tmp.y, tmp.z );
00172   }
00173   urdf::Pose PoseTimes(const urdf::Pose &_pose_a, const urdf::Pose &_pose_b) const
00174   {
00175     urdf::Rotation r = _pose_a.rotation * _pose_b.rotation;
00176     urdf::Vector3 p = _pose_a.RotateVector(_pose_b.position) + _pose_a.position;
00177 
00178     //  return urdf::Vector3(m_basis[0].dot(x) + m_origin.x(), 
00179     //                   m_basis[1].dot(x) + m_origin.y(), 
00180     //                   m_basis[2].dot(x) + m_origin.z());
00181     return urdf::Pose(p,r);
00182   }
00183 */
00184 
00185   class URDF2Gazebo
00186   {
00187     public:
00188       URDF2Gazebo();
00189       ~URDF2Gazebo();
00190 
00191       urdf::Vector3 parseVector3(TiXmlNode* key, double scale = 1.0);
00192       void addVisual(boost::shared_ptr<urdf::Link> link, std::string group_name, boost::shared_ptr<urdf::Visual> visual);
00193       void addCollision(boost::shared_ptr<urdf::Link> link, std::string group_name, boost::shared_ptr<urdf::Collision> collision);
00194 
00195       std::string values2str(unsigned int count, const double *values, double (*conv)(double));
00196       std::string vector32str(const urdf::Vector3 vector, double (*conv)(double));
00197 
00198       void addKeyValue(TiXmlElement *elem, const std::string& key, const std::string &value);
00199 
00200       void addTransform(TiXmlElement *elem, const::gazebo::math::Pose& transform);
00201 
00202       void printMass(boost::shared_ptr<urdf::Link> link);
00203       void printMass(std::string link_name, dMass mass);
00204 
00205       std::string getGazeboValue(TiXmlElement* elem);
00206       void parseGazeboExtension(TiXmlDocument &urdf_in);
00207       void insertGazeboExtensionGeom(TiXmlElement *elem,std::string link_name);
00208       void insertGazeboExtensionVisual(TiXmlElement *elem,std::string link_name);
00209       void insertGazeboExtensionBody(TiXmlElement *elem,std::string link_name);
00210       void insertGazeboExtensionJoint(TiXmlElement *elem,std::string joint_name);
00211       void insertGazeboExtensionRobot(TiXmlElement *elem);
00212       void listGazeboExtensions();
00213       void listGazeboExtensions(std::string reference);
00214       void reduceGazeboExtensionToParent(boost::shared_ptr<urdf::Link> link);
00215       void updateGazeboExtensionFrameReplace(GazeboExtension* ge, boost::shared_ptr<urdf::Link> link, std::string new_link_name);
00216       void updateGazeboExtensionBlobsReductionTransform(GazeboExtension* ge);
00217 
00218       urdf::Pose  transformToParentFrame(urdf::Pose transform_in_link_frame, urdf::Pose parent_to_link_transform);
00219       gazebo::math::Pose  transformToParentFrame(gazebo::math::Pose transform_in_link_frame, urdf::Pose parent_to_link_transform);
00220       gazebo::math::Pose  transformToParentFrame(gazebo::math::Pose transform_in_link_frame, gazebo::math::Pose parent_to_link_transform);
00221       gazebo::math::Pose  inverseTransformToParentFrame(gazebo::math::Pose transform_in_link_frame, urdf::Pose parent_to_link_transform);
00222       gazebo::math::Pose  copyPose(urdf::Pose pose);
00223       urdf::Pose  copyPose(gazebo::math::Pose pose);
00224 
00225       std::string getGeometrySize(boost::shared_ptr<urdf::Geometry> geometry, int *sizeCount, double *sizeVals);
00226       
00227       std::string getGeometryBoundingBox(boost::shared_ptr<urdf::Geometry> geometry, double *sizeVals);
00228 
00229       void reduceFixedJoints(TiXmlElement *root, boost::shared_ptr<urdf::Link> link);
00230       void printCollisionGroups(boost::shared_ptr<urdf::Link> link);
00231 
00232       void convertLink(TiXmlElement *root, boost::shared_ptr<const urdf::Link> link, const gazebo::math::Pose &transform,
00233                        bool enforce_limits,bool reduce_fixed_joints);
00234       void createBody(TiXmlElement* root, boost::shared_ptr<const urdf::Link> link,
00235                       gazebo::math::Pose &currentTransform, bool enforce_limits, bool reduce_fixed_joints);
00236       void createGeom(TiXmlElement* elem, boost::shared_ptr<const urdf::Link> link,
00237                       std::string collision_type, boost::shared_ptr<urdf::Collision> collision, boost::shared_ptr<urdf::Visual> visual,
00238                       int linkGeomSize, double linkSize[3], std::string original_reference = std::string(""));
00239       void createVisual(TiXmlElement *geom, boost::shared_ptr<const urdf::Link> link,
00240                       std::string collision_type, boost::shared_ptr<urdf::Collision> collision, boost::shared_ptr<urdf::Visual> visual,
00241                       std::string original_reference);
00242       void createJoint(TiXmlElement *root, boost::shared_ptr<const urdf::Link> link, gazebo::math::Pose &currentTransform,
00243                        bool enforce_limits,bool reduce_fixed_joints);
00244 
00245       bool convert( TiXmlDocument &urdf_in, TiXmlDocument &gazebo_xml_out, bool enforce_limits, 
00246                     urdf::Vector3 initial_xyz, urdf::Vector3 initial_rpy,std::string model_name=std::string(),
00247                     std::string robot_namespace=std::string(), bool xml_declaration = false);
00248 
00249       void walkChildAddNamespace(TiXmlNode* robot_xml,std::string robot_namespace);
00250 
00251       std::map<std::string, std::vector<GazeboExtension*> > gazebo_extensions_;
00252 
00253   };
00254 }
00255 
00256 #endif


gazebo
Author(s): Nate Koenig, Andrew Howard, with contributions from many others. See web page for a full credits llist.
autogenerated on Sun Jan 5 2014 11:34:52