• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..28-Oct-2017-

cmake/H28-Oct-2017-4940

doc/H28-Oct-2017-403289

examples/H03-May-2022-474305

include/H28-Oct-2017-579385

man/H03-May-2022-10175

src/H28-Oct-2017-1,4721,022

.clang-formatH A D28-Oct-20172.6 KiB9189

.gitignoreH A D28-Oct-201720 44

README.mdH A D28-Oct-201711.1 KiB330222

README.md

1# libsweep
2
3Low-level Scanse Sweep LiDAR library. Comes as C99 library `sweep.h` with optional C++11 header `sweep.hpp` on top of it.
4
5
6
7### Quick Start
8
9```bash
10mkdir -p build
11cd build
12cmake .. -DCMAKE_BUILD_TYPE=Release
13cmake --build .
14sudo cmake --build . --target install
15sudo ldconfig
16```
17
18If you don't have a Sweep device yet you can build a dummy `libsweep.so` always returning static point cloud data:
19
20```bash
21cmake .. -DCMAKE_BUILD_TYPE=Release -DDUMMY=On
22```
23
24This dummy library is API and ABI compatible. Once your device arrives switch out the `libsweep.so` shared library and you're good to go.
25
26For Windows users open a command prompt with administrative access:
27
28```bash
29mkdir build
30cd build
31cmake .. -G "Visual Studio 14 2015 Win64"
32cmake --build . --config Release
33cmake --build . --target install --config Release
34```
35
36The above command assumes Visual Studio 2015. If you have a different version installed, change the value. ie:
37
38    Visual Studio 11 2012 Win64 = Generates Visual Studio 11 (VS 2012) project files for x64 architecture
39    Visual Studio 12 2013 Win64 = Generates Visual Studio 12 (VS 2013) project files for x64 architecture
40    Visual Studio 14 2015 Win64 = Generates Visual Studio 14 (VS 2015) project files for x64 architecture
41    Visual Studio 15 2017 Win64 = Generates Visual Studio 15 (VS 2017) project files for x64 architecture
42
43Additionally, the above commands assume you want to build a x64 (64bit) verison of the library. To build a x86 (32 bit) version, simply drop the `Win64`. i.e.:
44
45    Visual Studio 14 2015 = Generates Visual Studio 14 (VS 2015) project files for x86 architecture
46
47To build the dummy library add the dummy flag to the command:
48
49```bash
50cmake ..  -DDUMMY=On -G "Visual Studio 14 2015 Win64"
51```
52
53Then be sure to add the installation directories for the library and the header files to the environment `PATH` variable. For the above installation you'd have to add something like the following:
54- `C:\Program Files\sweep\lib` for the library
55- `C:\Program Files\sweep\include`for the headers
56
57You may have to restart the computer before the changes take effect.
58
59Lastly, if you are on windows you will have to adjust the settings for the COM port you are using in order to communicate properly with the sweep sensor. Follow [this guide](https://support.scanse.io/hc/en-us/articles/115000793208-Changing-the-USB-Adapter-Latency-Timer-and-Byte-Size-Setting-on-Windows). Adjusting settings only has to be done once for a given COM port, and windows will remember the settings.
60
61### Usage
62
63- Include `<sweep/sweep.h>` for the C interface or `<sweep/sweep.hpp>` for the C++ interface.
64- Link `libsweep.so` with `-lsweep`.
65
66For example:
67
68    gcc -Wall -Wextra -pedantic -std=c99 examples/example.c -lsweep
69    g++ -Wall -Wextra -pedantic -std=c++11 examples/example.cc -lsweep
70
71In addition, we provide CMake integration. In your `CMakeLists.txt`:
72
73    find_package(Sweep REQUIRED)
74    target_link_libraries(.. ${LIBSWEEP_LIBRARY})
75    target_include_directories(.. ${LIBSWEEP_INCLUDE_DIR})
76
77See [example.c](examples/example.c) and [example.cc](examples/example.cc) for a C and C++ example, respectively.
78
79
80### libsweep
81
82Before jumping into details, here are the library's main design ideas:
83
84- Only opaque pointers (think typed `void *`) and plain C types in the API. This is how we accomplish ABI compatibility.
85- No global state: `_s` context objects (`_s` since POSIX reserves `_t`) hold state and have to be passed explicitly.
86- Make ownership and lifetimes explicit: all objects have to be `_construct()`ed for creation and successfully created objects have to be `_destruct()`ed for cleanup.
87- Sane defaults and user-friendly API: when possible we provide `_simple()` functions e.g. doing serial port auto-detection.
88- Fixed-size and signed integers for portability and runtime checking (think sanitizers).
89
90Table of Contents:
91- [Firmware Compatibility](#firmware-compatibility)
92- [Version and ABI Management](#version-and-abi-management)
93- [Error Handling](#error-handling)
94- [Device Interaction](#device-interaction)
95- [Full 360 Degree Scan](#full-360-degree-scan)
96- [Additional Information](#additional-information)
97
98#### Firmware Compatibility
99| libsweep | sweep firmware |
100| -------- | :------------: |
101| v1.2.0+   | v1.4           |
102| v1.1.1   | v1.2           |
103| v1.1.0   | v1.1           |
104| v0.x.x   | v1.0           |
105
106You can check the firmware version installed on your sweep device by using a serial terminal (see [manual](https://s3.amazonaws.com/scanse/Sweep_user_manual.pdf)) or more easily using the sweep visualizer (see [instructions](https://support.scanse.io/hc/en-us/articles/224557908-Upgrading-Firmware)).
107
108
109#### Version And ABI Management
110
111```c++
112SWEEP_VERSION_MAJOR
113```
114
115Interface major version number.
116
117```c++
118SWEEP_VERSION_MINOR
119```
120
121Interface minor version number.
122
123```c++
124SWEEP_VERSION
125```
126
127Combined interface major and minor version number.
128
129```c++
130int32_t sweep_get_version(void)
131```
132
133Returns the library's version (see `SWEEP_VERSION`).
134Used for ABI compatibility checks.
135
136```c++
137bool sweep_is_abi_compatible(void)
138```
139
140Returns true if the library is ABI compatible.
141This check is done by comparing the interface header with the installed library's version.
142
143
144#### Error Handling
145
146```c++
147SWEEP_ASSERT
148```
149
150Optionally define this for custom assertion handling.
151Uses `assert` from `<assert.h>` by default.
152
153```c++
154sweep_error_s
155```
156
157Opaque type representing an error.
158You can get a human readable representation using the `sweep_error_message` function.
159You have to destruct an error object with `sweep_error_destruct`.
160
161```c++
162const char* sweep_error_message(sweep_error_s error)
163```
164
165Human readable representation for an error.
166
167```c++
168void sweep_error_destruct(sweep_error_s error)
169```
170
171Destructs an `sweep_error_s` object.
172
173
174#### Device Interaction
175
176```c++
177sweep_device_s
178```
179
180Opaque type representing a Sweep device.
181All direct device interaction happens on this type.
182
183```c++
184sweep_device_s sweep_device_construct_simple(const char* port, sweep_error_s* error)
185```
186
187Constructs a `sweep_device_s` based on a serial device port (e.g. `/dev/ttyUSB0` on Linux or `COM5` on Windows).
188In case of error a `sweep_error_s` will be written into `error`.
189
190```c++
191sweep_device_s sweep_device_construct(const char* port, int32_t bitrate, sweep_error_s* error)
192```
193
194Constructs a `sweep_device_s` with explicit hardware configuration.
195In case of error a `sweep_error_s` will be written into `error`.
196
197```c++
198void sweep_device_destruct(sweep_device_s device)
199```
200
201Destructs an `sweep_device_s` object.
202
203```c++
204void sweep_device_start_scanning(sweep_device_s device, sweep_error_s* error)
205```
206
207Signals the `sweep_device_s` to start scanning.
208If the motor is stationary (0Hz), will automatically set motor speed to default 5Hz.
209Will block until the device is ready (calibration routine complete + motor speed is stable).
210Starts internal background thread to accumulate and queue up scans. Scans can then be retrieved using `sweep_device_get_scan`.
211In case of error a `sweep_error_s` will be written into `error`.
212
213
214```c++
215void sweep_device_stop_scanning(sweep_device_s device, sweep_error_s* error)
216```
217
218Signals the `sweep_device_s` to stop scanning.
219Blocks for ~35ms to allow time for the trailing data stream to collect and flush internally, before sending a second stop command and validate the response.
220In case of error a `sweep_error_s` will be written into `error`.
221
222```c++
223bool sweep_device_get_motor_ready(sweep_device_s device, sweep_error_s* error)
224```
225
226Returns `true` if the device is ready. A device is ready when the motor speed has stabilized to the current setting, and the calibration routine is complete. For visual reference, the blue LED on the device will blink unil the device is ready. This method is useful when the device is powered on, or when adjusting motor speed. If the device is NOT ready, it will respond to certain commands (`DS` or `MS`) with a status code indicating a failure to execute the command.
227In case of error a `sweep_error_s` will be written into `error`.
228
229```c++
230int32_t sweep_device_get_motor_speed(sweep_device_s device, sweep_error_s* error)
231```
232
233Returns the `sweep_device_s`'s motor speed setting in Hz.
234If the motor speed is currently changing, the returned motor speed is the target speed at which the device will stabilize.
235In case of error a `sweep_error_s` will be written into `error`.
236
237```c++
238void sweep_device_set_motor_speed(sweep_device_s device, int32_t hz, sweep_error_s* error)
239```
240
241Sets the `sweep_device_s`'s motor speed in Hz.
242Blocks until prior motor speed has stabilized.
243The device supports speeds of 0 Hz to 10 Hz, but be careful that the device is not set at 0Hz before calling `sweep_device_start_scanning`.
244In case of error a `sweep_error_s` will be written into `error`.
245
246
247```c++
248int32_t sweep_device_get_sample_rate(sweep_device_s device, sweep_error_s* error)
249```
250
251Returns the `sweep_device_s`'s sample rate in Hz.
252In case of error a `sweep_error_s` will be written into `error`.
253
254```c++
255void sweep_device_set_sample_rate(sweep_device_s device, int32_t hz, sweep_error_s* error)
256```
257
258Sets the `sweep_device_s`'s sample rate in Hz.
259The device supports setting sample rate to the following values: 500 Hz, 750 Hz and 1000 Hz.
260These sample rates are not exact. They are general ballpark values. The actual sample rate may differ slightly.
261In case of error a `sweep_error_s` will be written into `error`.
262
263```c++
264void sweep_device_reset(sweep_device_s device, sweep_error_s* error)
265```
266
267Resets the `sweep_device_s` hardware.
268In case of error a `sweep_error_s` will be written into `error`.
269
270
271#### Full 360 Degree Scan
272
273```c++
274sweep_scan_s
275```
276
277Opaque type representing a single full 360 degree scan from a `sweep_device_s`.
278
279```c++
280sweep_scan_s sweep_device_get_scan(sweep_device_s device, sweep_error_s* error)
281```
282
283Returns the ordered readings (1st to last) from a single scan.
284Retrieves the oldest scan from a queue of scans accumulated in a background thread. Blocks until a scan is available. To be used after calling `sweep_device_start_scanning`.
285In case of error a `sweep_error_s` will be written into `error`.
286
287
288```c++
289void sweep_scan_destruct(sweep_scan_s scan)
290```
291
292Destructs a `sweep_scan_s` object.
293
294```c++
295int32_t sweep_scan_get_number_of_samples(sweep_scan_s scan)
296```
297
298Returns the number of samples in a full 360 degree `sweep_scan_s`.
299
300```c++
301int32_t sweep_scan_get_angle(sweep_scan_s scan, int32_t sample)
302```
303
304Returns the angle in milli-degree for the `sample`th sample in the `sweep_scan_s`.
305
306```c++
307int32_t sweep_scan_get_distance(sweep_scan_s scan, int32_t sample)
308```
309
310Returns the distance in centi-meter for the `sample`th sample in the `sweep_scan_s`.
311
312```c++
313int32_t sweep_scan_get_signal_strength(sweep_scan_s scan, int32_t sample)
314```
315
316Returns the signal strength (0 low -- 255 high) for the `sample`th sample in the `sweep_scan_s`.
317
318
319#### Additional Information
320It is recommended that you read through the sweep [Theory of Operation](https://support.scanse.io/hc/en-us/articles/115006333327-Theory-of-Operation) and [Best Practices](https://support.scanse.io/hc/en-us/articles/115006055388-Best-Practices).
321
322
323### License
324
325Copyright © 2016 Daniel J. Hofmann
326
327Copyright © 2016 Scanse LLC
328
329Distributed under the MIT License (MIT).
330