Article directory
- Preface
- 1. Install libfranka and franka_ros
- 2. Set up the real-time kernel
-
- 1. Install dependencies
- 2. Compile the kernel
- 3. Install the kernel
- 4. Verify the kernel
- 3. Install the graphics card driver under the real-time kernel
-
- 1. Switch back to the previous kernel
- 2. Switch to real-time kernel
- 3. Allow users to set real-time permissions for their processes
Foreword
This article introduces the installation of Franka Control Interface (FCI) in ubuntu 20.04. The prerequisite is that ROS Noetic has been installed. The reference documents are as follows:
- Franka official documentation
- @囧paper, how to get started with robot control?
- David Augustat, How to Compile and Install the Linux Kernel on Ubuntu
- Code Pioneer Network, Ubuntu real-time kernel patching tutorial and solutions to graphics card driver problems after installation
- How to remove kernel
1. Install libfranka and franka_ros
After installing ROS Noetic, execute:
sudo apt install ros-noetic-libfranka ros-noetic-franka-ros
Before building from source, uninstall existing installations of libfranka
and franka_ros
to avoid conflicts:
sudo apt remove "*libfranka*"
Install the following dependencies from Ubuntu’s package manager to build libfranka:
sudo apt install build-essential cmake git libpoco-dev libeigen3-dev
Download the libfranka
source code from GitHub:
- For Panda:
git clone --recursive https://github.com/frankaemika/libfranka # only for panda cdlibfranka
- For Franka Research 3:
git clone --recursive https://github.com/frankaemika/libfranka --branch 0.10.0 # only for FR3 cdlibfranka
In the source directory, create a build directory and run CMake:
mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF .. cmake --build .
Optionally (but recommended) build and install the libfranka-Debian package in the same directory:
cpack -G DEB sudo dpkg -i libfranka*.deb
Create a Catkin workspace in the directory of your choice:
cd /path/to/desired/folder mkdir -p catkin_ws/src cd catkin_ws source /opt/ros/noetic/setup.sh catkin_init_workspace src
Then download the franka_ros
repository from GitHub:
git clone --recursive https://github.com/frankaemika/franka_ros src/franka_ros
Install any missing dependencies and build the package:
rosdep install --from-paths src --ignore-src --rosdistro noetic -y --skip-keys libfranka catkin_make -DCMAKE_BUILD_TYPE=Release -DFranka_DIR:PATH=/path/to/libfranka/build source devel/setup.sh
2. Set up real-time kernel
1. Install dependencies
First install several software packages required for compilation:
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev fakeroot
Install the dwarves package:
sudo apt install dwarves
Next, download the kernel source code from the official website kernel.org, select the latest longterm
version and copy the tarball
link, use this link to download the kernel source code and unzip it:
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.53.tar.xz tar -xf linux-6.1.53.tar.xz
2. Compile the kernel
Enter the directory of the Linux source:
cd linux-6.1.53
Copy the configuration files of the currently installed Linux kernel:
cp -v /boot/config-$(uname -r) .config
This configuration file contains a large number of unnecessary drivers and kernel modules. You can use the localmodconfig
command to view the kernel modules loaded on your system and modify the file to include only these modules in the build. When running this command, just hit theEnter key each time you are prompted for any request (without typing the answer).
make localmodconfig
Next, make four modifications to the configuration by running the following commands:
scripts/config --disable SYSTEM_TRUSTED_KEYS scripts/config --disable SYSTEM_REVOCATION_KEYS scripts/config --set-str CONFIG_SYSTEM_TRUSTED_KEYS "" scripts/config --set-str CONFIG_SYSTEM_REVOCATION_KEYS ""
Run the following command to compile the kernel:
fakeroot make
Alternatively, 8 represents the number of CPU cores:
fakeroot make -j8
After the build is complete, check whether the compilation was successful by running the following command. Returning 0 indicates success, returning any other value fails:
echo $?
3. Install kernel
First install the kernel module:
sudo make modules_install
Then install the kernel:
sudo make install
Finally restart:
sudo reboot
4. Verify kernel
Check the version of the installed kernel with the following command:
uname -rs
The return value matches the downloaded kernel source version, and your installation is successful:
Linux 6.1.53
3. Install the graphics driver under the real-time kernel
After installing the real-time kernel and restarting, entering nvidia-smi
in the terminal does not pop up the graphics driver information. This is because the graphics driver under the real-time kernel is missing. Switched back to the original kernel version and found that there was graphics card driver information. Under the real-time kernel, the graphics card driver cannot be downloaded directly, so this section introduces how to install the graphics card driver under the real-time kernel.
1. Switch back to the previous kernel
Go to the nvidia official website to download the driver (.run file) adapted to your computer’s graphics card version. Taking GeForce RTX 3070 Laptop GPU
as an example, the graphics card driver version is 535.104.05
. First install the dkms
management tool:
sudo apt install dkms
Disable nouveau:
sudo gedit /etc/modprobe.d/blacklist.conf
Insert the last line in the file:
blacklist nouveau options nouveau modeset=0
Save and exit, enter the following command in the terminal to make the settings take effect and restart:
sudo update-initramfs -u sudo reboot
Verify with the following command:
lsmod | grep nouveau
If there is no response when pressing Enter, it means success.
Uninstall the previous graphics card driver:
sudo apt-get remove --purge nvidia*
Run the graphics card driver installation package in the download directory:
chmod +x NVIDIA-Linux-x86_64-535.104.05.run sudo ./NVIDIA-Linux-x86_64-535.104.05.run
When the first interface pops up, select yes for the dkms
interface, and select no for the others. After the installation is complete, restart, open the terminal, and enter to view the graphics card information:
nvidia-smi
2. Switch to real-time kernel
Install the graphics card driver under the real-time kernel through the following .sh script:
#!/bin/bash BUILD_BASE=`pwd` NV_FILE="NVIDIA-Linux-x86_64-xxx.run" # Change here to the name of the .run file you downloaded (installed before) #NV_URL="https://us.download.nvidia.cn/XFree86/Linux-x86_64/430.50/${NV_FILE}" # I have downloaded the graphics card driver .run file before, so there is no need to download it from the Internet, just comment it directly dropped, and if you want to download, it will be slow NEED_TO_COMPILE_NV_KO=1 function clean_env() {<!-- --> [ -d ./${NV_DIR} ] & amp; & rm -rf ./${NV_DIR} } function check_env() {<!-- --> # check if in rt kernel uname -r | grep rt 1>/dev/null 2> & amp;1 if [ $? -ne 0 ] then echo "Not in rt kernel, Please install apollo kernel and reboot machine first." exit 2 fi # check if nv ko already in kernel if [ ! -f /lib/modules/`uname -r`/kernel/drivers/video/nvidia.ko ] then export NEED_TO_COMPILE_NV_KO=1 fi } function prepare_nv() {<!-- --> ## download nv install file from nvidia home page #if [ ! -f ./${NV_FILE} ] #then # echo "Downloading ${NV_FILE} from nvidia website..." # wget ${NV_URL} -O ${NV_FILE} # if [ $? -ne 0 ] # then # echo "Downloading ${NV_FILE} failed, please check your network connection!" # rm -rf ./${NV_FILE} # exit 1 # fi #fi ###########The above is the code for downloading the driver. We have downloaded it in advance, so we don’t need this code. Just comment out ############ # + x chmod + x ./${NV_FILE} echo "Extracting nvidia install run file..." ./${NV_FILE} -x 1>/dev/null 2> & amp;1 NV_DIR="`echo ${<!-- -->NV_FILE} | awk -F '.run' '{print $1}'`" NV_VERSION="`echo ${<!-- -->NV_FILE} | awk -F '-' '{print $4}' | awk -F '.run' '{print $1}'`" exportNV_DIR export NV_VERSION export NVIDIA_SOURCE="${NV_DIR}/kernel" } function install_lib() {<!-- --> NV_LIB_OUTPUT_PATH="/usr/lib/x86_64-linux-gnu/" NV_BIN_OUTPUT_PATH="/usr/bin/" [ -f ./${NV_DIR}/libnvidia-ml.so.${NV_VERSION} ] & amp; & amp; /bin/cp -f ./${NV_DIR}/libnvidia-ml.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH} [ -f ./${NV_DIR}/libnvidia-fatbinaryloader.so.${NV_VERSION} ] & amp; & amp; /bin/cp -f ./${NV_DIR}/libnvidia-fatbinaryloader.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH} [ -f ./${NV_DIR}/libnvidia-ptxjitcompiler.so.${NV_VERSION} ] & amp; & amp; /bin/cp -f ./${NV_DIR}/libnvidia-ptxjitcompiler.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH} [ -f ./${NV_DIR}/libcuda.so.${NV_VERSION} ] & amp; & amp; /bin/cp -f ./${NV_DIR}/libcuda.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH} [ -f ./${NV_DIR}/nvidia-modprobe ] & amp; & amp; /bin/cp -f ./${NV_DIR}/nvidia-modprobe ${NV_BIN_OUTPUT_PATH} [ -f ./${NV_DIR}/nvidia-smi ] & amp; & amp; /bin/cp -f ./${NV_DIR}/nvidia-smi ${NV_BIN_OUTPUT_PATH} chmod +x /usr/bin/nvidia* chmod + s /usr/bin/nvidia-modprobe # link for nvidia /bin/rm -rf /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 /usr/lib/x86_64-linux-gnu/libnvidia-ml.so /bin/ln -s /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.${NV_VERSION} /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 /bin/ln -s /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 /usr/lib/x86_64-linux-gnu/libnvidia-ml.so /bin/rm -rf /usr/lib/x86_64-linux-gnu/libcuda.so /usr/lib/x86_64-linux-gnu/libcuda.so.1 /bin/ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.${NV_VERSION} /usr/lib/x86_64-linux-gnu/libcuda.so.1 /bin/ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.1 /usr/lib/x86_64-linux-gnu/libcuda.so # take effect /sbin/ldconfig 1>/dev/null 2> &1 } function build_nv() {<!-- --> if [ ${NEED_TO_COMPILE_NV_KO} == 0 ] then return fi NVIDIA_MOD_REL_PATH='kernel/drivers/video' NVIDIA_OUTPUT_PATH="/lib/modules/`uname -r`/${NVIDIA_MOD_REL_PATH}" CPUNUM=`cat /proc/cpuinfo | grep processor | wc | awk -F " " '{print $1}'` export IGNORE_PREEMPT_RT_PRESENCE=true cd ${NVIDIA_SOURCE} & amp; & amp; make -j ${CPUNUM} module cd ${BUILD_BASE} unset IGNORE_PREEMPT_RT_PRESENCE mkdir -p ${NVIDIA_OUTPUT_PATH} [ -f ${NVIDIA_SOURCE}/nvidia.ko ] & amp; & amp; cp ${NVIDIA_SOURCE}/nvidia.ko ${NVIDIA_OUTPUT_PATH} [ -f ${NVIDIA_SOURCE}/nvidia-modeset.ko ] & amp; & amp; cp ${NVIDIA_SOURCE}/nvidia-modeset.ko ${NVIDIA_OUTPUT_PATH} [ -f ${NVIDIA_SOURCE}/nvidia-drm.ko ] & amp; & amp; cp ${NVIDIA_SOURCE}/nvidia-drm.ko ${NVIDIA_OUTPUT_PATH} [ -f ${NVIDIA_SOURCE}/nvidia-uvm.ko ] & amp; & amp; cp ${NVIDIA_SOURCE}/nvidia-uvm.ko ${NVIDIA_OUTPUT_PATH} depmod -a } # check environment check_env # prepare for nvidia prepare_nv # build nvidia.ko build_nv # install user lib install_lib # clean environment clean_env echo "Done to install nvidia kernel driver and user libraries."
Run the following command and copy and paste the above script code into it. Modify the corresponding content according to the version of your own graphics card driver installation package. The modified parts are noted above:
sudo gedit install_nvidia.sh
Note: Use the following command to view the kernel version. If the version number contains PREEMPT_DYNAMIC
, you need to comment out these contents in the script:
uname -a
uname -r | grep rt 1>/dev/null 2> & amp;1 if [ $? -ne 0 ] then echo "Not in rt kernel, Please install apollo kernel and reboot machine first." exit 2 fi
After modification, run:
chmod + x install_nvidia.sh sudo ./install_nvidia.sh
Restart after installation is complete.
Enter to view the graphics card information. The graphics card driver information appears, indicating that the installation is successful:
nvidia-smi
3. Allow users to set real-time permissions for their processes
Add a group called realtime
and add the user controlling the bot to this group:
sudo addgroup realtime sudo usermod -a -G realtime $(whoami)
Add the following limits to /etc/security/limits.conf
and they will take effect after restarting:
@realtime soft rtprio 99 @realtime soft priority 99 @realtime soft memlock 102400 @realtimehard rtprio 99 @realtimehard priority 99 @realtime hard memlock 102400