Skip to content

Commit f9675a6

Browse files
authored
Merge pull request #34 from Tigul/urdf-ros
Added parsing of filepaths in URDFs
2 parents 6758d60 + ccf68f3 commit f9675a6

3 files changed

Lines changed: 49 additions & 28 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,31 @@ on:
1010
jobs:
1111
test:
1212
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
python-version: ['3.10']
16-
13+
container:
14+
image: "pycram/semantic_world:jazzy"
1715
steps:
18-
- uses: actions/checkout@v3
19-
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v4
16+
- uses: actions/checkout@v4
2217
with:
23-
python-version: ${{ matrix.python-version }}
18+
path: "ros/src/semantic_world"
19+
repository: ${{ github.repository }}
20+
ref: ${{ github.ref }}
21+
submodules: 'false'
22+
- name: Update semantic_world source files
23+
run: |
24+
rm -rf /opt/ros/overlay_ws/src/semantic_world/*
25+
cd /opt/ros/overlay_ws/src/semantic_world
26+
rm -rf .git .github .gitignore .gitmodules .readthedocs.yaml
27+
cp -r /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/ros/src/semantic_world /opt/ros/overlay_ws/src
2428
2529
- name: Install dependencies
2630
run: |
2731
sudo apt-get update
28-
sudo apt install graphviz graphviz-dev
29-
python -m pip install --upgrade pip
30-
pip install virtualenv
31-
python -m virtualenv venv
32-
source venv/bin/activate
33-
pip install -r requirements.txt
34-
pip install pytest mypy flake8 black isort
35-
pip install .
36-
git clone https://github.com/Multiverse-Framework/Multiverse-Parser.git
37-
pip install -r ./Multiverse-Parser/requirements.txt
38-
pip install -e ./Multiverse-Parser
39-
echo "PATH=$PWD/ultiverse-Parser/ext/blender:$PWD/ultiverse-Parser/USD/linux/lib/python:$PWD/ultiverse-Parser/USD/linux/plugin/usd:$PATH" >> $GITHUB_ENV
40-
echo "PYTHONPATH=$PWD/ultiverse-Parser/USD/linux/lib/python:$PWD/src" >> $GITHUB_ENV
32+
cd /opt/ros/overlay_ws/src/semantic_world
33+
source ../semantic_world-venv/bin/activate
34+
pip install -U pip && pip install -r requirements.txt && pip install . && pip install -r doc/requirements.txt
4135
4236
- name: Run tests
4337
run: |
44-
source venv/bin/activate
45-
echo "PATH is: $PATH"
46-
echo "PYTHONPATH is: $PYTHONPATH"
47-
PATH=$PATH PYTHONPATH=$PYTHONPATH pytest -v test/
38+
cd /opt/ros/overlay_ws/src/semantic_world
39+
source ../semantic_world-venv/bin/activate
40+
pytest -v test/

docker/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ ARG OVERLAY_WS=/opt/ros/overlay_ws
99
WORKDIR $OVERLAY_WS/src
1010
SHELL ["/bin/bash", "-c"]
1111

12-
RUN apt update && apt install python3.12-venv ros-jazzy-xacro python3-vcstool git ros-dev-tools default-jre graphviz graphviz-dev -y
12+
RUN apt update && apt install python3.12-venv ros-jazzy-xacro python3-vcstool git ros-dev-tools default-jre graphviz graphviz-dev -y && apt-get clean && rm -rf /var/lib/apt/lists/*
1313
RUN vcs import --input https://raw.githubusercontent.com/cram2/semantic_world/main/rosinstall/semantic_world-https.rosinstall
1414
RUN source /opt/ros/jazzy/setup.bash && cd $OVERLAY_WS && colcon build --symlink-install
1515
RUN echo "source $OVERLAY_WS/install/setup.bash" >> ~/.bashrc
1616

1717
RUN python3 -m venv semantic_world-venv --system-site-packages && source semantic_world-venv/bin/activate && pip install -U pip && pip install -U setuptools && pip install -r $OVERLAY_WS/src/semantic_world/requirements.txt
1818

19+
# Install the Multiverse Parser
20+
RUN git clone https://github.com/Multiverse-Framework/Multiverse-Parser.git
21+
RUN source semantic_world-venv/bin/activate && pip install -r ../Multiverse-Parser/requirements.txt && pip install -e ../Multiverse-Parser
22+
RUN echo "PATH=$OVERLAY_WS/src/Multiverse-Parser/ext/blender:$OVERLAY_WS/src/Multiverse-Parser/USD/linux/lib/python:$OVERLAY_WS/src/Multiverse-Parser/USD/linux/plugin/usd:$PATH" >> $GITHUB_ENV
23+
RUN echo "PYTHONPATH=$OVERLAY_WS/src/Multiverse-Parser/USD/linux/lib/python:$OVERLAY_WS/src/src" >> $GITHUB_ENV
24+
1925
COPY entrypoint.sh /
2026
ENTRYPOINT ["bash", "/entrypoint.sh"]

src/semantic_world/adapters/urdf.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,28 @@ def parse_geometry(self, geometry: Union[List[urdf.Collision], List[urdf.Visual]
225225
elif isinstance(geom.geometry, urdf.Mesh):
226226
if geom.geometry.filename is None:
227227
raise ValueError("Mesh geometry must have a filename.")
228-
res.append(Mesh(origin=origin_transform, filename=geom.geometry.filename,
228+
res.append(Mesh(origin=origin_transform, filename=self.parse_file_path(geom.geometry.filename),
229229
scale=Scale(*(geom.geometry.scale or (1, 1, 1)))))
230230
return res
231+
232+
@staticmethod
233+
def parse_file_path(file_path: str) -> str:
234+
"""
235+
Parses a file path which contains a ros package to a path in the local file system.
236+
:param file_path: The path to the URDF file.
237+
:return: The parsed and processed file path.
238+
"""
239+
if "package://" in file_path:
240+
try:
241+
from ament_index_python.packages import get_package_share_directory
242+
except ImportError:
243+
raise ImportError("No ROS install found while the URDF file contains references to ROS packages. ")
244+
# Splits the file path at '//' to get the package and the rest of the path
245+
package_split = file_path.split('//')
246+
# Splits the path after the // to get the package name and the rest of the path
247+
package_name = package_split[1].split('/')[0]
248+
package_path = get_package_share_directory(package_name)
249+
file_path = file_path.replace("package://" + package_name, package_path)
250+
if 'file://' in file_path:
251+
file_path = file_path.replace("file://", './')
252+
return file_path

0 commit comments

Comments
 (0)