Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to change package:// to model:// when loading urdf file #288

Merged
merged 1 commit into from
Apr 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gazebo_ros/scripts/spawn_model
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import rospy, sys, os, time
import string
import warnings
import re

from gazebo_ros import gazebo_interface

Expand Down Expand Up @@ -63,6 +64,7 @@ def usage():
-P <pitch in radians> - optional: initial pose, use 0 if left out
-Y <yaw in radians> - optional: initial pose, use 0 if left out
-J <joint_name joint_position> - optional: initialize the specified joint at the specified value
-package_to_model - optional: convert urdf <mesh filename="package://..." to <mesh filename="model://..."
'''
sys.exit(1)

Expand All @@ -85,6 +87,7 @@ class SpawnModel():
self.sdf_format = False
self.joint_names = []
self.joint_positions = []
self.package_to_model = False

def parseUserInputs(self):
# get goal from commandline
Expand Down Expand Up @@ -173,6 +176,8 @@ class SpawnModel():
if sys.argv[i] == '-Y':
if len(sys.argv) > i+1:
self.initial_rpy[2] = float(sys.argv[i+1])
if sys.argv[i] == '-package_to_model':
self.package_to_model = True;

if not self.sdf_format and not self.urdf_format:
print "Error: you must specify incoming format as either urdf or sdf format xml"
Expand Down Expand Up @@ -243,6 +248,9 @@ class SpawnModel():
print "Error: user specified param or filename is an empty string"
sys.exit(0)

if self.package_to_model:
model_xml = re.sub("<\s*mesh\s+filename\s*=\s*\"package:/?/?","<mesh filename=\"model://", model_xml)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only works for attributes with double quotes ". I think it should be updated to handle single quotes ' as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# setting initial pose
initial_pose = Pose()
initial_pose.position.x = self.initial_xyz[0]
Expand Down