问题
I have a .world
file in ROS for gazebo simulation which is an XML file.
How can I put on a dynamic home path instead of the static path in <uri>
tag?
Here's my simplified .world
file:
<?xml version="1.0" ?>
<sdf version='1.5'>
<world name='default'>
<visual name='base_link_visual_front_sonar'>
<pose>0.109 0 0.209 0 -0 0</pose>
<geometry>
<mesh>
<uri>/home/agn/catkin_ws/src/description/meshes/sonar.stl</uri> <!--Note-->
</mesh>
</geometry>
</visual>
</world>
</sdf>
How can I use $HOME
instead of /home/agn
?
I tried the following cases with the failed results:
<uri>~/catkin_ws/src/description/meshes/sonar.stl</uri>
<uri>$HOME/catkin_ws/src/description/meshes/sonar.stl</uri>
<uri>"$HOME/catkin_ws/src/description/meshes/sonar.stl"</uri>
<uri>${HOME}/catkin_ws/src/description/meshes/sonar.stl</uri>
<uri>"${HOME}/catkin_ws/src/description/meshes/sonar.stl"</uri>
<uri>"${sys:user.home}/catkin_ws/src/description/meshes/sonar.stl"</uri>
<uri>${sys:user.home}/catkin_ws/src/description/meshes/sonar.stl</uri>
<uri>${user.home}/catkin_ws/src/description/meshes/sonar.stl</uri>
<uri>"${user.home}/catkin_ws/src/description/meshes/sonar.stl"</uri>
回答1:
According to the Gazebo tutorial Gazebo allows to find additional models at paths that are listed listed on the environment variable GAZEBO_MODEL_PATH
.
Adding a path to an environment variable is well described in How to correctly add a path to PATH? and can be done like
PATH=$GAZEBO_MODEL_PATH:/your/path/to/check
Now you are able to set the uri like
<uri>model://relative/path/file.stl</uri>
Note that there is also a hacks which allows changing the environment variable in the package.xml.
回答2:
According to roslaunch wiki,you should try this:
<uri>$(env HOME)/catkin_ws/src/description/meshes/sonar.stl</uri>
来源:https://stackoverflow.com/questions/53751987/how-to-put-on-the-home-path-in-an-xml-file-as-an-environment-variable