00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00052
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
00067 std::string original_reference;
00068 gazebo::math::Pose reduction_transform;
00069
00070
00071 std::string material;
00072
00073
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
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
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
00098 std::vector<TiXmlElement*> blobs;
00099
00100 GazeboExtension()
00101 {
00102
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
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
00154
00155
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
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 ¤tTransform, 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 ¤tTransform,
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