galou / freecad.cross

CROSS CAD and ROS, an Open-Source Synergy; ROS workbench for FreeCAD
GNU Lesser General Public License v2.1
85 stars 22 forks source link

Finded a way to run FreeCAD from ROS2 docker container without big overhead. #6

Closed drfenixion closed 6 months ago

drfenixion commented 7 months ago

Finded solution. See my second comment.

For your notation. It have dependency (rclpy) what dont mentioned in repo.

Also i think it is not be best way to direct dependency to ROS because best practice of usage ROS is in Docker. This lead to i dont have ROS in my host system (where installed freecad). Install freecad to docker ROS image will lead to big overhead. Could you describe why u need to dependency on ROS?

CROSS Workbranch does`t appear and have error logs in report view.

12:33:25  Init: Initializing freecad.cross
12:33:25  The environment variable `ROS_DISTRO` is not set and no ROS installation was found in /opt/ros, some functionalities will be missing
12:33:25  During initialization the error "No module named 'rclpy'" occurred in freecad.cross
12:33:25  --------------------------------------------------------------------------------
12:33:25  Traceback (most recent call last):
  File "<string>", line 226, in InitApplications
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/.local/share/FreeCAD/Mod/freecad.cross/freecad/cross/__init__.py", line 7, in <module>
    from .wb_globals import g_ros_distro
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
  File "/home/user/.local/share/FreeCAD/Mod/freecad.cross/freecad/cross/wb_globals.py", line 18, in <module>
    from .ros.node import get_node_and_executor  # noqa: E402.
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
  File "/home/user/.local/share/FreeCAD/Mod/freecad.cross/freecad/cross/ros/node.py", line 6, in <module>
    import rclpy
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'rclpy'
12:33:25  --------------------------------------------------------------------------------
12:33:25  Init:      Initializing freecad.cross... failed
12:33:25  --------------------------------------------------------------------------------
12:33:25  Traceback (most recent call last):
  File "<string>", line 226, in InitApplications
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/.local/share/FreeCAD/Mod/freecad.cross/freecad/cross/__init__.py", line 7, in <module>
    from .wb_globals import g_ros_distro
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
  File "/home/user/.local/share/FreeCAD/Mod/freecad.cross/freecad/cross/wb_globals.py", line 18, in <module>
    from .ros.node import get_node_and_executor  # noqa: E402.
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
  File "/home/user/.local/share/FreeCAD/Mod/freecad.cross/freecad/cross/ros/node.py", line 6, in <module>
    import rclpy
  File "/tmp/.mount_FreeCAocHVXG/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'rclpy'
12:33:25  --------------------------------------------------------------------------------
drfenixion commented 7 months ago

I find a way to run FreeCAD from docker ROS2 container without big overhead.

You should add FreeCAD appImage to bind volume directory. That you can do like this:

docker run -t -d --name=$ros_container_name \
    --volume=$path_to_ws/src:/home/ubuntu/$path_to_ws_relatively_user_directory/src \

You should place FreeCAD-0.21.2-Linux-x86_64.AppImage onto your host system in $path_to_ws/src dir

cp FreeCAD-0.21.2-Linux-x86_64.AppImage $path_to_ws/src/FreeCAD-0.21.2-Linux-x86_64.AppImage

Also you need bind your host $DISPLAY to container, like this:

    --env "DISPLAY=$DISPLAY" \
    --env WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
    --privileged \
    --volume="/dev/dri:/dev/dri" \
    --env QT_X11_NO_MITSHM=1 \
    --env PULSE_SERVER=$PULSE_SERVER \
    --env QT_X11_NO_MITSHM=1 \

and make other needed configuration for usage of host discrete GPU (if your integrated in proc GPU will be used and it not enough for rendering (you have lags))

After that you should run from container from ros workspace:

source /opt/ros/$ROS_DISTRO/setup.bash
source install/setup.bash

pip install urdf-parser-py #missed dependency

./src/FreeCAD-0.21.2-Linux-x86_64.AppImage --appimage-extract-and-run

And enjoy FreeCAD from ROS2 container.

If you have "segmentation fault" error use sudo. Like this: sudo ./src/FreeCAD-0.21.2-Linux-x86_64.AppImage --appimage-extract-and-run

Btw "Segmantation fault" appear after binding docker volume with freecad.cross source to FreeCAD mod path, like this: --volume=$path_to_ws/src/freecad.cross:/home/ubuntu/.local/share/FreeCAD/Mod/freecad.cross because it make dir of freecad.cross as root. You can fix that by: chown ubuntu:ubuntu /home/ubuntu/.local/share/FreeCAD/Mod/freecad.cross -R and after that you can use ./src/FreeCAD-0.21.2-Linux-x86_64.AppImage --appimage-extract-and-run without sudo

drfenixion commented 6 months ago

Resolved by merge