← afterhourC++ · Embedded
RPLidar Driver
A small C++ server that talks to an RPLIDAR A2M12, takes text commands on a control socket, and publishes decoded scan points line by line through a FIFO. Built for low-powered boards, so it deliberately does very little.
What it doesDeliberately minimal
Two planes, one processA control socket on port 9007 takes plain text commands. A FIFO at /tmp/lidar_data carries the decoded points. Nothing else is exposed, and nothing else needs to be.
Standard and express modesStandardScanner decodes fixed 5-byte packets into quality, angle, distance and a new-scan flag. ExpressScanner decodes 84-byte capsules. Switching modes restarts the worker in place.
Sample-rate decimationThe hardware pushes about 3200 points a second in standard mode and 2400 in express. --sample-rate n keeps every Nth point and counts the rest, so a slow board can sip from the stream instead of drowning in it.
Quality filtering--quality-data drops standard-mode points whose quality byte is zero before they ever reach the FIFO. Those drops are counted too, so status always tells you what you gave up.
The consumer side is the point. There is no client library to link against and no serialisation format to learn. Open a file, read lines, split on commas. Anything on the board can do that.
Shape of itControl in, data out
These are diagrams of the server’s structure and output rather than screenshots. It has no interface to photograph.
CommandsPort 9007, plain text
start [std|exp]Start the worker. Takes --device-path, --sample-rate and, in standard mode, --quality-data.
expShorthand for starting in express mode, with the same device-path and sample-rate options.
stopStop the worker and drain whatever is buffered in the FIFO, so the next start begins on fresh points.
statusWhether the worker is running, points seen, messages sent, messages dropped, the sample-rate limit, and whether quality filtering is on.
help / quitPrint the command list, or close the control connection.
Running itNotes from the README
Device/dev/ttyUSB0 by default. Another path can be passed per start with --device-path, or changed in rplidar::Config.
FIFO lifecycleThe server creates /tmp/lidar_data on startup and removes it on shutdown. Writes are dropped when no reader is attached or the pipe is full, and those drops are counted.
ShutdownCtrl+C is caught by a signal handler that asks for a clean shutdown rather than killing the worker mid-packet.
Buildmake, then ./rplidar. Cross-compilation is set up, and a Python visualiser ships in the repo for sanity-checking a live scan.