<style> .markdown-body pre { background-color: #333; border: 1px solid #555 !important; color: #dfdfdf; font-weight: 600; } .token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string { background: unset; } </style> # Installation instructions for CoppeliaSim, PyRep and YCB Dataset This course uses the robotic simulator CoppeliasSim, the programming language Python and the Python package PyRep, which wrapes CoppeliaSim's API and provides a high-level interface between CoppeliaSim and Python. High-fidelity 3D objects are provided by the YCB Dataset and WTM's YCB API, ## Getting Coppeliasim On Ubuntu 18.04, run the following commands to install CoppeliaSim in your home directory: ```bash cd ~ wget https://www.coppeliarobotics.com/files/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04.tar.xz tar -xvf CoppeliaSim_Edu_V4_1_0_Ubuntu18_04.tar.xz rm CoppeliaSim_Edu_V4_1_0_Ubuntu18_04.tar.xz ``` Alternatively, you can download the Edu verion for CoppeliaSim from [here](https://www.coppeliarobotics.com/downloads) and extract the archive manually. Verify installation: ```bash bash CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/coppeliaSim.sh ``` This should start CoppeliaSim and open an empty scene. You might get prompted to install aditional video compression libraries, if so, install them with `sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev`. ## Getting Python For this course, you will be using the programming language Python. Python is pre-installed on Ubuntu verify that you have it: `python3 --version` This will likely output `Python 3.6.9`, if you have Python3 installed. <!-- However, PyRep requires a different, specific Python3 version: ```bash sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python3.7 # verify installation: python3.7 --version ``` --> However, there are a few packages that you should install to ensure a complete development environment. Paste the following into your terminal: ```bash # If you don't have it, install python3 with: sudo apt install python3.6 sudo apt install -y build-essential libssl-dev libffi-dev python3-dev python3-pip python3-venv ``` ## Getting PyRep and YCB We prepared a repository with PyRep and the YCB dataset for you, to streamline the setup process. The below steps clone that repository, install PyRep and download the YCB models. ### Install PyRep in virtual environment Below, we setup the environment variables needef for PyRep to interact with CoppeliaSim, create a virtual environment and install PyRep (and its requirements) in that venv. ```bash # setup environment variables echo "# CoppeliaSim:" >> ~/.bashrc echo "export COPPELIASIM_ROOT=~/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/" >> ~/.bashrc echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:\$COPPELIASIM_ROOT" >> ~/.bashrc echo "export QT_QPA_PLATFORM_PLUGIN_PATH=\$COPPELIASIM_ROOT" >> ~/.bashrc source ~/.bashrc # clone the repository TODO: use course repo! cd ~ git clone https://git.informatik.uni-hamburg.de/5rietz/2021_bsc_project_test.git cd 2021_bsc_project_test # create virtualn environment in current working directory python3 -m venv venv # activate the venv. This ensures that everything you install is installed in # the venv instead of globally # the prefix (venv) indicates which environment is activated for # your current shell source venv/bin/activate # install PyRep in the venv cd myPyRep pip3 install -r requirements.txt pip3 install . ``` #### Verify installation: Keep in mind that everytime you restart your shell, you will have to activate the virtual environment again! If you just followed the guide, you can just run the below command directly: ```bash cd examples python3 example_turtlebot_navigation.py ``` Otherwise, first source the virtual environment then set the working directory of your terminal to the `examples` inside the `PyRep` folder. ### Downloadin YCB Data In the folder `ycb-objects-sim`, you find tools to use the YCB objects dataset in CoppeliaSim. However, the models have to be downloaded first and some configuration is due: 1. Adjust the path in `<project_root>/ycb-objects-sim/src/config.py` so that it points to the folder `data` in `<project_root>/ycb-objects-sim/src/`. This specifies the location where the object will be downloaded to (~3GB). 2. Add the `ycb-objects-sim` folder to the `PYTHONPATH`: For this, edit the script `activate.bash` in `ycb-objects-sim` 3. Run the script, so that your path is modified as specified in the file: `source activate.bash` 4. Download the ycb models. Run the following command with your working directory set to `ycb-objects-sim`: ```bash cd <project-root>/ycb-objects-sim python3 ycb-tools/download_ycb_dataset.py ``` If you get an SSL certificate error (`urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>`), run the following two commands to refresh your certificates: ```bash sudo update-ca-certificates --fresh export SSL_CERT_DIR=/etc/ssl/certs ``` 5. Create SDF files for YCB objects ```bash pip3 install trimesh[easy] cd ycb-tools python3 create_ycb_sdf.py ``` 7. Copy the file `simAddOnScript_remoteSDFImp.lua` from `ycb-objects-sim/RemoteSDFImp` to the installation folder of CoppeliaSim. You can either copy and paste the file by hand, or run the below command: ``` cd ../ # wdir should be set to ycb-objects-sim root folder cp RemoteSDFImp/simAddOnScript_remoteSDFImp.lua ~/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/ ``` ### Verify installation If everything worked, you can now run the script `example_coppelia.py` located in `ycb-objects-sim`. If you restarted your terminal or are using a different session, you will have to run `activate.bash` again, so that the `ycb-objects-sim` folder is added to your `PYTHONPATH`. Then, run: `python3 example_coppelia.py` This should open CoppeliaSim and spawn a few of the downloaded objects in the scene. # Setup PyCharm IDE As IDE, we will be using PyCharm. You can install it via SNAP/ or from the Ubuntu Software app. As a student, you can get a one-year professional key. Alternatively, install the community or EDU edition. To make PyCharm work with PyRep and CoppeliaSim, you have to do two things: 1. Set the virtual environment, that we created earlier, as interpreter for your PyCharm project under `Settings` -> `Project ...` ->`Python Interpreter` -> `Show All...` -> `+` `Existing environment` -> `...` -> `<PATH-TO-VENV>` (eg `/home/finn/uni/venv/bin/python3`) 2. For the Python file that interacts with the CoppeliaSim, set the following environment variables. Of course, adjust the paths to your system (if you followed this guide, you just have to replace "finn" with the ouput of the `whoami` command) ```bash # for PyRep & Coppelia COPPELIASIM_ROOT=/home/finn/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/ LD_LIBRARY_PATH=/home/finn/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/:$LD_LIBRARY_PATH QT_QPA_PLATFORM_PLUGIN_PATH=/home/finn/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/ # for YCB: PYTHONPATH=$PYTHONPATH:/home/finn/2021_bsc_project_test/ycb-objects-sim ``` ### Troubleshooting + If PyRep does not find your CoppeliaSim installation, try these comannds for your .bashrc and see whether PyRep finds Coppeliasim (for some of us, the $-signs needed to be escaped, for others not...): ```bash echo "export COPPELIASIM_ROOT=~/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/" >> ~/.bashrc echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COPPELIASIM_ROOT" >> ~/.bashrc echo "export QT_QPA_PLATFORM_PLUGIN_PATH=$COPPELIASIM_ROOT" >> ~/.bashrc source ~/.bashrc ``` + Alternatively, if you get something like: `ModuleNotFoundError: No module named 'pyrep'` (especially when using a virtualenv), make sure PyRep installed correctly and that is is on the `PYTHONPATH` (check [here](https://www.tutorialspoint.com/How-do-I-find-the-location-of-Python-module-sources)). + `qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""`: Check your your environment variables! Maybe typo in `QT_QPA_PLATFORM_PLUGIN_PATH=/home/finn/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04/`? + `ModuleNotFoundError: No module named 'wheel'`: Install Python `wheel` and `setuptools` in virtual environment: `python3 -m pip install wheel setuptools` + `ModuleNotFoundError: No module named 'pyrep.backend._sim_cffi'`: You are likely trying to import PyRep while your workind directory is set to PyRep's root directory. In this case, the imports fail, because Python tries to import from the folders instead of the installed packages. Change your working example (for example `cd examples`) and try again.