Skip to content


Set up a Lidar Base station for detecting vehicles

This system ultilises a Raspberry Pi 4, Livox Lidar Mid-400, and a screen to create a base station which can help to scan objects.

Last update: 2022-05-07


Components#

  1. Livox Lidar

    Livox Mid-40 provides SDK for Linux native C++ APIs and ROS driver.

    Livox only provides Livox Viewer 0.10.0 for 64-bit Ubuntu 16.04 (Xenial), no source code published.

  2. Raspberry Pi 4 B

    • Official Raspberry Pi OS does not have 64-bit version until 20.04 (Bullseye).
    • Ubuntu has provided 64-bit OS version for Raspberry Pi 4 from 18.04 (Bionic).
  3. ROS

    Livox ROS driver supports 64-bit Ubuntu 18.04, and ROS Melodic also fully supports Ubuntu 18.04.

Install OS#

  1. Flash Image

    Download Ubuntu 18.04.5 arm64 raspi3 and use Etcher to flash image to an SD Card.

    After flashing, there are 2 partitions on the SD Card:

    • system-boot: startup files and bootloader configs
    • writeable: root path of system

    By default, Ubuntu image enables the primary mini UART port, and also enables the Linux system console on that port. Connect a USB to TTL serial converter to GPIO 14 (PIN8) and GPIO 15 (PIN 10) to access Pi through the UART port.

    To access Pi through network, follow below instructions. Refer Ubuntu on Raspberry Pi for more information.

  2. Configure HDMI LCD (optional)

    This section is for WaveShare 7-inch HDMI LCD.

    In the system-boot partition, add below lines to the end of the file usercfg.txt:

    hdmi_group=2
    hdmi_mode=87
    hdmi_cvt=1024 600 60 6 0 0 0
    dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
    
  3. Enable SSH

    Add an empty file ssh in the system-boot partition to enable SSH.

  4. Set up Network

    Scan IP in LAN:

    for /L %i in (1,1,254) do ping -n 1 192.168.100.%i | findstr "ms" && echo %i >> ip.txt
    

    Then select an available IP in the network. e.g. 192.168.100.190.

    Starting from Ubuntu 18.04 LTS, Ubuntu uses Netplan to configure network interfaces by default. Edit the Netplan YAML configuration file network-config with the following content:

    version: 2
    ethernets:
    eth0:
        addresses: [192.168.100.190/24]
        gateway4: 192.168.100.1
        nameservers:
            addresses: [192.168.100.4,8.8.8.8]
    wifis:
        wlan0:
            dhcp4: true
            access-points:
                "mynetwork":
                    password: "123456789"
    

    This file is only used once at the first boot

    The configs will be copied to /etc/netplan/50-cloud-init.yaml.

    Scan for IP

    If you don’t want to set a static IP, you can let the router assign an address using dhcp4: true option, and then scan for it later using ARP table.

    Ping all hosts in the LAN:

    for /L %i in (1,1,254) do ping -n 1 192.168.100.%i
    

    Check ARP table, and look for MAC of Pi 3 b8-27-eb or Pi 4 dc-a6-32:

    arp -a | findstr b8-27-eb
    
  5. Boot up

    Use SSH to log in with the default user ubuntu, password: ubuntu. Right after the first time logging in, default password have to be changed.

    To skip entering password on sudo command, add current user to sudoers with the rule NOPASSWD:

    sudo bash -c "echo '$USER ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/$USER"
    
  6. Install Desktop

    Update packages:

    sudo apt update && \
    sudo apt upgrade -y
    

    Install Unity desktop environment without addons:

    sudo apt install ubuntu-desktop --no-install-recommends
    

    Or install the lightweight Xubuntu desktop without addons:

    sudo apt install xubuntu-desktop --no-install-recommends
    

    Missing packages in a minimal installation

    The option --no-install-recommends will not install many bloat packages (offices, mail, etc.,) that helps to reduce download and install size. However, it may cause GUI does not show up.

    The most happened issue is missing fbdev which shown in the log:

    ~/.local/share/xorg/Xorg.0.log
    ...
    (WW) Warning, couldn't open module fbdev
    (EE) Failed to load module "fbdev" (module does not exist, 0)
    ...
    Fatal server error:
    (EE) no screens found(EE)
    ...
    

    To install fbdev, run:

    sudo apt install xserver-xorg-video-fbdev
    
  7. Calibrate touch sensor

    The display can be calibrated via xinput-calibrator.

    sudo apt install xserver-xorg-input-evdev xinput-calibrator
    

    Create calibration config:

    sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf
    sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf
    
    /usr/share/X11/xorg.conf.d/99-calibration.conf
    Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
        Option  "Calibration"   "106 3990 3826 172"
        Option  "SwapAxes"      "1"
        Option "EmulateThirdButton" "1"
        Option "EmulateThirdButtonTimeout" "1000"
        Option "EmulateThirdButtonMoveThreshold" "300"
    EndSection
    

    After reboot, touch will work normally. You can perform touch calibration by clicking the Menu icon on the taskbar, selecting PreferencesCalibrate Touchscreen, and following the displayed prompts.

    Note to save calibration data back to /usr/share/X11/xorg.conf.d/99-calibration.conf.

  8. Auto Login

    Add new config for LightDM in

    sudo nano /etc/lightdm/lightdm.conf.d/60-xubuntu.conf
    
    /etc/lightdm/lightdm.conf.d/60-xubuntu.conf
    [Seat:*]
    user-session=xubuntu
    autologin-user=ubuntu
    
  9. Automount USB

    Install additional packages:

    sudo apt install thunar-volman gvfs udisks2
    

    Plugged-in USB will be mounted into /media/ubuntu/<Label> or /media/ubuntu/<sdXy>.

