Lidar

Garmin Lidar Lite 3

Fig. 1: LidarLite with Pan-Tilt HAT and 2 servos. The video (right) demonstrates the servo-driven motion system, which scans the environment.

Garmin LIDAR Lite v3 (Lidar = laser detection and ranging, Fig. 1) is a sensor, which calculates distance by emitting and recieving Laser light. In combination with the servo-driven motion system (Vid. 1) we generate a 3 dimensional point cloud of the environment (see point cloud example).

Setup

Fig. 1: Soldered Lidar, servo and Temperature connections plugged to the Raspberry Pi 3

To connect the Lidar to the Raspi 3 we used:

  • A Raspberry Pi 3, which is pre-installed with the free-to-use operating system "Noobs", available on: https://www.raspberrypi.org/downloads/noobs/
  • Connection wires
  • A printed circuit board
  • 1000µF Electrolytic Capacitor
  • It takes four steps to get the lidar running (a more detailed instruction is provided by Mobius Strip Blog):

  • Connect the wires the right way. Our result (plus temperature sensor connections) you can see here in Fig. 3 at the page bottom. The wires are soldered to the printed circuit board to guard it against intermittend contact. The result is shown in Fig. 2.
  • Turn on the I2C pin on the RasPi
  • Install the I2C tools
  • In our case the RasPi Kernel needed to be downgraded to version 4.4 before the lidar was communicating with the RasPi (see Raspberry Pi Forum)
  • Make the lidar move

    To make the lidar scan a big area instead of just a strip of riparian vegetation and to control the scanning pattern we chose the Pan-Tilt HAT motion system, what we already tested for the RasPi camera. We bought anotherPan-Tilt HAT and 2 micro servos.

    Lidar Script

    The following Python 2 script controls the scanning pattern of the lidar and saves the lidar data. It moves from top to bottom and from left to right. It scans an left-right-angle of 81 degrees and a top-bottom-angle of 35 degrees in total. The angles can be adjusted by editing the skript. When the lidar is attached to the platform it is orientated sideways. This way it scans one side of the river.

    #import modules, place lidar_lite.py in the same folder
    import RPi.GPIO as GPIO
    import time
    import csv
    from lidar_lite import Lidar_Lite
    
    #initialize lidar
    lidar = Lidar_Lite()
    
    connected = lidar.connect(1)
    if connected < -1:
        print("nema connecta")
    
    #set pin numbers, board layout, pin mode, pwm freq., start pwm signal at 0 degress
    servo1 = 16
    servo2 = 18
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(servo1, GPIO.OUT)
    GPIO.setup(servo2, GPIO.OUT)
    p = GPIO.PWM(servo1, 50)
    q = GPIO.PWM(servo2, 50)
    q.start(2.5)
    p.start(2.5)
    
    #angles for the servos to rotate, x i left and right, y is up and down
    px = [i  * 2.5  for i in reversed(range(16,35))]
    py = [56 + i*2 for i in range(0,11)]
    erg = []
    
    
    #runs until ctrl + c is pressed
    try:
        while True:
            #sets servos first y then x
            for y in py:
                q.ChangeDutyCycle(float(y/10.0))
                for x in px:
                    p.ChangeDutyCycle(float(x/10.0))
                    #sleep for more steady movement
                    time.sleep(0.05)
                    time.sleep(0.05)
                    #lidar messearue
                    dist = lidar.getDistance()
                    erg.append([x,y,dist])
            #write csv, append to file after each run
            with open("output.csv", "a") as f:
                writer = csv.writer(f)
                writer.writerows(erg)
            erg = []
        except KeyboardInterrupt:
            p.stop()
            q.stop()
            GPIO.cleanup()