Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:pycram:setup [2021/04/22 15:41] – [PyCRAM] adding cd pycram hawkintutorials:pycram:setup [2022/02/01 15:57] (current) – [PyCRAM on Ubuntu 20.04 (ROS Noetic)] jdech
Line 1: Line 1:
 ====== Setting up PyCRAM ====== ====== Setting up PyCRAM ======
-The setup of PyCRAM can be differentiated in three steps:+The setup of PyCRAM can be differentiated in four steps: 
 +    * Install ROS
     * Installing Dependencies      * Installing Dependencies 
     * Cloning the PyCRAM repo     * Cloning the PyCRAM repo
-    * Write a setup Script +    * Building your ROS workspace
  
 All dependencies are available via PyPi All dependencies are available via PyPi
  
-The setup script is used to add the src directory to the python pathThis has to be done so Python can find PyCRAM when importing from there.+PyCRAM is developed and tested currently with Python3.8, Ubuntu 20.04 and ROS Noetic. However, it does still support Ubuntu 18.04 and ROS Melodic. Please see below for installation instructions for both variants.
  
-This tutorial is tested with Python 3.8 and Ubuntu 18.04+===== Installing ROS ===== 
-===== Dependencies ===== +PyCRAM uses ROS for a variety of functionality, for this reason you need a working ROS installation on your machine 
-To install PyCRAM firstly the required packages must be installed. These are: +For information on how to install ROS please referee to the official documentation [[http://wiki.ros.org/ROS/Installation | here]].   
 + 
 +===== Installing Dependencies =====  
 +The dependencies you will need are:
     * Pip     * Pip
-    * CRAM/kdl_ik_service +    * vcstool 
-    * Pybullet +These are available via the Ubuntu apt-repos and can be installed via the terminal: 
-    * Pathlib +<code bash> 
-    * numpy+sudo apt-get install python3-pip python3-vcstool 
 +</code>
  
-Firstly Pip needs to be installed, on Ubuntu this can be done vie the following command: +===== PyCRAM on Ubuntu 20.04 (ROS Noetic) ===== 
-<code>sudo apt-get install python3-pip</code>+Before installing PyCRAM you need to setup a ROS workspace into which PyCRAM can be cloned. 
 +<code> 
 +mkdir -p ~/workspace/ros/src 
 +cd workspace/ros 
 +catkin_make 
 +source devel/setup.bash 
 +</code>
  
-PyCRAM uses the the KDL Inverse Kinematic service of CRAMto use the IK service CRAM needs to be installed. For instructions on how to install CRAM click [[../../installation | here]].+If ''catkin_make'' does not work this probably means that you did not source your ROS installationwhich is needed for ''catkin_make'': 
 +<code bash> 
 +source /opt/ros/noetic/setup.bash 
 +</code> 
 +Now you can install PyCRAM into your ROS workspace
  
-The rest can be installed using Pip by typing the following command into a terminal: +<code bash> 
-<code>pip3 install <package> </code>+cd <Path to your ROS workspace> 
 +cd src/ 
 +vcs import --input https://raw.githubusercontent.com/cram2/pycram/dev-noetic/pycram.rosinstall 
 +</code>
  
 +The cloning and setting up can take several minutes. After the command finishes you should see a number of repositories in your ROS workspace. 
  
-===== PyCRAM ===== +Now the last thing that needs to be done is clone the submodules of the PyCRAM repo, this is done via the following commands
-To get PyCRAM simply clone the repository with the following command into your workspace+<code bash
-<code> +cd pycram
-git clone https://github.com/cram2/pycram.git +
-cd pycram/+
 git submodule init git submodule init
 git submodule update git submodule update
 </code> </code>
 +
  
 The cloned repository contains the source code for PyCRAM as well as two short demos which demonstrate how to use it.  The cloned repository contains the source code for PyCRAM as well as two short demos which demonstrate how to use it. 
  
-===== Using PyCRAM ===== + 
-To use PyCRAM one needs to add the path to the source code manually at the moment.  +===== Python Dependencies ===== 
-This can be done in python script before executing the actual code+To install the Python dependencies Pip is used. To install Pip type the following command into terminal
 <code> <code>
-import sys +sudo apt-get install python3-pip 
-sys.path.append('<path to repository>/pycram/src/'+</code>  
 + 
 +Now the actual Python packages can be installed, these are summarized in the requirements.txt in the PyCRAM repo 
 +For this first navigate to your PyCRAM repo.  
 +<code> 
 +cd <path-to-your-pycram-repo>
 </code> </code>
 +Then install the Python packages in the requirements.txt file 
 +<code>
 +sudo pip install -r requirements.txt
 +</code>
 +
 +===== Building your ROS workspace ===== 
 +Building and sourcing your ROS workspace using catkin compiles all ROS packages and manages the appending to the respective PATH variables. This is necessary to be able to import PyCRAM via the Python import system and to find the robot descriptions in the launch file.
 +
 +You can build your ROS workspace with the following commands:
 +<code bash>
 +cd <Path to your ROS workspace>
 +catkin_make
 +source devel/local_setup.bash
 +</code> 
 +
 +===== PyCRAM on Ubuntu 18.04 (ROS Melodic) =====
 +To be able to use PyCRAM on Ubuntu 18.04 you need a few extra steps because ROS melodic doesn't fully support Python 3. The first thing you need to do is install Python3 pip.
 +<code>
 +apt-get install python3-pip
 +</code> 
 +Next you need to install the Python dependencies using pip
 +<code>
 +pip3 install rospkg empy numpy
 +</code>
 +So far you should be able to import rospy in Python and use all features but for PyCRAM to function you also need the ROS tf package which is unfortunately not available in Python 3. To be able to use the tf package we will compile it our self for Python 3.
 +==== Build Tf for Python 3 ====
 +Firstly you need to clone the geometry and geometry2 repos into your ROS workspace and select the melodic branches.
 +<code>
 +cd ur_ros_ws/src
 +git clone git@github.com:ros/geometry.git
 +cd geometry
 +git checkout melodic-devel
 +cd ..
 +git clone git@github.com:ros/geometry2.git
 +cd geometry2 
 +git checkout melodic-devel
 +</code>
 +Now all you need to do is source ROS and build your workspace using for Python 3. 
 +<code>
 +source /opt/ros/melodic/setup.bash
 +cd ur_ros_ws/
 +catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3.6
 +</code>
 +This should build the Tf package for Python 3. Now you can source your workspace and use the Tf package. 
 +
 +In order to use ROS and the Python3 Tf package you have to pay attention to a little thing when sourcing ROS. It is not enough to just source your workspace, you need to source the '/opt/ros/melodic/setup.bash' before hand to be able to use roslaunch. 
 +
 +The easiest way is to add the two sourcing commands to your .bashrc like so.
 +<code>
 +echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc && echo "source $(pwd)/devel/setup.bash" >> ~/.bashrc
 +</code>
 +
 +==== Build PyKDL for Python 3 ====
 +Now you need to build PyKDL as well as kdl_parser_py for Python 3.  This is done in two distinctive steps, first build orocos_kdl using cmake outside of your catkin workspace and then building your catkin workspace containing PyKDL and kdl_parser_py for Python 3. 
 +First clone the orocos kinematics dynamicas Repo, outside of your catkin workspace.
 +<code>
 +git clone git@github.com:orocos/orocos_kinematics_dynamics.git
 +</code>
 +Now build the orocos_kdl library, by pasting the following commands in a terminal. 
 +<code>
 +cd orocos_kinematics_dynamics/orocos_kdl
 +mkdir build
 +cd build
 +cmake ..
 +make
 +sudo make install
 +</code>
 +
 +Now all you have to do is copy the PyKDL package from the orocos kinematics dynamics folder to your catkin workspace, clone the kdl_parser_py and build. 
 +<code>
 +cd orocos_kinematics_dynamics
 +git submodule update --init
 +cp python_orocos_kdl path/to/your/catkin/workspace 
 +cd <path to yourt catkin workspace>/python_orocos_kdl
 +cd ../
 +</code>
 +This will copy python orocos kdl into your catkin workspace and clone the submodules contained in the repo. Now we have to clone the kdl_parser_py and build.
 +<code>
 +git clone git@github.com:ros/kdl_parser.git
 +cd ../..
 +catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3.6
 +</code>
 +