Install ROS#

Adding repository and source list

sudo apt-add-repository universe
sudo apt-add-repository multiverse
sudo apt-add-repository restricted
sudo apt update

Setup source list to get ROS packages:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Add keys:

sudo apt install -y curl && \
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

Pull the package list:

sudo apt update

Install ROS Melodic desktop:

sudo apt install -y ros-melodic-desktop --no-install-recommends

It’s convenient if the ROS environment variables are automatically added to a bash session every time a new shell is launched:

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc && \
source ~/.bashrc

A good way to check the installation is to ensure that environment variables like ROS_ROOT and ROS_PACKAGE_PATH are set:

printenv | grep ROS
ROS_ETC_DIR=/opt/ros/melodic/etc/ros
ROS_ROOT=/opt/ros/melodic/share/ros
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROS_PYTHON_VERSION=2
ROS_PACKAGE_PATH=/opt/ros/melodic/share
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=melodic

Initialize the package rosdep to track package dependency:

sudo apt install -y python-rosdep && \
sudo rosdep init && \
rosdep update

Build packages are needed for code compilation.

sudo apt install -y python-rosinstall python-rosinstall-generator python-wstool build-essential

Create a catkin workspace and try to build it:

mkdir -p ~/catkin_ws/src && \
cd ~/catkin_ws/src && \
catkin_init_workspace && \
cd .. && \
catkin_make

The workspace should be built successfully.

Install Livox SDK#

Dependency#

Livox SDK needs to be built in the host machine, therefore, some tool-chain and build tools have to be installed.

sudo apt update && \
sudo apt install -y build-essential && \
sudo apt install -y curl && \
sudo apt install -y git && \
sudo apt install -y cmake

The Pointcloud Library (PCL):

sudo apt install -y libpcl-dev
sudo apt install -y ros-melodic-pcl-ros

Eigen is a C++ template library for linear algebra:

sudo apt install -y libeigen3-dev

OpenCV (Open Source Computer Vision Library) is an open-source computer vision library:

sudo apt install -y python-opencv python3-opencv

Re-link libraries:

sudo ln -s /usr/bin/vtk6 /usr/bin/vtk
aarch64
sudo ln -s /usr/lib/python2.7/dist-packages/vtk/libvtkRenderingPythonTkWidgets.aarch64-linux-gnu.so /usr/lib/aarch64-linux-gnu/libvtkRenderingPythonTkWidgets.so

Livox SDK#

The official guide is at https://github.com/Livox-SDK/Livox-SDK.

Livox SDK is the software development kit designed for all Livox products. It is developed based on C/C++ following Livox SDK Communication Protocol, and provides easy-to-use C style API. With Livox SDK, users can quickly connect to Livox products and receive pointcloud data.

Installation

git clone https://github.com/Livox-SDK/Livox-SDK.git && \
cd Livox-SDK && \
cd build && \
cmake .. && \
make && \
sudo make install

The Livox SDK will be built and installed in /usr/local/lib:

Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/liblivox_sdk_static.a
-- Installing: /usr/local/include/livox_def.h
-- Installing: /usr/local/include/livox_sdk.h

Install Livox ROS Driver#

Get livox_ros_driver from GitHub

git clone https://github.com/Livox-SDK/livox_ros_driver.git ws_livox/src

Then build it:

cd ws_livox && \
catkin_make

Compilation errors

  • If running catkin_make gives error of command not found, it’s probably that the ROS setup.bash is not executed and included in ~/.bashrc. See above section to source it.

  • If gcc is halted, usually it is caused by lack of memory. The compilation takes more than 1.2 GB of RAM at peak!

Test Lidar#

  1. Chang Ethernet IP to static IP in subnet 192.168.1.0/24:

    /etc/netplan/50-cloud-init.yaml
    version: 2
    ethernets:
    eth0:
        addresses: [192.168.1.12/24]
        gateway4: 192.168.1.1
    
  2. Use Livox Viewer to set a Static IP for the Lidar module. Livox only accepts IP in 192.168.1.0 subnet.

  3. Then run the livox_lidar_rviz example:

    cd ws_livox
    source ./devel/setup.bash
    roslaunch livox_ros_driver livox_lidar_rviz.launch
    

    This will run Livox ROS and Rviz to visualize the received pointcloud.

Comments