roscatkinsingularity-containermoveit

How to use change directory CD and source commands in a singularity recipe


I am trying to create a singularity container for simulating the Emika Franka robot. For this, I need to use catkin to build the moveit examples and the panda_config from the GitHub repositories. However, I keep running into some troubles because of my understanding of how singularity mounts the container relative to my main system folders. I use the recipe below to build the container with the sudo singularity build --sandbox ros-kinetic-pandasim-xenial/ recipes/ros_kinetic_pandasim_xenial/ros_kinetic_pandasim_xenial.def command.

ros_kinetic_pandasim_xenial recipe

# Ros kinetic panda simulation ubuntu xenial singularity container recipe file
Bootstrap: docker
From: osrf/ros:kinetic-desktop-full-xenial

%help
    singularity container with Ros kinetic and Gazebo7 for the dynamic simulation of the Emika Franka Panda robot.

%post
    echo "Setting up ros kinetic emika Franka container."

    ## Set user permissions to root ##
    chmod 755 /root

    ## Retrieve updates ##
    apt-get update

    ## Install ros dependencies for building packages
    apt-get install -y python-rosinstall python-rosinstall-generator python-wstool build-essential

    ## Install additional ros packages ##
    apt-get install -y ros-kinetic-joint-state-controller ros-kinetic-controller-manager* ros-kinetic-joint-trajectory-controller
    apt-get install -y ros-kinetic-effort-controllers ros-kinetic-gazebo-ros* ros-kinetic-gazebo-ros-control ros-kinetic-rviz*
    apt-get install -y ros-kinetic-catkin python-catkin-tools

    ## Install other needed packages ##
    apt-get install -y usbutils wget libboost-filesystem-dev libjsoncpp-dev

    ## Setup ros dependency tool ##
    rosdep update

    ## Install MoveIt, MoveIt tutorials and the panda_movit_config files ##
    apt-get install -y ros-kinetic-moveit*
    . /opt/ros/kinetic/setup.sh
    mkdir -p ~/pandasim_ws/src
    cd ~/pandasim_ws/src
    git clone -b kinetic-devel https://github.com/ros-planning/moveit_tutorials.git
    git clone https://github.com/erdalpekel/panda_moveit_config.git
    rosdep install -y --from-paths . --ignore-src --rosdistro kinetic
    cd ~/pandasim_ws/
    catkin config --extend /opt/ros/kinetic
    catkin build
    . ~/pandasim_ws/devel/setup.bash

%environment

    ## Change floating point format ##
    LC_NUMERIC="en_US.UTF-8"

    ## Source ros setup file ##
    . /opt/ros/kinetic/setup.sh

    ## Source catkin setup file ##
    . ~/pandasim_ws/devel/setup.bash

Expected behaviour

I want the recipe to cd into the ~/pandasim_ws/ folder so I can perform the catkin build.

Current behaviour

Currently, it gives me the following error:

#All required steps installed successfully
+ cd ~/pandasim_ws/
/bin/sh: 31: cd: can't cd to ~/pandasim_ws/
FATAL:   post proc: exit status 2
FATAL:   While performing build: while running engine: exit status 255

Main question

Can somebody maybe give an explanation or some documentation about how singularity mounts its container relative to my system directories? It looks like it uses the user workspace and therefore cd ~/ points to the home directory of the user that started the container inside the host system. Following / looks to be the root directory. Is there a way to cd relative to the singularity sandbox folder? For example a $SINGULARITY_PATH variable or a build argument.


Solution

  • I found the solution. As singularity uses the sh shell you have to use the bash -c command to run bash commands. Futher since in the sandbox you are indeed in the main workspace it better to install under the root folder instead of the home folder see definition file documentation.

    ## Install MoveIt, MoveIt tutorials and the panda_movit_config files ##
    rosdep update
    apt-get install -y ros-kinetic-moveit
    apt-get install -y \
        ros-kinetic-catkin \
        python-catkin-tools \
        ros-kinetic-controller-manager* \
        ros-kinetic-effort-controllers \
        ros-kinetic-joint-trajectory-controller \
        ros-kinetic-rviz* \
        libboost-filesystem-dev \
        libjsoncpp-dev
    bash -c "source /opt/ros/kinetic/setup.sh \
        && mkdir -p /moveit_ws/src \
        && cd /moveit_ws/src \
        && git clone -b kinetic-devel https://github.com/ros-planning/moveit_tutorials.git \
        && git clone https://github.com/erdalpekel/panda_moveit_config.git \
        && rosdep install -y --from-paths . --ignore-src --rosdistro kinetic \
        && cd /moveit_ws \
        && catkin config --extend /opt/ros/kinetic \
        && catkin build \
        && source /moveit_ws/devel/setup.bash