Week 0 & 1 :

Update personal blog.

Set up ROS Melodic Morenia on Raspbian Buster with YDLIDAR X4 and hector-slam support.

  • Use Raspberry Pi Imager to install 32 bit Raspbian GNU/Linux 10 (buster) armv7li.

  • Check if YDLIDAR X4 hardware works with the Raspberry Pi by installing YDLidar-SDK :

    # To build and install :
    $ sudo apt install cmake pkg-config python swig python-pip git
    $ git clone https://github.com/YDLIDAR/YDLidar-SDK.git
    $ cd YDLidar-SDK/build
    $ cmake ..
    $ make
    $ sudo make install
    
    # To run :
    $ ./ydlidar_test #if fails, try with sudo
    
    • The ydlidar_test program will corresponding ask for LIDAR parameters, for YDLIDAR X4 :

      • Attach external USB if using with Raspberry Pi (otherwise underpowered and DEVICE FAILED warning)
      • Baudrate : 128000
      • One Way Communication : No
      • ToF LIDAR : No
      • Scan Frequency : 5-12 Hz
    • The LIDAR must start spinning and corresponding data would be shown in the terminal : ydlidarsdk

  • Install ROS Melodic on the Raspberry Pi.

    # Installing Dependencies :
    $ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
    $ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake
    $ sudo rosdep init
    $ rosdep update
      
    # Installing ROS :
    $ mkdir -p ~/ros_catkin_ws
    $ cd ~/ros_catkin_ws
    $ rosinstall_generator desktop --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall
    # To add all of the catkin or wet packages in the given variant and 
      then fetch the sources into the ~/ros_catkin_ws/src directory. The 
      command will take a few minutes to download all of the core ROS packages 
      into the src folder. The -j8 option downloads 8 packages in parallel. 
    $ wstool init src melodic-desktop-wet.rosinstall
    # If wstool init fails or is interrupted, you can resume the download by running: 
    $ wstool update -j4 -t src
      
    # Resolve Dependencies & Build the catkin workspace :
    $ cd ~/ros_catkin_ws
    $ rosdep install -y --from-paths src --ignore-src --rosdistro melodic -r --os=debian:buster
    $ sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic
    $ echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
    $ source ~/.bashrc
      
    # ROS Melodic is now installed on your system.
    
  • Install YDLIDAR ROS package for the ros drivers.

    # Create a ROS workspace :
    $ mkdir -p ~/catkin_ws/src
    $ cd ~/catkin_ws/
    $ catkin_make
    $ echo "source /home/$USER/catkin/devel/setup.bash" >> ~/.bashrc
    $ source ~/.bashrc
      
    # Install YDLIDAR ROS Package
    $ cd ~/catkin_ws/src
    $ git clone https://github.com/YDLIDAR/ydlidar_ros
    $ cd ..
    $ catkin_make
    $ chmod 0777 src/ydlidar_ros/startup/*
    $ sudo sh src/ydlidar_ros/startup/initenv.sh #after completion, replug the LiDAR.
    $ source ~/.bashrc
      
    # Configure LIDAR parameters
    $ git checkout X4 #move to branch of your LIDAR model
    $ cd ..
    $ catkin_make
    $ source ~/.bashrc
    
  • Run YDLIDAR X4 using ROS. Attach external USB if using with Raspberry Pi (otherwise underpowered and DEVICE FAILED warning). Run $ roscore and in a new terminal run sudo sh ~/catkin_ws/src/ydlidar_ros/startup/initenv.sh and correspondingly run:

    • $ roslaunch ydlidar lidar.launch to print LIDAR data. ydlidarros
    • $ roslaunch ydlidar display.launch to visualize LIDAR data using RVIZ. 2021-05-20-11-19-04-ydlidarrosrviz.png
  • Install and configure hector_slam package to build hector map using logged LIDAR data.

    • Install hector_slam ROS Package :
      $ cd ~/catkin_ws/src
      $ git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam
      $ cd ..
      $ catkin_make
      $ source ~/catkin_ws/devel/setup.bash
      
    • Checkout YDLIDAR /tf parameter :
      $ roscore
      # In new terminal tab
      $ roslaunch ydlidar_ros lidar.launch
      # In new terminal tab
      $ rostopic echo /tf
      
    • Output of $ rostopic echo /tf for YDLIDAR X4 would contain one transformation and be of the nature :
      ---
      transforms:
       -
       header:
          seq: 0
          stamp:
              secs: 1578619851
              nsecs: 284012533
          frame_id: "/base_footprint"
       child_frame_id: "/laser_frame"
       transform:
         translation:
           x: 0.2245                                          
           y: 0.0                                             
           z: 0.2                                             
         rotation:
           x: 0.0                                             
           y: 0.0                                             
           z: 0.0                                             
           w: 1.0                                             
      ---
      
    • Edit parameters of hector slam :
      • $ vim ~/catkin_ws/src/hector_slam/hector_mapping/launch/mapping_default.launch
        • From <arg name="odom_frame" default="nav"/> to <arg name="odom_frame" default="base_footprint"/>
        • From <node pkg="tf" type="static_transform_publisher" name="map_nav_broadcaster" args="0 0 0 0 0 0 map nav 100"/> to <node pkg="tf" type="static_transform_publisher" name="map_nav_broadcaster" args="0 0 0 0 0 0 base_footprint laser_frame 100"/>
      • $ vim ~/catkin_ws/src/hector_slam/hector_slam_launch/launch/tutorial.launch
        • From <param name="/use_sim_time" value="true"/> to <param name="/use_sim_time" value="false"/>
  • Run hector_slam package to build hector map using logged LIDAR data. Attach external USB if using with Raspberry Pi (otherwise underpowered and DEVICE FAILED warning). Rotate and translate the YDLIDAR slowly (due to low revolution rate) for an accurate map to cover the whole room/system, otherwise false maps may arise.

    $ roscore
    # In new terminal tab
    $ roslaunch ydlidar_ros lidar.launch
    # In new terminal tab
    $ roslaunch hector_slam_launch tutorial.launch
    

    ydlidarroshectorslam

    ydlidarroshectorslamrqttree

Set up ROS2 Foxy Fitzroy on Ubuntu 20.04 with YDLIDAR X4 support.

  • Use Raspberry Pi Imager to install 64 bit Server Ubuntu 20.04 arm64. Install desktop for Ubuntu 20.04.

  • Check if YDLIDAR X4 hardware works with the Raspberry Pi by installing YDLidar-SDK :

    # To build and install :
    $ sudo apt install cmake pkg-config python swig python-pip git g++
    $ git clone https://github.com/YDLIDAR/YDLidar-SDK.git
    $ cd YDLidar-SDK/build
    $ cmake ..
    $ make
    $ sudo make install
    
    # To run :
    $ ./ydlidar_test #if fails, try with sudo
    
    • The ydlidar_test program will corresponding ask for LIDAR parameters, for YDLIDAR X4 :

      • Attach external USB if using with Raspberry Pi (otherwise underpowered and DEVICE FAILED warning)
      • Baudrate : 128000
      • One Way Communication : No
      • ToF LIDAR : No
      • Scan Frequency : 5-12 Hz
    • The LIDAR must start spinning and corresponding data would be shown in the terminal : ydlidarsdk

  • Install ROS2 Foxy on the Raspberry Pi.

    # Setup locale and sources :
    $ sudo locale-gen en_US en_US.UTF-8
    $ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
    $ export LANG=en_US.UTF-8
    $ sudo apt update && sudo apt install curl gnupg2 lsb-release
    $ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
    $ sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
      
    # Installing ROS :
    $ sudo apt update
    $ sudo apt install ros-foxy-desktop
    $ sudo apt install python3-colcon-common-extensions
    $ sudo apt install python3-argcomplete
    $ sudo apt install python3-rosdep2
    $ rosdep update
    $ echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
    $ ros2 run demo_nodes_cpp talker #if this works, ROS2 is sucessfully installed
      
    # ROS2 Foxy is now installed on your system.
    
  • Checkout basic ros2 tutorial, if you’re new to ROS2.

    $ mkdir -p ~/ros2_ws/src
    $ cd ~/ros22_ws/src
    $ git clone https://github.com/ros/ros_tutorials.git -b foxy-devel #https://docs.ros.org/en/foxy/Tutorials/Workspace/Creating-A-Workspace.html
    $ cd ..
    $ rosdep install -i --from-path src --rosdistro foxy -y
    $ colcon build
    $ echo "source /home/$USER/ros22_ws/install/local_setup.bash" >> ~/.bashrc
    $ source ~/.bashrc
    $ ros2 run turtlesim turtlesim_node
    # In new terminal tab
    $ ros2 run turtlesim turtle_teleop_key
    # In new terminal tab
    $ rqt_graph
    

    ros2turtlesim

  • Install YDLIDAR ROS2 package for the ros2 drivers.

    # Create a ROS workspace :
    $ mkdir -p ~/ydlidar_ros2_ws/src
    $ cd ~/ydlidar_ros2_ws/src
      
    # Install YDLIDAR ROS2 Package
    $ git clone https://github.com/YDLIDAR/ydlidar_ros2_driver.git
    $ cd ..
    $ colcon build --symlink-install
    $ echo "source ~/ydlidar_ros2_ws/install/setup.bash" >> ~/.bashrc
    $ source ~/.bashrc
    $ printenv | grep -i ROS
    $ chmod 0777 src/ydlidar_ros2_driver/startup/*
    $ sudo sh src/ydlidar_ros2_driver/startup/initenv.sh #after completion, replug the LiDAR.
    $ source ~/.bashrc
    
  • Configure correct LIDAR parameters for particular YDLIDAR. Proper configuration of ydlidar is essential, otherwise device fail error might occur.

    $ vim ~/ydlidar_ros2_ws/src/ydlidar_ros2_driver/params/ydlidar.yaml
      
    # for YDLIDAR X4 :
      
    ydlidar_ros2_driver_node:
      ros__parameters:
        port: /dev/ydlidar
        frame_id: laser_frame
        ignore_array: ""
        baudrate: 128000
        lidar_type: 1
        device_type: 0
        sample_rate: 5
        abnormal_check_count: 4
        resolution_fixed: true
        reversion: false
        inverted: true
        auto_reconnect: true
        isSingleChannel: false
        intensity: false
        support_motor_dtr: true
        angle_max: 180.0
        angle_min: -180.0
        range_max: 12.0
        range_min: 0.1
        frequency: 8.0
        invalid_range_is_inf: false
      
    
  • Run YDLIDAR X4 using ROS2. Attach external USB if using with Raspberry Pi (otherwise underpowered and DEVICE FAILED warning).

    $ ros2 launch ydlidar_ros2_driver ydlidar_launch.py #to print LIDAR data
    $ ros2 launch ydlidar_ros2_driver ydlidar_launch_view.py #to visualize LIDAR data using RVIZ
    # In new terminal tab
    $ rqt_graph
    

    ydlidarros2

Would like to acknowledge the support of mentor (Jan-Simon) who kindly provided the access to necessary hardware - Raspberry Pi (8 GB RAM) & YDLIDAR X4.