hku-mars / FAST-LIVO

A Fast and Tightly-coupled Sparse-Direct LiDAR-Inertial-Visual Odometry (LIVO).
GNU General Public License v2.0
1.26k stars 202 forks source link

Use with Docker #136

Closed MGforest closed 1 month ago

MGforest commented 1 month ago

Hi, I created a Dockerfile for it. Save it as "Dockerfile", without file extension.

FROM osrf/ros:noetic-desktop-full

# Set non-interactive mode to avoid prompts
ENV DEBIAN_FRONTEND=noninteractive

# Install necessary system dependencies and ROS tools (excluding pre-built PCL ROS packages)
RUN apt-get update && apt-get install -y \
    gedit \
    nano \
    git \
    build-essential \
    cmake \
    python3-pip \
    python3-rosdep \
    python3-catkin-tools \
    locales \
    libeigen3-dev \
    libceres-dev \
    libopencv-dev \
    libyaml-cpp-dev \
    ros-noetic-cv-bridge \
    ros-noetic-image-transport \
    ros-noetic-tf2-geometry-msgs \
    ros-noetic-message-filters \
    ros-noetic-geometry-msgs \
    ros-noetic-sensor-msgs \
    ros-noetic-eigen-conversions \
    ros-noetic-catkin \
    && rm -rf /var/lib/apt/lists/*

# Install PCL 1.13 from source
RUN mkdir -p /opt/pcl && \
    cd /opt/pcl && \
    git clone https://github.com/PointCloudLibrary/pcl.git && \
    cd pcl && \
    git checkout pcl-1.13.0 && \
    mkdir build && \
    cd build && \
    cmake .. -DCMAKE_BUILD_TYPE=Release && \
    make -j"$(nproc)" && \
    make install && \
    ldconfig

# Install Sophus (with fix for so2.cpp)
RUN cd /opt && \
    rm -rf Sophus && \
    git clone https://github.com/strasdat/Sophus.git && \
    cd Sophus && \
    git checkout a621ff && \
    sed -i 's/unit_complex_.real() = 1\.;/unit_complex_ = std::complex<double>(1,0);/' sophus/so2.cpp && \
    sed -i 's/unit_complex_.imag() = 0\.;/unit_complex_ = std::complex<double>(1,0);/' sophus/so2.cpp && \
    mkdir build && cd build && \
    cmake .. && make -j"$(nproc)" && make install

# Create the workspace and build Fast-LIVO in it
ENV WORKSPACE=/catkin_ws

RUN mkdir -p $WORKSPACE/src

# Clone Vikit
RUN cd $WORKSPACE/src && \
    git clone https://github.com/uzh-rpg/rpg_vikit.git && \
    cd rpg_vikit/vikit_common/src && \
    sed -i '48s/CV_RANSAC/cv::RANSAC/' homography.cpp && \
    sed -i '112s/CV_INTER_LINEAR/cv::INTER_LINEAR/' pinhole_camera.cpp && \
    sed -i '237s/CV_WINDOW_AUTOSIZE/cv::WINDOW_AUTOSIZE/' img_align.cpp && \
    sed -i '437s/CV_WINDOW_AUTOSIZE/cv::WINDOW_AUTOSIZE/' img_align.cpp

# Clone and build livox_ros_driver
RUN cd $WORKSPACE/src && \
    git clone https://github.com/Livox-SDK/livox_ros_driver.git

# Clone and build Fast-LIVO
RUN cd $WORKSPACE/src && \
    git clone https://github.com/hku-mars/Fast-LIVO.git && \
    cd Fast-LIVO && \
    git submodule update --init --recursive

RUN cd $WORKSPACE && \
    /bin/bash -c "source /opt/ros/noetic/setup.bash && catkin_make"

WORKDIR /catkin_ws

then go to your local Fast-LIVO folder. I created a "data" folder. PWD : ~/catkin_ws/src/FAST-LIVO/data The dot says, the Dockerfile is located in the current folder, can be anywhere, but I have in the Fast-LIVO folder.

$ docker build -t fast-livo .

$docker run -it -e "DISPLAY" -e "QT_X11_NO_MITSHM=1" -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" -v "$PWD:/data" fast-livo

in the container: /catkin_ws# source devel/setup.bash

/catkin_ws# roslaunch fast_livo mapping_avia.launch

add a new terminal: in a new local terminal, type: $ docker ps $ docker exec -it -e DISPLAY -e QT_X11_NO_MITSHM=1 CONTAINTER-ID bash /catkin_ws# rosbag play /data/lidar_cam.bag

This was based on #53 and https://github.com/ethz-asl/kalibr/wiki/installation