Scanse.io Sweep Lidar installation on GoPiGo2

I’m writing this the day after completing the setup so I may have forgotten some part of the process. I believe it went like this:

 Image

Clone the Sweep-SDK Repository

Log in to the Raspberry PI OS. Open a terminal and clone the sweep repo.

git clone https://github.com/scanse/sweep-sdk

Install CMAKE

Install CMAKE on Raspberry Pi in order to build `libsweep.so` in *sweep-sdk*.
Replace the version number with the latest, which in my case was 3.8.1 (https://cmake.org/download/).

INSTRUCTIONS FROM: http://osdevlab.blogspot.tw/2015/12/how-to-install-latest-cmake-for.html

1. Create a folder

pi@raspberrypi ~ $ mkdir Download
pi@raspberrypi ~ $ cd Download

2. Download the compressed file and extract it

pi@raspberrypi ~/Download $ wget https://cmake.org/files/v3.8/cmake-3.8.1.tar.gz
pi@raspberrypi ~/Download $ tar -xvzf cmake-3.8.1.tar.gz

3. Compile and install cmake. This will take several minutes.

pi@raspberrypi ~/Download $ cd cmake-3.4.1/
pi@raspberrypi ~/Download/cmake-3.4.1 $ sudo ./bootstrap
pi@raspberrypi ~/Download/cmake-3.4.1 $ sudo make
pi@raspberrypi ~/Download/cmake-3.4.1 $ sudo make install

Install libsweep

INSTRUCTIONS FROM: https://github.com/scanse/sweep-sdk/tree/master/libsweep

1. Enter the libsweep directory

cd sweep-sdk/libsweep

2. Create and enter a build directory

mkdir -p build
cd build

3. Build and install the libsweep library

cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
sudo cmake --build . --target install
sudo ldconfig

Install SweepPy

INSTRUCTIONS FROM: https://github.com/scanse/sweep-sdk/tree/master/sweeppy

1. Go to the `sweep-sdk/sweeppy` folder where `setup.py` is located.
2. Install sweep for python. (I don’t know if both versions is necessary but that’s what I did.)

python3 setup.py install --user
sudo python setup.py install --user

Run Sample Code

1. Connect Scanse Sweep to USB. I used the center top USB port for the Scanse lidar.

2. Run some code. (I skipped trying to add the `sweep` module globally and just wrote my test file inside the `sweeppy` folder.)

from sweeppy import Sweep

with Sweep('/dev/ttyUSB0') as sweep:
    print(sweep.get_motor_speed())
    print(sweep.get_sample_rate())
    sweep.start_scanning()

    for scan in sweep.get_scans():
        print('{}\n'.format(scan))

Note:

You cannot “get” or “set” while scanning. Do it before “start_scanning()” or after “stop_scanning()”.

String formatting with dictionary-like objects

In the past, whenever I needed to format a datetime.date string, I would do something like this:

date = datetime.date.today()

#Chinese year, month and day.
u'{}年 {}月 {}日'.format(*str(date).split('-'))

#Output: u'2014年 05月 02日'

It worked but I always had a nagging feeling that it’s not clean or pretty enough. So I finally took a moment to rethink it and remembered that you can also access attributes of an object when formatting:

u'{0.year}年 {0.month}月 {0.day}日'.format(date)

#Output: u'2014年 5月 2日'

(Zero is the index of the argument passed to the format method.)

In this case, the two ways are about the same length but the second one is more readable. These are not exactly the same though. Using split in the first method will give you two-digit strings for month and day (i.e. “05”), whereas accessing the attribute only retrieves a number. To get the two-digit output from attributes, add a bit more formatting code:

u'{0.year}年 {0.month:0>2}月 {0.day:0>2}日'.format(date)

#Output: u'2014年 05月 02日'

“0>2” orders up a 2 character long string with the main value served on the right with a side of zeros (if there’s room).